Skip to content

Commit

Permalink
add enum support for generating perf event data struct (iovisor#2199)
Browse files Browse the repository at this point in the history
Add enum type support so that scripts like tools/dcsnoop.py could be
simplied.
  • Loading branch information
boat0 authored and yonghong-song committed Feb 14, 2019
1 parent 790425e commit 6c79c68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/python/bcc/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ def _get_event_class(self):
'u16' : ct.c_ushort,
'int' : ct.c_int,
's32' : ct.c_int,
'enum' : ct.c_int,
'unsigned int' : ct.c_uint,
'u32' : ct.c_uint,
'long' : ct.c_long,
Expand All @@ -599,6 +600,9 @@ def _get_event_class(self):
field_name = m.group(1)
field_type = m.group(2)

if re.match(r"enum .*", field_type):
field_type = "enum"

m = array_type.match(field_type)
try:
if m:
Expand Down
14 changes: 1 addition & 13 deletions tools/dcsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from __future__ import print_function
from bcc import BPF
import argparse
import ctypes as ct
import re
import time

Expand Down Expand Up @@ -123,17 +122,6 @@
}
"""

TASK_COMM_LEN = 16 # linux/sched.h
MAX_FILE_LEN = 64 # see inline C

class Data(ct.Structure):
_fields_ = [
("pid", ct.c_uint),
("type", ct.c_int),
("comm", ct.c_char * TASK_COMM_LEN),
("filename", ct.c_char * MAX_FILE_LEN),
]

if args.ebpf:
print(bpf_text)
exit()
Expand All @@ -151,7 +139,7 @@ class Data(ct.Structure):
start_ts = time.time()

def print_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(Data)).contents
event = b["events"].event(data)
print("%-11.6f %-6d %-16s %1s %s" % (
time.time() - start_ts, event.pid,
event.comm.decode('utf-8', 'replace'), mode_s[event.type],
Expand Down

0 comments on commit 6c79c68

Please sign in to comment.