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/ttysnoop.py b/tools/ttysnoop.py
index 07f272f..058dc7e 100755
--- a/tools/ttysnoop.py
+++ b/tools/ttysnoop.py
@@ -16,7 +16,6 @@
from __future__ import print_function
from bcc import BPF
-import ctypes as ct
from subprocess import call
import argparse
from sys import argv
@@ -101,20 +100,12 @@
# initialize BPF
b = BPF(text=bpf_text)
-BUFSIZE = 256
-
-class Data(ct.Structure):
- _fields_ = [
- ("count", ct.c_int),
- ("buf", ct.c_char * BUFSIZE)
- ]
-
if not args.noclear:
call("clear")
# process event
def print_event(cpu, data, size):
- event = ct.cast(data, ct.POINTER(Data)).contents
+ event = b["events"].event(data)
print("%s" % event.buf[0:event.count].decode('utf-8', 'replace'), end="")
sys.stdout.flush()