Commit aed9b1e2 authored by japroc's avatar japroc Committed by yonghong-song

Add stdout flushing to some tools (#2110)

* add stdout flushing to some tools

* change printb import source in opensnoop tool
parent c5a448a1
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
from __future__ import print_function from __future__ import print_function
from bcc import ArgString, BPF from bcc import ArgString, BPF
from bcc.utils import printb
import argparse import argparse
import ctypes as ct import ctypes as ct
from datetime import datetime, timedelta from datetime import datetime, timedelta
...@@ -222,7 +223,7 @@ def print_event(cpu, data, size): ...@@ -222,7 +223,7 @@ def print_event(cpu, data, size):
if args.extended_fields: if args.extended_fields:
print("%08o " % event.flags, end="") 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 # loop with callback to print_event
b["events"].open_perf_buffer(print_event, page_cnt=64) b["events"].open_perf_buffer(print_event, page_cnt=64)
......
...@@ -23,6 +23,7 @@ from struct import pack ...@@ -23,6 +23,7 @@ from struct import pack
import argparse import argparse
from bcc import BPF from bcc import BPF
import ctypes as ct import ctypes as ct
from bcc.utils import printb
# Arguments # Arguments
examples = """Examples: examples = """Examples:
...@@ -165,12 +166,12 @@ def event_printer(show_netns): ...@@ -165,12 +166,12 @@ def event_printer(show_netns):
# Display # Display
if show_netns: 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, pid, event.task, event.netns, protocol, event.backlog,
event.lport, address, event.lport, address,
)) ))
else: else:
print("%-6d %-12.12s %-6s %-8s %-5s %-39s" % ( printb(b"%-6d %-12.12s %-6s %-8s %-5s %-39s" % (
pid, event.task, protocol, event.backlog, pid, event.task, protocol, event.backlog,
event.lport, address, event.lport, address,
)) ))
......
...@@ -21,6 +21,7 @@ from socket import inet_ntop, AF_INET, AF_INET6 ...@@ -21,6 +21,7 @@ from socket import inet_ntop, AF_INET, AF_INET6
from struct import pack from struct import pack
import argparse import argparse
import ctypes as ct import ctypes as ct
from bcc.utils import printb
# arguments # arguments
examples = """examples: examples = """examples:
...@@ -238,7 +239,7 @@ def print_ipv4_event(cpu, data, size): ...@@ -238,7 +239,7 @@ def print_ipv4_event(cpu, data, size):
if start_ts == 0: if start_ts == 0:
start_ts = event.ts_us start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="") 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, event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET, pack("I", event.daddr)), inet_ntop(AF_INET, pack("I", event.daddr)),
inet_ntop(AF_INET, pack("I", event.saddr)), event.lport)) inet_ntop(AF_INET, pack("I", event.saddr)), event.lport))
...@@ -250,7 +251,7 @@ def print_ipv6_event(cpu, data, size): ...@@ -250,7 +251,7 @@ def print_ipv6_event(cpu, data, size):
if start_ts == 0: if start_ts == 0:
start_ts = event.ts_us start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="") 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, event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET6, event.daddr),inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr),inet_ntop(AF_INET6, event.saddr),
event.lport)) event.lport))
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
from __future__ import print_function from __future__ import print_function
from bcc import BPF from bcc import BPF
from bcc.utils import printb
import argparse import argparse
from socket import inet_ntop, ntohs, AF_INET, AF_INET6 from socket import inet_ntop, ntohs, AF_INET, AF_INET6
from struct import pack from struct import pack
...@@ -201,7 +202,7 @@ def print_ipv4_event(cpu, data, size): ...@@ -201,7 +202,7 @@ def print_ipv4_event(cpu, data, size):
if start_ts == 0: if start_ts == 0:
start_ts = event.ts_us start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="") 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, event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET, pack("I", event.saddr)), inet_ntop(AF_INET, pack("I", event.saddr)),
inet_ntop(AF_INET, pack("I", event.daddr)), event.dport)) inet_ntop(AF_INET, pack("I", event.daddr)), event.dport))
...@@ -213,7 +214,7 @@ def print_ipv6_event(cpu, data, size): ...@@ -213,7 +214,7 @@ def print_ipv6_event(cpu, data, size):
if start_ts == 0: if start_ts == 0:
start_ts = event.ts_us start_ts = event.ts_us
print("%-9.3f" % ((float(event.ts_us) - start_ts) / 1000000), end="") 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, event.task.decode('utf-8', 'replace'), event.ip,
inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr), inet_ntop(AF_INET6, event.saddr), inet_ntop(AF_INET6, event.daddr),
event.dport)) event.dport))
......
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