Commit a789867d authored by Brenden Blanco's avatar Brenden Blanco

Merge pull request #182 from brendangregg/master

simplify code using new features
parents e79676a7 d21af64c
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
from __future__ import print_function from __future__ import print_function
from bcc import BPF from bcc import BPF
import sys
REQ_WRITE = 1 # from include/linux/blk_types.h REQ_WRITE = 1 # from include/linux/blk_types.h
...@@ -24,13 +23,6 @@ b.attach_kprobe(event="blk_update_request", fn_name="do_completion") ...@@ -24,13 +23,6 @@ b.attach_kprobe(event="blk_update_request", fn_name="do_completion")
# header # header
print("%-18s %-2s %-7s %8s" % ("TIME(s)", "T", "BYTES", "LAT(ms)")) print("%-18s %-2s %-7s %8s" % ("TIME(s)", "T", "BYTES", "LAT(ms)"))
# open trace pipe
try:
trace = open("/sys/kernel/debug/tracing/trace_pipe", "r")
except:
print("ERROR: opening trace_pipe", file=sys.stderr)
exit(1)
# format output # format output
while 1: while 1:
(task, pid, cpu, flags, ts, msg) = b.trace_readline_fields() (task, pid, cpu, flags, ts, msg) = b.trace_readline_fields()
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
from __future__ import print_function from __future__ import print_function
from bcc import BPF from bcc import BPF
import sys
# load BPF program # load BPF program
b = BPF(text = """ b = BPF(text = """
...@@ -22,26 +21,12 @@ int do_sync(void *ctx) { ...@@ -22,26 +21,12 @@ int do_sync(void *ctx) {
return 0; return 0;
}; };
""") """)
b.attach_kprobe(event="sys_sync") b.attach_kprobe(event="sys_sync", fn_name="do_sync")
# header # header
print("%-18s %s" % ("TIME(s)", "CALL")) print("%-18s %s" % ("TIME(s)", "CALL"))
# open trace pipe
try:
trace = open("/sys/kernel/debug/tracing/trace_pipe", "r")
except:
print("ERROR: opening trace_pipe", file=sys.stderr)
exit(1)
# format output # format output
while 1: while 1:
try: (task, pid, cpu, flags, ts, msg) = b.trace_readline_fields()
line = trace.readline().rstrip() print("%-18.9f %s" % (ts, msg))
except KeyboardInterrupt:
pass; exit()
prolog, time_s, colon, word = line.rsplit(" ", 3)
time_s = time_s[:-1] # strip trailing ":"
print("%-18s %s" % (time_s, word))
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
from __future__ import print_function from __future__ import print_function
from bcc import BPF from bcc import BPF
from ctypes import c_ushort, c_int, c_ulonglong from time import sleep
from time import sleep, strftime
from sys import stderr
# load BPF program # load BPF program
b = BPF(src_file = "vfscount.c") b = BPF(src_file = "vfscount.c")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment