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/gethostlatency.py b/tools/gethostlatency.py
index 8d07e23..965c0db 100755
--- a/tools/gethostlatency.py
+++ b/tools/gethostlatency.py
@@ -19,7 +19,6 @@
from bcc import BPF
from time import strftime
import argparse
-import ctypes as ct
examples = """examples:
./gethostlatency # trace all TCP accept()s
@@ -113,21 +112,11 @@
b.attach_uretprobe(name="c", sym="gethostbyname2", fn_name="do_return",
pid=args.pid)
-TASK_COMM_LEN = 16 # linux/sched.h
-
-class Data(ct.Structure):
- _fields_ = [
- ("pid", ct.c_ulonglong),
- ("delta", ct.c_ulonglong),
- ("comm", ct.c_char * TASK_COMM_LEN),
- ("host", ct.c_char * 80)
- ]
-
# header
print("%-9s %-6s %-16s %10s %s" % ("TIME", "PID", "COMM", "LATms", "HOST"))
def print_event(cpu, data, size):
- event = ct.cast(data, ct.POINTER(Data)).contents
+ event = b["events"].event(data)
print("%-9s %-6d %-16s %10.2f %s" % (strftime("%H:%M:%S"), event.pid,
event.comm.decode('utf-8', 'replace'), (float(event.delta) / 1000000),
event.host.decode('utf-8', 'replace')))