diff options
author | Tony Jones <tonyj@suse.de> | 2019-02-22 18:06:05 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-02-25 15:16:42 -0500 |
commit | 02b03ec383e0c79d73aa4b402b3427a8b490ef9f (patch) | |
tree | ccc9b0ef444bdc233ce5d65a00e07d76bff42f48 /tools/perf/scripts/python/netdev-times.py | |
parent | 94816add0005595ea33fc8456519be582330401e (diff) |
perf script python: Add Python3 support to netdev-times.py
Support both Python2 and Python3 in the netdev-times.py script
There may be differences in the ordering of output lines due to
differences in dictionary ordering etc. However the format within lines
should be unchanged.
The use of 'from __future__' implies the minimum supported Python2
version is now v2.6.
Signed-off-by: Tony Jones <tonyj@suse.de>
Cc: Sanagi Koki <sanagi.koki@jp.fujitsu.com>
Link: http://lkml.kernel.org/r/20190222230619.17887-2-tonyj@suse.de
Signed-off-by: Seeteena Thoufeek <s1seetee@linux.vnet.ibm.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/scripts/python/netdev-times.py')
-rw-r--r-- | tools/perf/scripts/python/netdev-times.py | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py index 9b2050f778f1..267bda49325d 100644 --- a/tools/perf/scripts/python/netdev-times.py +++ b/tools/perf/scripts/python/netdev-times.py | |||
@@ -8,6 +8,8 @@ | |||
8 | # dev=: show only thing related to specified device | 8 | # dev=: show only thing related to specified device |
9 | # debug: work with debug mode. It shows buffer status. | 9 | # debug: work with debug mode. It shows buffer status. |
10 | 10 | ||
11 | from __future__ import print_function | ||
12 | |||
11 | import os | 13 | import os |
12 | import sys | 14 | import sys |
13 | 15 | ||
@@ -17,6 +19,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | |||
17 | from perf_trace_context import * | 19 | from perf_trace_context import * |
18 | from Core import * | 20 | from Core import * |
19 | from Util import * | 21 | from Util import * |
22 | from functools import cmp_to_key | ||
20 | 23 | ||
21 | all_event_list = []; # insert all tracepoint event related with this script | 24 | all_event_list = []; # insert all tracepoint event related with this script |
22 | irq_dic = {}; # key is cpu and value is a list which stacks irqs | 25 | irq_dic = {}; # key is cpu and value is a list which stacks irqs |
@@ -61,12 +64,12 @@ def diff_msec(src, dst): | |||
61 | def print_transmit(hunk): | 64 | def print_transmit(hunk): |
62 | if dev != 0 and hunk['dev'].find(dev) < 0: | 65 | if dev != 0 and hunk['dev'].find(dev) < 0: |
63 | return | 66 | return |
64 | print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ | 67 | print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % |
65 | (hunk['dev'], hunk['len'], | 68 | (hunk['dev'], hunk['len'], |
66 | nsecs_secs(hunk['queue_t']), | 69 | nsecs_secs(hunk['queue_t']), |
67 | nsecs_nsecs(hunk['queue_t'])/1000, | 70 | nsecs_nsecs(hunk['queue_t'])/1000, |
68 | diff_msec(hunk['queue_t'], hunk['xmit_t']), | 71 | diff_msec(hunk['queue_t'], hunk['xmit_t']), |
69 | diff_msec(hunk['xmit_t'], hunk['free_t'])) | 72 | diff_msec(hunk['xmit_t'], hunk['free_t']))) |
70 | 73 | ||
71 | # Format for displaying rx packet processing | 74 | # Format for displaying rx packet processing |
72 | PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" | 75 | PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" |
@@ -98,55 +101,55 @@ def print_receive(hunk): | |||
98 | if show_hunk == 0: | 101 | if show_hunk == 0: |
99 | return | 102 | return |
100 | 103 | ||
101 | print "%d.%06dsec cpu=%d" % \ | 104 | print("%d.%06dsec cpu=%d" % |
102 | (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) | 105 | (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)) |
103 | for i in range(len(irq_list)): | 106 | for i in range(len(irq_list)): |
104 | print PF_IRQ_ENTRY % \ | 107 | print(PF_IRQ_ENTRY % |
105 | (diff_msec(base_t, irq_list[i]['irq_ent_t']), | 108 | (diff_msec(base_t, irq_list[i]['irq_ent_t']), |
106 | irq_list[i]['irq'], irq_list[i]['name']) | 109 | irq_list[i]['irq'], irq_list[i]['name'])) |
107 | print PF_JOINT | 110 | print(PF_JOINT) |
108 | irq_event_list = irq_list[i]['event_list'] | 111 | irq_event_list = irq_list[i]['event_list'] |
109 | for j in range(len(irq_event_list)): | 112 | for j in range(len(irq_event_list)): |
110 | irq_event = irq_event_list[j] | 113 | irq_event = irq_event_list[j] |
111 | if irq_event['event'] == 'netif_rx': | 114 | if irq_event['event'] == 'netif_rx': |
112 | print PF_NET_RX % \ | 115 | print(PF_NET_RX % |
113 | (diff_msec(base_t, irq_event['time']), | 116 | (diff_msec(base_t, irq_event['time']), |
114 | irq_event['skbaddr']) | 117 | irq_event['skbaddr'])) |
115 | print PF_JOINT | 118 | print(PF_JOINT) |
116 | print PF_SOFT_ENTRY % \ | 119 | print(PF_SOFT_ENTRY % |
117 | diff_msec(base_t, hunk['sirq_ent_t']) | 120 | diff_msec(base_t, hunk['sirq_ent_t'])) |
118 | print PF_JOINT | 121 | print(PF_JOINT) |
119 | event_list = hunk['event_list'] | 122 | event_list = hunk['event_list'] |
120 | for i in range(len(event_list)): | 123 | for i in range(len(event_list)): |
121 | event = event_list[i] | 124 | event = event_list[i] |
122 | if event['event_name'] == 'napi_poll': | 125 | if event['event_name'] == 'napi_poll': |
123 | print PF_NAPI_POLL % \ | 126 | print(PF_NAPI_POLL % |
124 | (diff_msec(base_t, event['event_t']), event['dev']) | 127 | (diff_msec(base_t, event['event_t']), event['dev'])) |
125 | if i == len(event_list) - 1: | 128 | if i == len(event_list) - 1: |
126 | print "" | 129 | print("") |
127 | else: | 130 | else: |
128 | print PF_JOINT | 131 | print(PF_JOINT) |
129 | else: | 132 | else: |
130 | print PF_NET_RECV % \ | 133 | print(PF_NET_RECV % |
131 | (diff_msec(base_t, event['event_t']), event['skbaddr'], | 134 | (diff_msec(base_t, event['event_t']), event['skbaddr'], |
132 | event['len']) | 135 | event['len'])) |
133 | if 'comm' in event.keys(): | 136 | if 'comm' in event.keys(): |
134 | print PF_WJOINT | 137 | print(PF_WJOINT) |
135 | print PF_CPY_DGRAM % \ | 138 | print(PF_CPY_DGRAM % |
136 | (diff_msec(base_t, event['comm_t']), | 139 | (diff_msec(base_t, event['comm_t']), |
137 | event['pid'], event['comm']) | 140 | event['pid'], event['comm'])) |
138 | elif 'handle' in event.keys(): | 141 | elif 'handle' in event.keys(): |
139 | print PF_WJOINT | 142 | print(PF_WJOINT) |
140 | if event['handle'] == "kfree_skb": | 143 | if event['handle'] == "kfree_skb": |
141 | print PF_KFREE_SKB % \ | 144 | print(PF_KFREE_SKB % |
142 | (diff_msec(base_t, | 145 | (diff_msec(base_t, |
143 | event['comm_t']), | 146 | event['comm_t']), |
144 | event['location']) | 147 | event['location'])) |
145 | elif event['handle'] == "consume_skb": | 148 | elif event['handle'] == "consume_skb": |
146 | print PF_CONS_SKB % \ | 149 | print(PF_CONS_SKB % |
147 | diff_msec(base_t, | 150 | diff_msec(base_t, |
148 | event['comm_t']) | 151 | event['comm_t'])) |
149 | print PF_JOINT | 152 | print(PF_JOINT) |
150 | 153 | ||
151 | def trace_begin(): | 154 | def trace_begin(): |
152 | global show_tx | 155 | global show_tx |
@@ -172,8 +175,7 @@ def trace_begin(): | |||
172 | 175 | ||
173 | def trace_end(): | 176 | def trace_end(): |
174 | # order all events in time | 177 | # order all events in time |
175 | all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], | 178 | all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME])) |
176 | b[EINFO_IDX_TIME])) | ||
177 | # process all events | 179 | # process all events |
178 | for i in range(len(all_event_list)): | 180 | for i in range(len(all_event_list)): |
179 | event_info = all_event_list[i] | 181 | event_info = all_event_list[i] |
@@ -210,19 +212,19 @@ def trace_end(): | |||
210 | print_receive(receive_hunk_list[i]) | 212 | print_receive(receive_hunk_list[i]) |
211 | # display transmit hunks | 213 | # display transmit hunks |
212 | if show_tx: | 214 | if show_tx: |
213 | print " dev len Qdisc " \ | 215 | print(" dev len Qdisc " |
214 | " netdevice free" | 216 | " netdevice free") |
215 | for i in range(len(tx_free_list)): | 217 | for i in range(len(tx_free_list)): |
216 | print_transmit(tx_free_list[i]) | 218 | print_transmit(tx_free_list[i]) |
217 | if debug: | 219 | if debug: |
218 | print "debug buffer status" | 220 | print("debug buffer status") |
219 | print "----------------------------" | 221 | print("----------------------------") |
220 | print "xmit Qdisc:remain:%d overflow:%d" % \ | 222 | print("xmit Qdisc:remain:%d overflow:%d" % |
221 | (len(tx_queue_list), of_count_tx_queue_list) | 223 | (len(tx_queue_list), of_count_tx_queue_list)) |
222 | print "xmit netdevice:remain:%d overflow:%d" % \ | 224 | print("xmit netdevice:remain:%d overflow:%d" % |
223 | (len(tx_xmit_list), of_count_tx_xmit_list) | 225 | (len(tx_xmit_list), of_count_tx_xmit_list)) |
224 | print "receive:remain:%d overflow:%d" % \ | 226 | print("receive:remain:%d overflow:%d" % |
225 | (len(rx_skb_list), of_count_rx_skb_list) | 227 | (len(rx_skb_list), of_count_rx_skb_list)) |
226 | 228 | ||
227 | # called from perf, when it finds a correspoinding event | 229 | # called from perf, when it finds a correspoinding event |
228 | def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec): | 230 | def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec): |