Blame SOURCES/bcc-0.8.0-print_log2_hist-check-and-skip-possible-paddings-215.patch

5d1f51
From 3f7b59660037c0d5dea785d115df25d9b95f07dc Mon Sep 17 00:00:00 2001
5d1f51
From: Xiaozhou Liu <liuxiaozhou@bytedance.com>
5d1f51
Date: Mon, 21 Jan 2019 11:23:42 +0800
5d1f51
Subject: [PATCH] print_log2_hist(): check and skip possible paddings (#2155)
5d1f51
5d1f51
Address issue 2154.
5d1f51
5d1f51
When a struct S is used as key to a BPF_HISTOGRAM, it is assumed that the second
5d1f51
member of S holds the slot. But when S is converted to python from bpf C,
5d1f51
a padding may be inserted as a second member. This breaks print_log2_hist().
5d1f51
5d1f51
    root@debian:~/bcc/tools# ./softirqs.py -d
5d1f51
    Tracing soft irq event time... Hit Ctrl-C to end.
5d1f51
    ^C
5d1f51
    Traceback (most recent call last):
5d1f51
      File "./softirqs.py", line 144, in <module>
5d1f51
        dist.print_log2_hist(label, "softirq", section_print_fn=vec_to_name)
5d1f51
      File "/usr/local/lib/python2.7/dist-packages/bcc/table.py", line 326, in print_log2_hist
5d1f51
        vals[slot] = v.value
5d1f51
    TypeError: list indices must be integers, not str
5d1f51
5d1f51
Fix it by skipping the possible padding. Future work would be fixing/working
5d1f51
around in the library where the padding is introduced.
5d1f51
---
5d1f51
 src/python/bcc/table.py | 9 +++++++++
5d1f51
 1 file changed, 9 insertions(+)
5d1f51
5d1f51
diff --git a/src/python/bcc/table.py b/src/python/bcc/table.py
5d1f51
index 6f598353..f6449de7 100644
5d1f51
--- a/src/python/bcc/table.py
5d1f51
+++ b/src/python/bcc/table.py
5d1f51
@@ -317,6 +317,15 @@ linear_index_max = 1025
5d1f51
             tmp = {}
5d1f51
             f1 = self.Key._fields_[0][0]
5d1f51
             f2 = self.Key._fields_[1][0]
5d1f51
+
5d1f51
+            # The above code assumes that self.Key._fields_[1][0] holds the
5d1f51
+            # slot. But a padding member may have been inserted here, which
5d1f51
+            # breaks the assumption and leads to chaos.
5d1f51
+            # TODO: this is a quick fix. Fixing/working around in the BCC
5d1f51
+            # internal library is the right thing to do.
5d1f51
+            if f2 == '__pad_1' and len(self.Key._fields_) == 3:
5d1f51
+                f2 = self.Key._fields_[2][0]
5d1f51
+
5d1f51
             for k, v in self.items():
5d1f51
                 bucket = getattr(k, f1)
5d1f51
                 if bucket_fn:
5d1f51
-- 
5d1f51
2.20.1
5d1f51