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.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -8,6 +8,8 @@ · 7 unmodified lines | ||
| 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 | |
| @@ -17,6 +19,7 @@ sys.path.append(os.environ['PERF_EXEC_PATH'] + \ · 3 unmodified lines | ||
| 17 | 19 | from perf_trace_context import * |
| 18 | 20 | from Core import * |
| 19 | 21 | from Util import * |
| 22 | +from functools import cmp_to_key | |
| 20 | 23 | |
| 21 | 24 | all_event_list = []; # insert all tracepoint event related with this script |
| 22 | 25 | irq_dic = {}; # key is cpu and value is a list which stacks irqs |
| @@ -61,12 +64,12 @@ def diff_msec(src, dst): · 38 unmodified lines | ||
| 61 | 64 | def print_transmit(hunk): |
| 62 | 65 | if dev != 0 and hunk['dev'].find(dev) < 0: |
| 63 | 66 | return |
| 64 | − print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ | |
| 67 | + print("%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % | |
| 65 | 68 | (hunk['dev'], hunk['len'], |
| 66 | 69 | nsecs_secs(hunk['queue_t']), |
| 67 | 70 | nsecs_nsecs(hunk['queue_t'])/1000, |
| 68 | 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 | 74 | # Format for displaying rx packet processing |
| 72 | 75 | PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" |
| @@ -98,55 +101,55 @@ def print_receive(hunk): · 25 unmodified lines | ||
| 98 | 101 | if show_hunk == 0: |
| 99 | 102 | return |
| 100 | 103 | |
| 101 | − print "%d.%06dsec cpu=%d" % \ | |
| 102 | − (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) | |
| 104 | + print("%d.%06dsec cpu=%d" % | |
| 105 | + (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu)) | |
| 103 | 106 | for i in range(len(irq_list)): |
| 104 | − print PF_IRQ_ENTRY % \ | |
| 107 | + print(PF_IRQ_ENTRY % | |
| 105 | 108 | (diff_msec(base_t, irq_list[i]['irq_ent_t']), |
| 106 | − irq_list[i]['irq'], irq_list[i]['name']) | |
| 107 | − print PF_JOINT | |
| 109 | + irq_list[i]['irq'], irq_list[i]['name'])) | |
| 110 | + print(PF_JOINT) | |
| 108 | 111 | irq_event_list = irq_list[i]['event_list'] |
| 109 | 112 | for j in range(len(irq_event_list)): |
| 110 | 113 | irq_event = irq_event_list[j] |
| 111 | 114 | if irq_event['event'] == 'netif_rx': |
| 112 | − print PF_NET_RX % \ | |
| 115 | + print(PF_NET_RX % | |
| 113 | 116 | (diff_msec(base_t, irq_event['time']), |
| 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 | |
| 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) | |
| 119 | 122 | event_list = hunk['event_list'] |
| 120 | 123 | for i in range(len(event_list)): |
| 121 | 124 | event = event_list[i] |
| 122 | 125 | if event['event_name'] == 'napi_poll': |
| 123 | − print PF_NAPI_POLL % \ | |
| 124 | − (diff_msec(base_t, event['event_t']), event['dev']) | |
| 126 | + print(PF_NAPI_POLL % | |
| 127 | + (diff_msec(base_t, event['event_t']), event['dev'])) | |
| 125 | 128 | if i == len(event_list) - 1: |
| 126 | − print "" | |
| 129 | + print("") | |
| 127 | 130 | else: |
| 128 | − print PF_JOINT | |
| 131 | + print(PF_JOINT) | |
| 129 | 132 | else: |
| 130 | − print PF_NET_RECV % \ | |
| 133 | + print(PF_NET_RECV % | |
| 131 | 134 | (diff_msec(base_t, event['event_t']), event['skbaddr'], |
| 132 | − event['len']) | |
| 135 | + event['len'])) | |
| 133 | 136 | if 'comm' in event.keys(): |
| 134 | − print PF_WJOINT | |
| 135 | − print PF_CPY_DGRAM % \ | |
| 137 | + print(PF_WJOINT) | |
| 138 | + print(PF_CPY_DGRAM % | |
| 136 | 139 | (diff_msec(base_t, event['comm_t']), |
| 137 | − event['pid'], event['comm']) | |
| 140 | + event['pid'], event['comm'])) | |
| 138 | 141 | elif 'handle' in event.keys(): |
| 139 | − print PF_WJOINT | |
| 142 | + print(PF_WJOINT) | |
| 140 | 143 | if event['handle'] == "kfree_skb": |
| 141 | − print PF_KFREE_SKB % \ | |
| 144 | + print(PF_KFREE_SKB % | |
| 142 | 145 | (diff_msec(base_t, |
| 143 | 146 | event['comm_t']), |
| 144 | − event['location']) | |
| 147 | + event['location'])) | |
| 145 | 148 | elif event['handle'] == "consume_skb": |
| 146 | − print PF_CONS_SKB % \ | |
| 149 | + print(PF_CONS_SKB % | |
| 147 | 150 | diff_msec(base_t, |
| 148 | − event['comm_t']) | |
| 149 | − print PF_JOINT | |
| 151 | + event['comm_t'])) | |
| 152 | + print(PF_JOINT) | |
| 150 | 153 | |
| 151 | 154 | def trace_begin(): |
| 152 | 155 | global show_tx |
| @@ -172,8 +175,7 @@ def trace_begin(): · 19 unmodified lines | ||
| 172 | 175 | |
| 173 | 176 | def trace_end(): |
| 174 | 177 | # order all events in time |
| 175 | − all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], | |
| 176 | − b[EINFO_IDX_TIME])) | |
| 178 | + all_event_list.sort(key=cmp_to_key(lambda a,b :a[EINFO_IDX_TIME] < b[EINFO_IDX_TIME])) | |
| 177 | 179 | # process all events |
| 178 | 180 | for i in range(len(all_event_list)): |
| 179 | 181 | event_info = all_event_list[i] |
| @@ -210,19 +212,19 @@ def trace_end(): · 30 unmodified lines | ||
| 210 | 212 | print_receive(receive_hunk_list[i]) |
| 211 | 213 | # display transmit hunks |
| 212 | 214 | if show_tx: |
| 213 | − print " dev len Qdisc " \ | |
| 214 | − " netdevice free" | |
| 215 | + print(" dev len Qdisc " | |
| 216 | + " netdevice free") | |
| 215 | 217 | for i in range(len(tx_free_list)): |
| 216 | 218 | print_transmit(tx_free_list[i]) |
| 217 | 219 | if debug: |
| 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) | |
| 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)) | |
| 226 | 228 | |
| 227 | 229 | # called from perf, when it finds a correspoinding event |
| 228 | 230 | def irq__softirq_entry(name, context, cpu, sec, nsec, pid, comm, callchain, vec): |