diff --git a/scripts/gdb/linux/lists.py b/scripts/gdb/linux/lists.py index 2f335fbd86fd5..51dd0bf7815bf 100644 --- a/scripts/gdb/linux/lists.py +++ b/scripts/gdb/linux/lists.py @@ -41,9 +41,9 @@ def list_for_each_entry(head, gdbtype, member): def list_check(head): nb = 0 - if (head.type == list_head.get_type().pointer()): + if head.type == list_head.get_type().pointer(): head = head.dereference() - elif (head.type != list_head.get_type()): + elif head.type != list_head.get_type(): raise gdb.GdbError('argument must be of type (struct list_head [*])') c = head try: @@ -90,9 +90,8 @@ def list_check(head): current=c )) return - c = n nb += 1 - if c == head: + if n == head: gdb.write("list is consistent: {} node(s)\n".format(nb)) return @@ -106,7 +105,7 @@ def __init__(self): def invoke(self, arg, from_tty): argv = gdb.string_to_argv(arg) - if len(argv) != 1: + if not argv: raise gdb.GdbError("lx-list-check takes one argument") list_check(gdb.parse_and_eval(argv[0])) diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index b19172d673af9..5154c1d16c2f3 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py @@ -28,7 +28,7 @@ def trace_end(): print "End" def trace_unhandled(event_name, context, event_fields_dict): - print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) + print " ".join("%s=%s" % pair for pair in sorted(event_fields_dict.items())) def print_ptwrite(raw_buf): data = struct.unpack_from("> 32) & 0x3 - print "hints: %#x extensions: %#x" % (hints, extensions), + print "hints: %#x extensions: %#x" % (hints, extensions) def print_pwre(raw_buf): data = struct.unpack_from("> 7) & 1 cstate = (payload >> 12) & 0xf subcstate = (payload >> 8) & 0xf - print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), + print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate) def print_exstop(raw_buf): data = struct.unpack_from("> 4) & 0xf wake_reason = (payload >> 8) & 0xf - print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), + print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason) def print_common_start(comm, sample, name): ts = sample["time"] cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), + print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 10**9, ts % 10**9, name) def print_common_ip(sample, symbol, dso): - ip = sample["ip"] - print "%16x %s (%s)" % (ip, symbol, dso) + print "%16x %s (%s)" % (sample["ip"], symbol, dso) def process_event(param_dict): event_attr = param_dict["attr"] @@ -92,37 +91,12 @@ def process_event(param_dict): name = param_dict["ev_name"] # Symbol and dso info are not always resolved - if (param_dict.has_key("dso")): - dso = param_dict["dso"] - else: - dso = "[unknown]" - - if (param_dict.has_key("symbol")): - symbol = param_dict["symbol"] - else: - symbol = "[unknown]" - - if name == "ptwrite": - print_common_start(comm, sample, name) - print_ptwrite(raw_buf) - print_common_ip(sample, symbol, dso) - elif name == "cbr": - print_common_start(comm, sample, name) - print_cbr(raw_buf) - print_common_ip(sample, symbol, dso) - elif name == "mwait": - print_common_start(comm, sample, name) - print_mwait(raw_buf) - print_common_ip(sample, symbol, dso) - elif name == "pwre": - print_common_start(comm, sample, name) - print_pwre(raw_buf) - print_common_ip(sample, symbol, dso) - elif name == "exstop": - print_common_start(comm, sample, name) - print_exstop(raw_buf) - print_common_ip(sample, symbol, dso) - elif name == "pwrx": + dso = param_dict.get("dso", "[unknown]") + symbol = param_dict.get("symbol", "[unknown") + + func = globals().get("print_%s" % name, None) + + if func is not None: print_common_start(comm, sample, name) - print_pwrx(raw_buf) + func(raw_buf) print_common_ip(sample, symbol, dso) diff --git a/tools/perf/scripts/python/mem-phys-addr.py b/tools/perf/scripts/python/mem-phys-addr.py index ebee2c5ae4969..e655588cf7dbc 100644 --- a/tools/perf/scripts/python/mem-phys-addr.py +++ b/tools/perf/scripts/python/mem-phys-addr.py @@ -27,24 +27,24 @@ def parse_iomem(): global f - f = open('/proc/iomem', 'r') + f = open('/proc/iomem') for i, j in enumerate(f): - m = re.split('-|:',j,2) - if m[2].strip() == 'System RAM': - system_ram.append(long(m[0], 16)) - system_ram.append(long(m[1], 16)) - if m[2].strip() == 'Persistent Memory': - pmem.append(long(m[0], 16)) - pmem.append(long(m[1], 16)) + m = re.split('-|:', j, 2) + m[2] = m[2].strip() + if m[2] == 'System RAM': + system_ram.extend([long(m[0], 16), long(m[1], 16)]) + elif m[2] == 'Persistent Memory': + pmem.extend([long(m[0], 16), long(m[1], 16)]) def print_memory_type(): - print "Event: %s" % (event_name) + print "Event: %s" % event_name print "%-40s %10s %10s\n" % ("Memory type", "count", "percentage"), print "%-40s %10s %10s\n" % ("----------------------------------------", \ "-----------", "-----------"), total = sum(load_mem_type_cnt.values()) - for mem_type, count in sorted(load_mem_type_cnt.most_common(), \ - key = lambda(k, v): (v, k), reverse = True): + for mem_type, count in sorted(load_mem_type_cnt.most_common(), + key = lambda k, v: v, k, + reverse = True): print "%-40s %10d %10.1f%%\n" % (mem_type, count, 100 * count / total), def trace_begin(): @@ -57,29 +57,24 @@ def trace_end(): def is_system_ram(phys_addr): #/proc/iomem is sorted position = bisect.bisect(system_ram, phys_addr) - if position % 2 == 0: - return False - return True + return position & 1 def is_persistent_mem(phys_addr): position = bisect.bisect(pmem, phys_addr) - if position % 2 == 0: - return False - return True + return position & 1 def find_memory_type(phys_addr): - if phys_addr == 0: + if not phys_addr: return "N/A" - if is_system_ram(phys_addr): + elif is_system_ram(phys_addr): return "System RAM" - - if is_persistent_mem(phys_addr): + elif is_persistent_mem(phys_addr): return "Persistent Memory" #slow path, search all f.seek(0, 0) for j in f: - m = re.split('-|:',j,2) + m = re.split('-|:', j, 2) if long(m[0], 16) <= phys_addr <= long(m[1], 16): return m[2] return "N/A" @@ -90,6 +85,6 @@ def process_event(param_dict): phys_addr = sample["phys_addr"] global event_name - if event_name == None: + if event_name is None: event_name = name load_mem_type_cnt[find_memory_type(phys_addr)] += 1 diff --git a/tools/perf/scripts/python/net_dropmonitor.py b/tools/perf/scripts/python/net_dropmonitor.py index a150164b44a3f..3bdb874f0f52d 100755 --- a/tools/perf/scripts/python/net_dropmonitor.py +++ b/tools/perf/scripts/python/net_dropmonitor.py @@ -18,8 +18,8 @@ def get_kallsyms_table(): global kallsyms try: - f = open("/proc/kallsyms", "r") - except: + f = open("/proc/kallsyms") + except IOError: return for line in f: @@ -45,9 +45,8 @@ def get_sym(sloc): # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0]) if start >= 0: symloc, name = kallsyms[start] - return (name, loc - symloc) - else: - return (None, 0) + return name, loc - symloc + return None, 0 def print_drop_table(): print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") @@ -66,11 +65,11 @@ def trace_end(): get_kallsyms_table() print_drop_table() -# called from perf, when it finds a correspoinding event +# called from perf, when it finds a corresponding event def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr, location, protocol): slocation = str(location) try: - drop_log[slocation] = drop_log[slocation] + 1 - except: + drop_log[slocation] += 1 + except TypeError: drop_log[slocation] = 1 diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py index 9b2050f778f10..01e64eb3b189c 100644 --- a/tools/perf/scripts/python/netdev-times.py +++ b/tools/perf/scripts/python/netdev-times.py @@ -18,40 +18,40 @@ from Core import * from Util import * -all_event_list = []; # insert all tracepoint event related with this script -irq_dic = {}; # key is cpu and value is a list which stacks irqs +all_event_list = [] # insert all tracepoint event related with this script +irq_dic = {} # key is cpu and value is a list which stacks irqs # which raise NET_RX softirq -net_rx_dic = {}; # key is cpu and value include time of NET_RX softirq-entry +net_rx_dic = {} # key is cpu and value include time of NET_RX softirq-entry # and a list which stacks receive -receive_hunk_list = []; # a list which include a sequence of receive events -rx_skb_list = []; # received packet list for matching +receive_hunk_list = [] # a list which include a sequence of receive events +rx_skb_list = [] # received packet list for matching # skb_copy_datagram_iovec -buffer_budget = 65536; # the budget of rx_skb_list, tx_queue_list and +buffer_budget = 65536 # the budget of rx_skb_list, tx_queue_list and # tx_xmit_list -of_count_rx_skb_list = 0; # overflow count +of_count_rx_skb_list = 0 # overflow count -tx_queue_list = []; # list of packets which pass through dev_queue_xmit -of_count_tx_queue_list = 0; # overflow count +tx_queue_list = [] # list of packets which pass through dev_queue_xmit +of_count_tx_queue_list = 0 # overflow count -tx_xmit_list = []; # list of packets which pass through dev_hard_start_xmit -of_count_tx_xmit_list = 0; # overflow count +tx_xmit_list = [] # list of packets which pass through dev_hard_start_xmit +of_count_tx_xmit_list = 0 # overflow count -tx_free_list = []; # list of packets which is freed +tx_free_list = [] # list of packets which is freed # options -show_tx = 0; -show_rx = 0; -dev = 0; # store a name of device specified by option "dev=" -debug = 0; +show_tx = 0 +show_rx = 0 +dev = 0 # store a name of device specified by option "dev=" +debug = 0 # indices of event_info tuple -EINFO_IDX_NAME= 0 -EINFO_IDX_CONTEXT=1 -EINFO_IDX_CPU= 2 -EINFO_IDX_TIME= 3 -EINFO_IDX_PID= 4 -EINFO_IDX_COMM= 5 +EINFO_IDX_NAME = 0 +EINFO_IDX_CONTEXT = 1 +EINFO_IDX_CPU = 2 +EINFO_IDX_TIME = 3 +EINFO_IDX_PID = 4 +EINFO_IDX_COMM = 5 # Calculate a time interval(msec) from src(nsec) to dst(nsec) def diff_msec(src, dst): @@ -59,7 +59,7 @@ def diff_msec(src, dst): # Display a process of transmitting a packet def print_transmit(hunk): - if dev != 0 and hunk['dev'].find(dev) < 0: + if dev and hunk['dev'].find(dev) < 0: return print "%7s %5d %6d.%06dsec %12.3fmsec %12.3fmsec" % \ (hunk['dev'], hunk['len'], @@ -69,16 +69,16 @@ def print_transmit(hunk): diff_msec(hunk['xmit_t'], hunk['free_t'])) # Format for displaying rx packet processing -PF_IRQ_ENTRY= " irq_entry(+%.3fmsec irq=%d:%s)" -PF_SOFT_ENTRY=" softirq_entry(+%.3fmsec)" -PF_NAPI_POLL= " napi_poll_exit(+%.3fmsec %s)" -PF_JOINT= " |" -PF_WJOINT= " | |" -PF_NET_RECV= " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)" -PF_NET_RX= " |---netif_rx(+%.3fmsec skb=%x)" -PF_CPY_DGRAM= " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)" -PF_KFREE_SKB= " | kfree_skb(+%.3fmsec location=%x)" -PF_CONS_SKB= " | consume_skb(+%.3fmsec)" +PF_IRQ_ENTRY = " irq_entry(+%.3fmsec irq=%d:%s)" +PF_SOFT_ENTRY = " softirq_entry(+%.3fmsec)" +PF_NAPI_POLL = " napi_poll_exit(+%.3fmsec %s)" +PF_JOINT = " |" +PF_WJOINT = " | |" +PF_NET_RECV = " |---netif_receive_skb(+%.3fmsec skb=%x len=%d)" +PF_NET_RX = " |---netif_rx(+%.3fmsec skb=%x)" +PF_CPY_DGRAM = " | skb_copy_datagram_iovec(+%.3fmsec %d:%s)" +PF_KFREE_SKB = " | kfree_skb(+%.3fmsec location=%x)" +PF_CONS_SKB = " | consume_skb(+%.3fmsec)" # Display a process of received packets and interrputs associated with # a NET_RX softirq @@ -88,26 +88,26 @@ def print_receive(hunk): cpu = irq_list[0]['cpu'] base_t = irq_list[0]['irq_ent_t'] # check if this hunk should be showed - if dev != 0: - for i in range(len(irq_list)): - if irq_list[i]['name'].find(dev) >= 0: + if dev: + for v in irq_list: + if v['name'].find(dev) >= 0: show_hunk = 1 break else: show_hunk = 1 - if show_hunk == 0: + if not show_hunk: return print "%d.%06dsec cpu=%d" % \ (nsecs_secs(base_t), nsecs_nsecs(base_t)/1000, cpu) - for i in range(len(irq_list)): + for i in irq_list: print PF_IRQ_ENTRY % \ - (diff_msec(base_t, irq_list[i]['irq_ent_t']), - irq_list[i]['irq'], irq_list[i]['name']) + (diff_msec(base_t, i['irq_ent_t']), + i['irq'], i['name']) print PF_JOINT - irq_event_list = irq_list[i]['event_list'] - for j in range(len(irq_event_list)): - irq_event = irq_event_list[j] + irq_event_list = i['event_list'] + for j in irq_event_list: + irq_event = j if irq_event['event'] == 'netif_rx': print PF_NET_RX % \ (diff_msec(base_t, irq_event['time']), @@ -117,13 +117,13 @@ def print_receive(hunk): diff_msec(base_t, hunk['sirq_ent_t']) print PF_JOINT event_list = hunk['event_list'] - for i in range(len(event_list)): - event = event_list[i] + for i in event_list: + event = i if event['event_name'] == 'napi_poll': print PF_NAPI_POLL % \ (diff_msec(base_t, event['event_t']), event['dev']) - if i == len(event_list) - 1: - print "" + if i == event_list[-1]: + print else: print PF_JOINT else: @@ -154,66 +154,40 @@ def trace_begin(): global dev global debug - for i in range(len(sys.argv)): - if i == 0: - continue - arg = sys.argv[i] + for arg in sys.argv[1:]: if arg == 'tx': show_tx = 1 elif arg =='rx': show_rx = 1 - elif arg.find('dev=',0, 4) >= 0: + elif arg.find('dev=', 0, 4) >= 0: dev = arg[4:] elif arg == 'debug': debug = 1 - if show_tx == 0 and show_rx == 0: - show_tx = 1 - show_rx = 1 + if not show_tx and not show_rx: + show_tx = show_rx = 1 def trace_end(): # order all events in time all_event_list.sort(lambda a,b :cmp(a[EINFO_IDX_TIME], b[EINFO_IDX_TIME])) # process all events - for i in range(len(all_event_list)): - event_info = all_event_list[i] - name = event_info[EINFO_IDX_NAME] - if name == 'irq__softirq_exit': - handle_irq_softirq_exit(event_info) - elif name == 'irq__softirq_entry': - handle_irq_softirq_entry(event_info) - elif name == 'irq__softirq_raise': - handle_irq_softirq_raise(event_info) - elif name == 'irq__irq_handler_entry': - handle_irq_handler_entry(event_info) - elif name == 'irq__irq_handler_exit': - handle_irq_handler_exit(event_info) - elif name == 'napi__napi_poll': - handle_napi_poll(event_info) - elif name == 'net__netif_receive_skb': - handle_netif_receive_skb(event_info) - elif name == 'net__netif_rx': - handle_netif_rx(event_info) - elif name == 'skb__skb_copy_datagram_iovec': - handle_skb_copy_datagram_iovec(event_info) - elif name == 'net__net_dev_queue': - handle_net_dev_queue(event_info) - elif name == 'net__net_dev_xmit': - handle_net_dev_xmit(event_info) - elif name == 'skb__kfree_skb': - handle_kfree_skb(event_info) - elif name == 'skb__consume_skb': - handle_consume_skb(event_info) + for event_info in all_event_list: + name = event_info[EINFO_IDX_NAME].split("__")[-1] + + func = globals().get("handle_%s" % name, None) + if func is not None: + func(event_info) + # display receive hunks if show_rx: - for i in range(len(receive_hunk_list)): - print_receive(receive_hunk_list[i]) + for i in receive_hunk_list: + print_receive(i) # display transmit hunks if show_tx: print " dev len Qdisc " \ " netdevice free" - for i in range(len(tx_free_list)): - print_transmit(tx_free_list[i]) + for i in tx_free_list: + print_transmit(i) if debug: print "debug buffer status" print "----------------------------" @@ -348,7 +322,7 @@ def handle_irq_softirq_exit(event_info): sirq_ent_t = net_rx_dic[cpu]['sirq_ent_t'] event_list = net_rx_dic[cpu]['event_list'] del net_rx_dic[cpu] - if irq_list == [] or event_list == 0: + if not irq_list or not event_list: return rec_data = {'sirq_ent_t':sirq_ent_t, 'sirq_ext_t':time, 'irq_list':irq_list, 'event_list':event_list} @@ -369,7 +343,7 @@ def handle_netif_rx(event_info): (name, context, cpu, time, pid, comm, skbaddr, skblen, dev_name) = event_info if cpu not in irq_dic.keys() \ - or len(irq_dic[cpu]) == 0: + or not irq_dic[cpu]: return irq_record = irq_dic[cpu].pop() if 'event_list' in irq_record.keys(): @@ -401,7 +375,12 @@ def handle_net_dev_queue(event_info): (name, context, cpu, time, pid, comm, skbaddr, skblen, dev_name) = event_info - skb = {'dev':dev_name, 'skbaddr':skbaddr, 'len':skblen, 'queue_t':time} + skb = { + 'dev': dev_name, + 'skbaddr': skbaddr, + 'len': skblen, + 'queue_t': time + } tx_queue_list.insert(0, skb) if len(tx_queue_list) > buffer_budget: tx_queue_list.pop() @@ -412,7 +391,7 @@ def handle_net_dev_xmit(event_info): (name, context, cpu, time, pid, comm, skbaddr, skblen, rc, dev_name) = event_info - if rc == 0: # NETDEV_TX_OK + if not rc: # NETDEV_TX_OK for i in range(len(tx_queue_list)): skb = tx_queue_list[i] if skb['skbaddr'] == skbaddr: @@ -427,20 +406,17 @@ def handle_net_dev_xmit(event_info): def handle_kfree_skb(event_info): (name, context, cpu, time, pid, comm, skbaddr, protocol, location) = event_info - for i in range(len(tx_queue_list)): - skb = tx_queue_list[i] + for i, skb in enumerate(tx_queue_list): if skb['skbaddr'] == skbaddr: del tx_queue_list[i] return - for i in range(len(tx_xmit_list)): - skb = tx_xmit_list[i] + for i, skb in enumerate(tx_xmit_list): if skb['skbaddr'] == skbaddr: skb['free_t'] = time tx_free_list.append(skb) del tx_xmit_list[i] return - for i in range(len(rx_skb_list)): - rec_data = rx_skb_list[i] + for i, rec_data in rx_skb_list: if rec_data['skbaddr'] == skbaddr: rec_data.update({'handle':"kfree_skb", 'comm':comm, 'pid':pid, 'comm_t':time}) @@ -449,8 +425,7 @@ def handle_kfree_skb(event_info): def handle_consume_skb(event_info): (name, context, cpu, time, pid, comm, skbaddr) = event_info - for i in range(len(tx_xmit_list)): - skb = tx_xmit_list[i] + for i, skb in enumerate(tx_xmit_list): if skb['skbaddr'] == skbaddr: skb['free_t'] = time tx_free_list.append(skb) @@ -459,8 +434,7 @@ def handle_consume_skb(event_info): def handle_skb_copy_datagram_iovec(event_info): (name, context, cpu, time, pid, comm, skbaddr, skblen) = event_info - for i in range(len(rx_skb_list)): - rec_data = rx_skb_list[i] + for i, rec_data in enumerate(rx_skb_list): if skbaddr == rec_data['skbaddr']: rec_data.update({'handle':"skb_copy_datagram_iovec", 'comm':comm, 'pid':pid, 'comm_t':time}) diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py index 1697b5e18c962..4e029e8024921 100755 --- a/tools/perf/scripts/python/stackcollapse.py +++ b/tools/perf/scripts/python/stackcollapse.py @@ -55,7 +55,7 @@ parser = OptionParser(option_list=option_list) (opts, args) = parser.parse_args() -if len(args) != 0: +if args: parser.error("unexpected command line argument") if opts.include_tid and not opts.include_comm: parser.error("requesting tid but not comm is invalid") @@ -89,8 +89,7 @@ def tidy_function_name(sym, dso): if opts.annotate_kernel and dso == '[kernel.kallsyms]': return sym + '_[k]' - else: - return sym + return sym stack = list() if 'callchain' in param_dict: @@ -110,17 +109,17 @@ def tidy_function_name(sym, dso): comm = param_dict["comm"].replace(' ', '_') sep = "-" if opts.include_pid: - comm = comm + sep + str(param_dict['sample']['pid']) + comm += sep + str(param_dict['sample']['pid']) sep = "/" if opts.include_tid: - comm = comm + sep + str(param_dict['sample']['tid']) + comm += sep + str(param_dict['sample']['tid']) stack.append(comm) stack_string = ';'.join(reversed(stack)) - lines[stack_string] = lines[stack_string] + 1 + lines[stack_string] += 1 def trace_end(): - list = lines.keys() - list.sort() - for stack in list: + list_ = lines.keys() + list_.sort() + for stack in list_: print "%s %d" % (stack, lines[stack])