Skip to content

Commit

Permalink
examples/tracing: Handle KeyboardInterrupt
Browse files Browse the repository at this point in the history
Signed-off-by: Gary Lin <[email protected]>
  • Loading branch information
lcp committed Mar 4, 2019
1 parent bb65bea commit 593339d
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions examples/tracing/hello_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
except ValueError:
continue
except KeyboardInterrupt:
exit()
printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
2 changes: 2 additions & 0 deletions examples/tracing/mysqld_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@
except ValueError:
print("value error")
continue
except KeyboardInterrupt:
exit()
printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
2 changes: 2 additions & 0 deletions examples/tracing/nodejs_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@
except ValueError:
print("value error")
continue
except KeyboardInterrupt:
exit()
printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
13 changes: 8 additions & 5 deletions examples/tracing/sync_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
# format output
start = 0
while 1:
(task, pid, cpu, flags, ts, ms) = b.trace_fields()
if start == 0:
start = ts
ts = ts - start
printb(b"At time %.2f s: multiple syncs detected, last %s ms ago" % (ts, ms))
try:
(task, pid, cpu, flags, ts, ms) = b.trace_fields()
if start == 0:
start = ts
ts = ts - start
printb(b"At time %.2f s: multiple syncs detected, last %s ms ago" % (ts, ms))
except KeyboardInterrupt:
exit()
2 changes: 2 additions & 0 deletions examples/tracing/tcpv4connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def inet_ntoa(addr):
except ValueError:
# Ignore messages from other tracers
continue
except KeyboardInterrupt:
exit()

# Ignore messages from other tracers
if _tag != "trace_tcp4connect":
Expand Down
5 changes: 4 additions & 1 deletion examples/tracing/trace_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
b = BPF(text=prog)
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="hello")
print("PID MESSAGE")
b.trace_print(fmt="{1} {5}")
try:
b.trace_print(fmt="{1} {5}")
except KeyboardInterrupt:
exit()
2 changes: 2 additions & 0 deletions examples/tracing/urandomread-explicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
except ValueError:
continue
except KeyboardInterrupt:
exit()
printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))
2 changes: 2 additions & 0 deletions examples/tracing/urandomread.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
except ValueError:
continue
except KeyboardInterrupt:
exit()
printb(b"%-18.9f %-16s %-6d %s" % (ts, task, pid, msg))

0 comments on commit 593339d

Please sign in to comment.