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

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