Skip to content

Commit

Permalink
Merge pull request iovisor#2182 from boat0/enhance-examples
Browse files Browse the repository at this point in the history
examples/tracing: some minor fixes
  • Loading branch information
palmtenor committed Feb 3, 2019
2 parents 8b48206 + 922f1ab commit 339587f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
5 changes: 4 additions & 1 deletion examples/tracing/dddos.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ def trigger_alert_event(cpu, data, size):
# loop with callback to trigger_alert_event
b["events"].open_perf_buffer(trigger_alert_event)
while 1:
b.perf_buffer_poll()
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
23 changes: 13 additions & 10 deletions examples/tracing/disksnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@

# format output
while 1:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
(bytes_s, bflags_s, us_s) = msg.split()
try:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
(bytes_s, bflags_s, us_s) = msg.split()

if int(bflags_s, 16) & REQ_WRITE:
type_s = "W"
elif bytes_s == "0": # see blk_fill_rwbs() for logic
type_s = "M"
else:
type_s = "R"
ms = float(int(us_s, 10)) / 1000
if int(bflags_s, 16) & REQ_WRITE:
type_s = "W"
elif bytes_s == "0": # see blk_fill_rwbs() for logic
type_s = "M"
else:
type_s = "R"
ms = float(int(us_s, 10)) / 1000

print("%-18.9f %-2s %-7s %8.2f" % (ts, type_s, bytes_s, ms))
print("%-18.9f %-2s %-7s %8.2f" % (ts, type_s, bytes_s, ms))
except KeyboardInterrupt:
exit()
5 changes: 4 additions & 1 deletion examples/tracing/hello_perf_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ def print_event(cpu, data, size):
# loop with callback to print_event
b["events"].open_perf_buffer(print_event)
while 1:
b.perf_buffer_poll()
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
Empty file modified examples/tracing/mallocstacks.py
100644 → 100755
Empty file.
Empty file modified examples/tracing/stack_buildid_example.py
100644 → 100755
Empty file.
5 changes: 4 additions & 1 deletion examples/tracing/stacksnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,7 @@ def print_event(cpu, data, size):

b["events"].open_perf_buffer(print_event)
while 1:
b.perf_buffer_poll()
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()
5 changes: 4 additions & 1 deletion examples/tracing/trace_perf_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ def print_counter():
print("Tracing " + event_name + ", try `dd if=/dev/zero of=/dev/null`")
print("Tracing... Hit Ctrl-C to end.")
while 1:
b.perf_buffer_poll()
try:
b.perf_buffer_poll()
except KeyboardInterrupt:
exit()

0 comments on commit 339587f

Please sign in to comment.