tools: don't mix print(end="") with printb()
While mixing print(end="") with printb(), some messages may miss due to
the underlying buffer handling in python 3.
For example:
# python3 opensnoop.py
PID COMM FD ERR PATH
/proc/18849/cmdline
4109 tmux: server 67 0 /proc/18849/cmdline
4109 tmux: server 67 0 /proc/18849/cmdline
4109 tmux: server 67 0 /proc/18849/cmdline
The PID, COMM, FD, and ERR are printed with print(end=""), and those of
the first instance was eaten by printb() which outputs PATH.
The following scripts mix print(end="") and printb() for the same line:
tools/execsnoop.py
tools/opensnoop.py
tools/tcpaccept.py
tools/tcpconnect.py
Those scripts work fine with python 2 but some messages may miss while
using python 3.
This commit converts print(end="") to printb(nl="") to avoid the
inconsistent outputs.
Signed-off-by: Gary Lin <glin@suse.com>
diff --git a/tools/opensnoop.py b/tools/opensnoop.py
index 4ffedfa..60d11c6 100755
--- a/tools/opensnoop.py
+++ b/tools/opensnoop.py
@@ -218,17 +218,17 @@
if args.timestamp:
delta = event.ts - initial_ts
- print("%-14.9f" % (float(delta) / 1000000), end="")
+ printb(b"%-14.9f" % (float(delta) / 1000000), nl="")
if args.print_uid:
- print("%-6d" % event.uid, end="")
+ printb(b"%-6d" % event.uid, nl="")
- print("%-6d %-16s %4d %3d " %
- (event.id & 0xffffffff if args.tid else event.id >> 32,
- event.comm.decode('utf-8', 'replace'), fd_s, err), end="")
+ printb(b"%-6d %-16s %4d %3d " %
+ (event.id & 0xffffffff if args.tid else event.id >> 32,
+ event.comm, fd_s, err), nl="")
if args.extended_fields:
- print("%08o " % event.flags, end="")
+ printb(b"%08o " % event.flags, nl="")
printb(b'%s' % event.fname)