Skip to content

Commit

Permalink
Add stdout flushing to some tools (iovisor#2110)
Browse files Browse the repository at this point in the history
* add stdout flushing to some tools

* change printb import source in opensnoop tool
  • Loading branch information
japroc authored and yonghong-song committed Jan 4, 2019
1 parent c5a448a commit aed9b1e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tools/opensnoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import print_function
from bcc import ArgString, BPF
from bcc.utils import printb
import argparse
import ctypes as ct
from datetime import datetime, timedelta
Expand Down Expand Up @@ -222,7 +223,7 @@ def print_event(cpu, data, size):
if args.extended_fields:
print("%08o " % event.flags, end="")

print(event.fname.decode('utf-8', 'replace'))
printb(b'%s' % event.fname.decode('utf-8', 'replace'))

# loop with callback to print_event
b["events"].open_perf_buffer(print_event, page_cnt=64)
Expand Down
5 changes: 3 additions & 2 deletions tools/solisten.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import argparse
from bcc import BPF
import ctypes as ct
from bcc.utils import printb

# Arguments
examples = """Examples:
Expand Down Expand Up @@ -165,12 +166,12 @@ def print_event(cpu, data, size):

# Display
if show_netns:
print("%-6d %-12.12s %-12s %-6s %-8s %-5s %-39s" % (
printb(b"%-6d %-12.12s %-12s %-6s %-8s %-5s %-39s" % (
pid, event.task, event.netns, protocol, event.backlog,
event.lport, address,
))
else:
print("%-6d %-12.12s %-6s %-8s %-5s %-39s" % (
printb(b"%-6d %-12.12s %-6s %-8s %-5s %-39s" % (
pid, event.task, protocol, event.backlog,
event.lport, address,
))
Expand Down
5 changes: 3 additions & 2 deletions tools/tcpaccept.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from struct import pack
import argparse
import ctypes as ct
from bcc.utils import printb

# arguments
examples = """examples:
Expand Down Expand Up @@ -238,7 +239,7 @@ def print_ipv4_event(cpu, data, size):
if start_ts == 0:
start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
printb(b"%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET, pack("I", event.daddr)),
inet_ntop(AF_INET, pack("I", event.saddr)), event.lport))
Expand All @@ -250,7 +251,7 @@ def print_ipv6_event(cpu, data, size):
if start_ts == 0:
start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
printb(b"%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET6, event.daddr),inet_ntop(AF_INET6, event.saddr),
event.lport))
Expand Down
5 changes: 3 additions & 2 deletions tools/tcpconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from __future__ import print_function
from bcc import BPF
from bcc.utils import printb
import argparse
from socket import inet_ntop, ntohs, AF_INET, AF_INET6
from struct import pack
Expand Down Expand Up @@ -201,7 +202,7 @@ def print_ipv4_event(cpu, data, size):
if start_ts == 0:
start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
printb(b"%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET, pack("I", event.saddr)),
inet_ntop(AF_INET, pack("I", event.daddr)), event.dport))
Expand All @@ -213,7 +214,7 @@ def print_ipv6_event(cpu, data, size):
if start_ts == 0:
start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="")
print("%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
printb(b"%-6d %-12.12s %-2d %-16s %-16s %-4d" % (event.pid,
event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr),
event.dport))
Expand Down

0 comments on commit aed9b1e

Please sign in to comment.