tools: remove redundant Python event data structure definitions (#2204)
Simplify code following #2198 (https://github.com/iovisor/bcc/pull/2198).
Some tools are not touched: mountsnoop.py, trace.py, lib/*.py, old/*.py.
diff --git a/tools/mdflush.py b/tools/mdflush.py
index 485635d..f1c68ae 100755
--- a/tools/mdflush.py
+++ b/tools/mdflush.py
@@ -14,7 +14,6 @@
from __future__ import print_function
from bcc import BPF
from time import strftime
-import ctypes as ct
# load BPF program
b = BPF(text="""
@@ -54,23 +53,13 @@
}
""")
-# event data
-TASK_COMM_LEN = 16 # linux/sched.h
-DISK_NAME_LEN = 32 # linux/genhd.h
-class Data(ct.Structure):
- _fields_ = [
- ("pid", ct.c_ulonglong),
- ("comm", ct.c_char * TASK_COMM_LEN),
- ("disk", ct.c_char * DISK_NAME_LEN)
- ]
-
# header
print("Tracing md flush requests... Hit Ctrl-C to end.")
print("%-8s %-6s %-16s %s" % ("TIME", "PID", "COMM", "DEVICE"))
# process event
def print_event(cpu, data, size):
- event = ct.cast(data, ct.POINTER(Data)).contents
+ event = b["events"].event(data)
print("%-8s %-6d %-16s %s" % (strftime("%H:%M:%S"), event.pid,
event.comm.decode('utf-8', 'replace'),
event.disk.decode('utf-8', 'replace')))