From d0764aae3224c6f99293032e6ac3bfca4d678713 Mon Sep 17 00:00:00 2001 From: Jean-Tiare Le Bigot Date: Sun, 21 Feb 2016 23:45:29 +0100 Subject: [PATCH] make tcpv4connect.py example tracer more robust --- examples/tracing/tcpv4connect.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/tracing/tcpv4connect.py b/examples/tracing/tcpv4connect.py index b5a10626b3c8..6841115e4010 100755 --- a/examples/tracing/tcpv4connect.py +++ b/examples/tracing/tcpv4connect.py @@ -62,7 +62,7 @@ bpf_probe_read(&dport, sizeof(dport), &skp->__sk_common.skc_dport); // output - bpf_trace_printk("%x %x %d\\n", saddr, daddr, ntohs(dport)); + bpf_trace_printk("trace_tcp4connect %x %x %d\\n", saddr, daddr, ntohs(dport)); currsock.delete(&pid); @@ -86,10 +86,19 @@ def inet_ntoa(addr): addr = addr >> 8 return dq -# format output +# filter and format output while 1: - (task, pid, cpu, flags, ts, msg) = b.trace_fields() - (saddr_hs, daddr_hs, dport_s) = msg.split(" ") + # Read messages from kernel pipe + try: + (task, pid, cpu, flags, ts, msg) = b.trace_fields() + (_tag, saddr_hs, daddr_hs, dport_s) = msg.split(" ") + except ValueError: + # Ignore messages from other tracers + continue + + # Ignore messages from other tracers + if _tag != "trace_tcp4connect": + continue print("%-6d %-12.12s %-16s %-16s %-4s" % (pid, task, inet_ntoa(int(saddr_hs, 16)),