more examples of b[] syntax, fix func arg passing
authorBrendan Gregg <brendan.d.gregg@gmail.com>
Thu, 20 Aug 2015 19:40:37 +0000 (12:40 -0700)
committerBrendan Gregg <brendan.d.gregg@gmail.com>
Thu, 20 Aug 2015 19:40:37 +0000 (12:40 -0700)
examples/bitehist.py
examples/vfsreadlat.py
tools/pidpersec
tools/vfscount
tools/vfsstat

index af4bb3b..55c902f 100755 (executable)
@@ -40,7 +40,6 @@ if len(argv) > 1:
 # load BPF program
 b = BPF(src_file = "bitehist.c")
 b.attach_kprobe(event="blk_start_request", fn_name="do_request")
-dist = b.get_table("dist")
 dist_max = 64
 
 # header
@@ -63,7 +62,7 @@ def stars(val, val_max, width):
                text = text[:-1] + "+"
        return text
 
-def print_log2_hist(d, val_type):
+def print_log2_hist(dist, val_type):
        idx_max = -1
        val_max = 0
        for i in range(1, dist_max + 1):
@@ -104,6 +103,6 @@ while (1):
                pass; do_exit = 1
 
        print
-       print_log2_hist(dist, "kbytes")
+       print_log2_hist(b["dist"], "kbytes")
        if do_exit:
                exit()
index febd5c4..7c28b9a 100755 (executable)
@@ -63,12 +63,12 @@ def stars(val, val_max, width):
                text = text[:-1] + "+"
        return text
 
-def print_log2_hist(d, val_type):
+def print_log2_hist(dist, val_type):
        idx_max = -1
        val_max = 0
        for i in range(1, dist_max + 1):
                try:
-                       val = b["dist"][c_int(i)].value - last[i]
+                       val = dist[c_int(i)].value - last[i]
                        if (val > 0):
                                idx_max = i
                        if (val > val_max):
@@ -83,10 +83,10 @@ def print_log2_hist(d, val_type):
                if (low == high):
                        low -= 1
                try:
-                       val = b["dist"][c_int(i)].value - last[i]
+                       val = dist[c_int(i)].value - last[i]
                        print("%8d -> %-8d : %-8d |%-*s|" % (low, high, val,
                            stars_max, stars(val, val_max, stars_max)))
-                       last[i] = b["dist"][c_int(i)].value
+                       last[i] = dist[c_int(i)].value
                except:
                        break
 
index 32afaa1..767c092 100755 (executable)
@@ -19,7 +19,6 @@ from time import sleep, strftime
 # load BPF program
 b = BPF(src_file = "pidpersec.c")
 b.attach_kprobe(event="sched_fork", fn_name="do_count")
-stats = b.get_table("stats")
 
 # stat indexes
 S_COUNT = 1
@@ -36,5 +35,5 @@ while (1):
                pass; exit()
 
        print("%s: PIDs/sec: %d" % (strftime("%H:%M:%S"),
-           (stats[c_int(S_COUNT)].value - last)))
-       last = stats[c_int(S_COUNT)].value
+           (b["stats"][c_int(S_COUNT)].value - last)))
+       last = b["stats"][c_int(S_COUNT)].value
index dfa812f..970b342 100755 (executable)
@@ -57,7 +57,6 @@ b.attach_kprobe(event="vfs_write", fn_name="do_count")
 b.attach_kprobe(event="vfs_fsync", fn_name="do_count")
 b.attach_kprobe(event="vfs_open", fn_name="do_count")
 b.attach_kprobe(event="vfs_create", fn_name="do_count")
-counts = b.get_table("counts")
 
 # header
 print("Tracing... Ctrl-C to end.")
@@ -69,5 +68,6 @@ except KeyboardInterrupt:
        pass
 
 print("\n%-16s %-12s %8s" % ("ADDR", "FUNC", "COUNT"))
+counts = b.get_table("counts")
 for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
        print("%-16x %-12s %8d" % (k.ip, ksym(k.ip), v.value))
index 4c96bff..d44a987 100755 (executable)
@@ -42,7 +42,6 @@ b.attach_kprobe(event="vfs_write", fn_name="do_write")
 b.attach_kprobe(event="vfs_fsync", fn_name="do_fsync")
 b.attach_kprobe(event="vfs_open", fn_name="do_open")
 b.attach_kprobe(event="vfs_create", fn_name="do_create")
-stats = b.get_table("stats")
 
 # stat column labels and indexes
 stat_types = {
@@ -79,9 +78,9 @@ while (1):
        for stype in stat_types.keys():
                idx = stat_types[stype]
                try:
-                       delta = stats[c_int(idx)].value - last[idx]
+                       delta = b["stats"][c_int(idx)].value - last[idx]
                        print(" %8d" % (delta / interval), end="")
-                       last[idx] = stats[c_int(idx)].value
+                       last[idx] = b["stats"][c_int(idx)].value
                except:
                        print(" %8d" % 0, end="")
        print("")