Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Tony Jones and committed by
Arnaldo Carvalho de Melo
02b03ec3 94816add

+42 -40
+42 -40
tools/perf/scripts/python/netdev-times.py
··· 8 8 # dev=: show only thing related to specified device 9 9 # debug: work with debug mode. It shows buffer status. 10 10 11 + from __future__ import print_function 12 + 11 13 import os 12 14 import sys 13 15 ··· 19 17 from perf_trace_context import * 20 18 from Core import * 21 19 from Util import * 20 + from functools import cmp_to_key 22 21 23 22 all_event_list = []; # insert all tracepoint event related with this script 24 23 irq_dic = {}; # key is cpu and value is a list which stacks irqs ··· 64 61 def print_transmit(hunk): 65 62 if dev != 0 and hunk['dev'].find(dev) < 0: 66 63 return 67 - print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ 64 + print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % 68 65 (hunk['dev'], hunk['len'], 69 66 nsecs_secs(hunk['queue_t']), 70 67 nsecs_nsecs(hunk['queue_t'])/1000, 71 68 diff_msec(hunk['queue_t'], hunk['xmit_t']), 72 - diff_msec(hunk['xmit_t'], hunk['free_t'])) 69 + diff_msec(hunk['xmit_t'], hunk['free_t']))) 73 70 74 71 # Format for displaying rx packet processing 75 72 PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" ··· 101 98 if show_hunk == 0: 102 99 return 103 100 104 - print "%d.%06dsec cpu=%d" % \ 105 - (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) 101 + print("%d.%06dsec cpu=%d" % 102 + (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)) 106 103 for i in range(len(irq_list)): 107 - print PF_IRQ_ENTRY % \ 104 + print(PF_IRQ_ENTRY % 108 105 (diff_msec(base_t, irq_list[i]['irq_ent_t']), 109 - irq_list[i]['irq'], irq_list[i]['name']) 110 - print PF_JOINT 106 + irq_list[i]['irq'], irq_list[i]['name'])) 107 + print(PF_JOINT) 111 108 irq_event_list = irq_list[i]['event_list'] 112 109 for j in range(len(irq_event_list)): 113 110 irq_event = irq_event_list[j] 114 111 if irq_event['event'] == 'netif_rx': 115 - print PF_NET_RX % \ 112 + print(PF_NET_RX % 116 113 (diff_msec(base_t, irq_event['time']), 117 - irq_event['skbaddr']) 118 - print PF_JOINT 119 - print PF_SOFT_ENTRY % \ 120 - diff_msec(base_t, hunk['sirq_ent_t']) 121 - print PF_JOINT 114 + irq_event['skbaddr'])) 115 + print(PF_JOINT) 116 + print(PF_SOFT_ENTRY % 117 + diff_msec(base_t, hunk['sirq_ent_t'])) 118 + print(PF_JOINT) 122 119 event_list = hunk['event_list'] 123 120 for i in range(len(event_list)): 124 121 event = event_list[i] 125 122 if event['event_name'] == 'napi_poll': 126 - print PF_NAPI_POLL % \ 127 - (diff_msec(base_t, event['event_t']), event['dev']) 123 + print(PF_NAPI_POLL % 124 + (diff_msec(base_t, event['event_t']), event['dev'])) 128 125 if i == len(event_list) - 1: 129 - print "" 126 + print("") 130 127 else: 131 - print PF_JOINT 128 + print(PF_JOINT) 132 129 else: 133 - print PF_NET_RECV % \ 130 + print(PF_NET_RECV % 134 131 (diff_msec(base_t, event['event_t']), event['skbaddr'], 135 - event['len']) 132 + event['len'])) 136 133 if 'comm' in event.keys(): 137 - print PF_WJOINT 138 - print PF_CPY_DGRAM % \ 134 + print(PF_WJOINT) 135 + print(PF_CPY_DGRAM % 139 136 (diff_msec(base_t, event['comm_t']), 140 - event['pid'], event['comm']) 137 + event['pid'], event['comm'])) 141 138 elif 'handle' in event.keys(): 142 - print PF_WJOINT 139 + print(PF_WJOINT) 143 140 if event['handle'] == "kfree_skb": 144 - print PF_KFREE_SKB % \ 141 + print(PF_KFREE_SKB % 145 142 (diff_msec(base_t, 146 143 event['comm_t']), 147 - event['location']) 144 + event['location'])) 148 145 elif event['handle'] == "consume_skb": 149 - print PF_CONS_SKB % \ 146 + print(PF_CONS_SKB % 150 147 diff_msec(base_t, 151 - event['comm_t']) 152 - print PF_JOINT 148 + event['comm_t'])) 149 + print(PF_JOINT) 153 150 154 151 def trace_begin(): 155 152 global show_tx ··· 175 172 176 173 def trace_end(): 177 174 # order all events in time 178 - all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], 179 - b[EINFO_IDX_TIME])) 175 + all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME])) 180 176 # process all events 181 177 for i in range(len(all_event_list)): 182 178 event_info = all_event_list[i] ··· 212 210 print_receive(receive_hunk_list[i]) 213 211 # display transmit hunks 214 212 if show_tx: 215 - print " dev len Qdisc " \ 216 - " netdevice free" 213 + print(" dev len Qdisc " 214 + " netdevice free") 217 215 for i in range(len(tx_free_list)): 218 216 print_transmit(tx_free_list[i]) 219 217 if debug: 220 - print "debug buffer status" 221 - print "----------------------------" 222 - print "xmit Qdisc:remain:%d overflow:%d" % \ 223 - (len(tx_queue_list), of_count_tx_queue_list) 224 - print "xmit netdevice:remain:%d overflow:%d" % \ 225 - (len(tx_xmit_list), of_count_tx_xmit_list) 226 - print "receive:remain:%d overflow:%d" % \ 227 - (len(rx_skb_list), of_count_rx_skb_list) 218 + print("debug buffer status") 219 + print("----------------------------") 220 + print("xmit Qdisc:remain:%d overflow:%d" % 221 + (len(tx_queue_list), of_count_tx_queue_list)) 222 + print("xmit netdevice:remain:%d overflow:%d" % 223 + (len(tx_xmit_list), of_count_tx_xmit_list)) 224 + print("receive:remain:%d overflow:%d" % 225 + (len(rx_skb_list), of_count_rx_skb_list)) 228 226 229 227 # called from perf, when it finds a correspoinding event 230 228 def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec):