examples/tracing: Use printb to improve python3 compatibility
When using python3, 'print' will output the bytes arrays with the "b"
prefix. Switch to printb to get rid of the prefix.
Signed-off-by: Gary Lin <glin@suse.com>
diff --git a/examples/tracing/tcpv4connect.py b/examples/tracing/tcpv4connect.py
index 8a89469..81385e8 100755
--- a/examples/tracing/tcpv4connect.py
+++ b/examples/tracing/tcpv4connect.py
@@ -16,6 +16,7 @@
from __future__ import print_function
from bcc import BPF
+from bcc.utils import printb
# define BPF program
bpf_text = """
@@ -76,11 +77,11 @@
"DPORT"))
def inet_ntoa(addr):
- dq = ''
+ dq = b''
for i in range(0, 4):
- dq = dq + str(addr & 0xff)
+ dq = dq + str(addr & 0xff).encode()
if (i != 3):
- dq = dq + '.'
+ dq = dq + b'.'
addr = addr >> 8
return dq
@@ -89,7 +90,7 @@
# Read messages from kernel pipe
try:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
- (_tag, saddr_hs, daddr_hs, dport_s) = msg.split(" ")
+ (_tag, saddr_hs, daddr_hs, dport_s) = msg.split(b" ")
except ValueError:
# Ignore messages from other tracers
continue
@@ -98,7 +99,7 @@
if _tag != "trace_tcp4connect":
continue
- print("%-6d %-12.12s %-16s %-16s %-4s" % (pid, task,
+ printb(b"%-6d %-12.12s %-16s %-16s %-4s" % (pid, task,
inet_ntoa(int(saddr_hs, 16)),
inet_ntoa(int(daddr_hs, 16)),
dport_s))