Skip to content

Commit

Permalink
tools: Flush stdout explicitly in event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
xingfeng2510 authored and yonghong-song committed Mar 24, 2022
1 parent 43fec8b commit 7b2c114
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/compactsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import argparse
import platform
from datetime import datetime, timedelta
import sys

# arguments
examples = """examples:
Expand Down Expand Up @@ -390,6 +391,8 @@ def print_event(cpu, data, size):
print("\t%s" % sym)
print("")

sys.stdout.flush()

# loop with callback to print_event
b["events"].open_perf_buffer(print_event, page_cnt=64)
start_time = datetime.now()
Expand Down
3 changes: 3 additions & 0 deletions tools/drsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from datetime import datetime, timedelta
import os
import math
import sys

# symbols
kallsyms = "/proc/kallsyms"
Expand Down Expand Up @@ -224,6 +225,8 @@ def print_event(cpu, data, size):
else:
print("")

sys.stdout.flush()


# loop with callback to print_event
b["events"].open_perf_buffer(print_event, page_cnt=64)
Expand Down
3 changes: 3 additions & 0 deletions tools/hardirqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from bcc import BPF
from time import sleep, strftime
import argparse
import sys

# arguments
examples = """examples:
Expand Down Expand Up @@ -248,6 +249,8 @@
print("%-26s %11d" % (k.name.decode('utf-8', 'replace'), v.value / factor))
dist.clear()

sys.stdout.flush()

countdown -= 1
if exiting or countdown == 0:
exit()
1 change: 1 addition & 0 deletions tools/mountsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def print_event(mounts, umounts, parent, cpu, data, size):
print('{:16} {:<7} {:<7} {:<11} {}'.format(
syscall['comm'].decode('utf-8', 'replace'), syscall['tgid'],
syscall['pid'], syscall['mnt_ns'], call))
sys.stdout.flush()
except KeyError:
# This might happen if we lost an event.
pass
Expand Down
3 changes: 3 additions & 0 deletions tools/softirqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from bcc import BPF
from time import sleep, strftime
import argparse
import sys

# arguments
examples = """examples:
Expand Down Expand Up @@ -175,6 +176,8 @@ def vec_to_name(vec):
print("%-16s %11d" % (vec_to_name(k.vec), v.value / factor))
dist.clear()

sys.stdout.flush()

countdown -= 1
if exiting or countdown == 0:
exit()
2 changes: 2 additions & 0 deletions tools/syncsnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from __future__ import print_function
from bcc import BPF
import sys

# load BPF program
b = BPF(text="""
Expand All @@ -40,6 +41,7 @@
def print_event(cpu, data, size):
event = b["events"].event(data)
print("%-18.9f sync()" % (float(event.ts) / 1000000))
sys.stdout.flush()

# loop with callback to print_event
b["events"].open_perf_buffer(print_event)
Expand Down

0 comments on commit 7b2c114

Please sign in to comment.