diff options
Diffstat (limited to 'tools/perf/scripts/python')
8 files changed, 240 insertions, 35 deletions
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py index 38dfb720fb6f..54ace2f6bc36 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py | |||
| @@ -31,10 +31,8 @@ def flag_str(event_name, field_name, value): | |||
| 31 | string = "" | 31 | string = "" |
| 32 | 32 | ||
| 33 | if flag_fields[event_name][field_name]: | 33 | if flag_fields[event_name][field_name]: |
| 34 | print_delim = 0 | 34 | print_delim = 0 |
| 35 | keys = flag_fields[event_name][field_name]['values'].keys() | 35 | for idx in sorted(flag_fields[event_name][field_name]['values']): |
| 36 | keys.sort() | ||
| 37 | for idx in keys: | ||
| 38 | if not value and not idx: | 36 | if not value and not idx: |
| 39 | string += flag_fields[event_name][field_name]['values'][idx] | 37 | string += flag_fields[event_name][field_name]['values'][idx] |
| 40 | break | 38 | break |
| @@ -51,14 +49,12 @@ def symbol_str(event_name, field_name, value): | |||
| 51 | string = "" | 49 | string = "" |
| 52 | 50 | ||
| 53 | if symbolic_fields[event_name][field_name]: | 51 | if symbolic_fields[event_name][field_name]: |
| 54 | keys = symbolic_fields[event_name][field_name]['values'].keys() | 52 | for idx in sorted(symbolic_fields[event_name][field_name]['values']): |
| 55 | keys.sort() | ||
| 56 | for idx in keys: | ||
| 57 | if not value and not idx: | 53 | if not value and not idx: |
| 58 | string = symbolic_fields[event_name][field_name]['values'][idx] | 54 | string = symbolic_fields[event_name][field_name]['values'][idx] |
| 59 | break | 55 | break |
| 60 | if (value == idx): | 56 | if (value == idx): |
| 61 | string = symbolic_fields[event_name][field_name]['values'][idx] | 57 | string = symbolic_fields[event_name][field_name]['values'][idx] |
| 62 | break | 58 | break |
| 63 | 59 | ||
| 64 | return string | 60 | return string |
| @@ -74,19 +70,17 @@ def trace_flag_str(value): | |||
| 74 | string = "" | 70 | string = "" |
| 75 | print_delim = 0 | 71 | print_delim = 0 |
| 76 | 72 | ||
| 77 | keys = trace_flags.keys() | 73 | for idx in trace_flags: |
| 78 | 74 | if not value and not idx: | |
| 79 | for idx in keys: | 75 | string += "NONE" |
| 80 | if not value and not idx: | 76 | break |
| 81 | string += "NONE" | 77 | |
| 82 | break | 78 | if idx and (value & idx) == idx: |
| 83 | 79 | if print_delim: | |
| 84 | if idx and (value & idx) == idx: | 80 | string += " | "; |
| 85 | if print_delim: | 81 | string += trace_flags[idx] |
| 86 | string += " | "; | 82 | print_delim = 1 |
| 87 | string += trace_flags[idx] | 83 | value &= ~idx |
| 88 | print_delim = 1 | ||
| 89 | value &= ~idx | ||
| 90 | 84 | ||
| 91 | return string | 85 | return string |
| 92 | 86 | ||
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py index 81a56cd2b3c1..21a7a1298094 100755 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/EventClass.py | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | # PerfEvent is the base class for all perf event sample, PebsEvent | 8 | # PerfEvent is the base class for all perf event sample, PebsEvent |
| 9 | # is a HW base Intel x86 PEBS event, and user could add more SW/HW | 9 | # is a HW base Intel x86 PEBS event, and user could add more SW/HW |
| 10 | # event classes based on requirements. | 10 | # event classes based on requirements. |
| 11 | from __future__ import print_function | ||
| 11 | 12 | ||
| 12 | import struct | 13 | import struct |
| 13 | 14 | ||
| @@ -44,7 +45,8 @@ class PerfEvent(object): | |||
| 44 | PerfEvent.event_num += 1 | 45 | PerfEvent.event_num += 1 |
| 45 | 46 | ||
| 46 | def show(self): | 47 | def show(self): |
| 47 | print "PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % (self.name, self.symbol, self.comm, self.dso) | 48 | print("PMU event: name=%12s, symbol=%24s, comm=%8s, dso=%12s" % |
| 49 | (self.name, self.symbol, self.comm, self.dso)) | ||
| 48 | 50 | ||
| 49 | # | 51 | # |
| 50 | # Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer | 52 | # Basic Intel PEBS (Precise Event-based Sampling) event, whose raw buffer |
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py index fdd92f699055..cac7b2542ee8 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py | |||
| @@ -11,7 +11,7 @@ | |||
| 11 | try: | 11 | try: |
| 12 | import wx | 12 | import wx |
| 13 | except ImportError: | 13 | except ImportError: |
| 14 | raise ImportError, "You need to install the wxpython lib for this script" | 14 | raise ImportError("You need to install the wxpython lib for this script") |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | class RootFrame(wx.Frame): | 17 | class RootFrame(wx.Frame): |
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py index f6c84966e4f8..7384dcb628c4 100644 --- a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | # This software may be distributed under the terms of the GNU General | 5 | # This software may be distributed under the terms of the GNU General |
| 6 | # Public License ("GPL") version 2 as published by the Free Software | 6 | # Public License ("GPL") version 2 as published by the Free Software |
| 7 | # Foundation. | 7 | # Foundation. |
| 8 | from __future__ import print_function | ||
| 8 | 9 | ||
| 9 | import errno, os | 10 | import errno, os |
| 10 | 11 | ||
| @@ -33,7 +34,7 @@ def nsecs_str(nsecs): | |||
| 33 | return str | 34 | return str |
| 34 | 35 | ||
| 35 | def add_stats(dict, key, value): | 36 | def add_stats(dict, key, value): |
| 36 | if not dict.has_key(key): | 37 | if key not in dict: |
| 37 | dict[key] = (value, value, value, 1) | 38 | dict[key] = (value, value, value, 1) |
| 38 | else: | 39 | else: |
| 39 | min, max, avg, count = dict[key] | 40 | min, max, avg, count = dict[key] |
| @@ -72,10 +73,10 @@ try: | |||
| 72 | except: | 73 | except: |
| 73 | if not audit_package_warned: | 74 | if not audit_package_warned: |
| 74 | audit_package_warned = True | 75 | audit_package_warned = True |
| 75 | print "Install the audit-libs-python package to get syscall names.\n" \ | 76 | print("Install the audit-libs-python package to get syscall names.\n" |
| 76 | "For example:\n # apt-get install python-audit (Ubuntu)" \ | 77 | "For example:\n # apt-get install python-audit (Ubuntu)" |
| 77 | "\n # yum install audit-libs-python (Fedora)" \ | 78 | "\n # yum install audit-libs-python (Fedora)" |
| 78 | "\n etc.\n" | 79 | "\n etc.\n") |
| 79 | 80 | ||
| 80 | def syscall_name(id): | 81 | def syscall_name(id): |
| 81 | try: | 82 | try: |
diff --git a/tools/perf/scripts/python/bin/powerpc-hcalls-record b/tools/perf/scripts/python/bin/powerpc-hcalls-record new file mode 100644 index 000000000000..b7402aa9147d --- /dev/null +++ b/tools/perf/scripts/python/bin/powerpc-hcalls-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -e "{powerpc:hcall_entry,powerpc:hcall_exit}" $@ | ||
diff --git a/tools/perf/scripts/python/bin/powerpc-hcalls-report b/tools/perf/scripts/python/bin/powerpc-hcalls-report new file mode 100644 index 000000000000..dd32ad7465f6 --- /dev/null +++ b/tools/perf/scripts/python/bin/powerpc-hcalls-report | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf script $@ -s "$PERF_EXEC_PATH"/scripts/python/powerpc-hcalls.py | ||
diff --git a/tools/perf/scripts/python/powerpc-hcalls.py b/tools/perf/scripts/python/powerpc-hcalls.py new file mode 100644 index 000000000000..00e0e7476e55 --- /dev/null +++ b/tools/perf/scripts/python/powerpc-hcalls.py | |||
| @@ -0,0 +1,200 @@ | |||
| 1 | # SPDX-License-Identifier: GPL-2.0+ | ||
| 2 | # | ||
| 3 | # Copyright (C) 2018 Ravi Bangoria, IBM Corporation | ||
| 4 | # | ||
| 5 | # Hypervisor call statisics | ||
| 6 | |||
| 7 | import os | ||
| 8 | import sys | ||
| 9 | |||
| 10 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 11 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 12 | |||
| 13 | from perf_trace_context import * | ||
| 14 | from Core import * | ||
| 15 | from Util import * | ||
| 16 | |||
| 17 | # output: { | ||
| 18 | # opcode: { | ||
| 19 | # 'min': minimum time nsec | ||
| 20 | # 'max': maximum time nsec | ||
| 21 | # 'time': average time nsec | ||
| 22 | # 'cnt': counter | ||
| 23 | # } ... | ||
| 24 | # } | ||
| 25 | output = {} | ||
| 26 | |||
| 27 | # d_enter: { | ||
| 28 | # cpu: { | ||
| 29 | # opcode: nsec | ||
| 30 | # } ... | ||
| 31 | # } | ||
| 32 | d_enter = {} | ||
| 33 | |||
| 34 | hcall_table = { | ||
| 35 | 4: 'H_REMOVE', | ||
| 36 | 8: 'H_ENTER', | ||
| 37 | 12: 'H_READ', | ||
| 38 | 16: 'H_CLEAR_MOD', | ||
| 39 | 20: 'H_CLEAR_REF', | ||
| 40 | 24: 'H_PROTECT', | ||
| 41 | 28: 'H_GET_TCE', | ||
| 42 | 32: 'H_PUT_TCE', | ||
| 43 | 36: 'H_SET_SPRG0', | ||
| 44 | 40: 'H_SET_DABR', | ||
| 45 | 44: 'H_PAGE_INIT', | ||
| 46 | 48: 'H_SET_ASR', | ||
| 47 | 52: 'H_ASR_ON', | ||
| 48 | 56: 'H_ASR_OFF', | ||
| 49 | 60: 'H_LOGICAL_CI_LOAD', | ||
| 50 | 64: 'H_LOGICAL_CI_STORE', | ||
| 51 | 68: 'H_LOGICAL_CACHE_LOAD', | ||
| 52 | 72: 'H_LOGICAL_CACHE_STORE', | ||
| 53 | 76: 'H_LOGICAL_ICBI', | ||
| 54 | 80: 'H_LOGICAL_DCBF', | ||
| 55 | 84: 'H_GET_TERM_CHAR', | ||
| 56 | 88: 'H_PUT_TERM_CHAR', | ||
| 57 | 92: 'H_REAL_TO_LOGICAL', | ||
| 58 | 96: 'H_HYPERVISOR_DATA', | ||
| 59 | 100: 'H_EOI', | ||
| 60 | 104: 'H_CPPR', | ||
| 61 | 108: 'H_IPI', | ||
| 62 | 112: 'H_IPOLL', | ||
| 63 | 116: 'H_XIRR', | ||
| 64 | 120: 'H_MIGRATE_DMA', | ||
| 65 | 124: 'H_PERFMON', | ||
| 66 | 220: 'H_REGISTER_VPA', | ||
| 67 | 224: 'H_CEDE', | ||
| 68 | 228: 'H_CONFER', | ||
| 69 | 232: 'H_PROD', | ||
| 70 | 236: 'H_GET_PPP', | ||
| 71 | 240: 'H_SET_PPP', | ||
| 72 | 244: 'H_PURR', | ||
| 73 | 248: 'H_PIC', | ||
| 74 | 252: 'H_REG_CRQ', | ||
| 75 | 256: 'H_FREE_CRQ', | ||
| 76 | 260: 'H_VIO_SIGNAL', | ||
| 77 | 264: 'H_SEND_CRQ', | ||
| 78 | 272: 'H_COPY_RDMA', | ||
| 79 | 276: 'H_REGISTER_LOGICAL_LAN', | ||
| 80 | 280: 'H_FREE_LOGICAL_LAN', | ||
| 81 | 284: 'H_ADD_LOGICAL_LAN_BUFFER', | ||
| 82 | 288: 'H_SEND_LOGICAL_LAN', | ||
| 83 | 292: 'H_BULK_REMOVE', | ||
| 84 | 304: 'H_MULTICAST_CTRL', | ||
| 85 | 308: 'H_SET_XDABR', | ||
| 86 | 312: 'H_STUFF_TCE', | ||
| 87 | 316: 'H_PUT_TCE_INDIRECT', | ||
| 88 | 332: 'H_CHANGE_LOGICAL_LAN_MAC', | ||
| 89 | 336: 'H_VTERM_PARTNER_INFO', | ||
| 90 | 340: 'H_REGISTER_VTERM', | ||
| 91 | 344: 'H_FREE_VTERM', | ||
| 92 | 348: 'H_RESET_EVENTS', | ||
| 93 | 352: 'H_ALLOC_RESOURCE', | ||
| 94 | 356: 'H_FREE_RESOURCE', | ||
| 95 | 360: 'H_MODIFY_QP', | ||
| 96 | 364: 'H_QUERY_QP', | ||
| 97 | 368: 'H_REREGISTER_PMR', | ||
| 98 | 372: 'H_REGISTER_SMR', | ||
| 99 | 376: 'H_QUERY_MR', | ||
| 100 | 380: 'H_QUERY_MW', | ||
| 101 | 384: 'H_QUERY_HCA', | ||
| 102 | 388: 'H_QUERY_PORT', | ||
| 103 | 392: 'H_MODIFY_PORT', | ||
| 104 | 396: 'H_DEFINE_AQP1', | ||
| 105 | 400: 'H_GET_TRACE_BUFFER', | ||
| 106 | 404: 'H_DEFINE_AQP0', | ||
| 107 | 408: 'H_RESIZE_MR', | ||
| 108 | 412: 'H_ATTACH_MCQP', | ||
| 109 | 416: 'H_DETACH_MCQP', | ||
| 110 | 420: 'H_CREATE_RPT', | ||
| 111 | 424: 'H_REMOVE_RPT', | ||
| 112 | 428: 'H_REGISTER_RPAGES', | ||
| 113 | 432: 'H_DISABLE_AND_GETC', | ||
| 114 | 436: 'H_ERROR_DATA', | ||
| 115 | 440: 'H_GET_HCA_INFO', | ||
| 116 | 444: 'H_GET_PERF_COUNT', | ||
| 117 | 448: 'H_MANAGE_TRACE', | ||
| 118 | 468: 'H_FREE_LOGICAL_LAN_BUFFER', | ||
| 119 | 472: 'H_POLL_PENDING', | ||
| 120 | 484: 'H_QUERY_INT_STATE', | ||
| 121 | 580: 'H_ILLAN_ATTRIBUTES', | ||
| 122 | 592: 'H_MODIFY_HEA_QP', | ||
| 123 | 596: 'H_QUERY_HEA_QP', | ||
| 124 | 600: 'H_QUERY_HEA', | ||
| 125 | 604: 'H_QUERY_HEA_PORT', | ||
| 126 | 608: 'H_MODIFY_HEA_PORT', | ||
| 127 | 612: 'H_REG_BCMC', | ||
| 128 | 616: 'H_DEREG_BCMC', | ||
| 129 | 620: 'H_REGISTER_HEA_RPAGES', | ||
| 130 | 624: 'H_DISABLE_AND_GET_HEA', | ||
| 131 | 628: 'H_GET_HEA_INFO', | ||
| 132 | 632: 'H_ALLOC_HEA_RESOURCE', | ||
| 133 | 644: 'H_ADD_CONN', | ||
| 134 | 648: 'H_DEL_CONN', | ||
| 135 | 664: 'H_JOIN', | ||
| 136 | 676: 'H_VASI_STATE', | ||
| 137 | 688: 'H_ENABLE_CRQ', | ||
| 138 | 696: 'H_GET_EM_PARMS', | ||
| 139 | 720: 'H_SET_MPP', | ||
| 140 | 724: 'H_GET_MPP', | ||
| 141 | 748: 'H_HOME_NODE_ASSOCIATIVITY', | ||
| 142 | 756: 'H_BEST_ENERGY', | ||
| 143 | 764: 'H_XIRR_X', | ||
| 144 | 768: 'H_RANDOM', | ||
| 145 | 772: 'H_COP', | ||
| 146 | 788: 'H_GET_MPP_X', | ||
| 147 | 796: 'H_SET_MODE', | ||
| 148 | 61440: 'H_RTAS', | ||
| 149 | } | ||
| 150 | |||
| 151 | def hcall_table_lookup(opcode): | ||
| 152 | if (hcall_table.has_key(opcode)): | ||
| 153 | return hcall_table[opcode] | ||
| 154 | else: | ||
| 155 | return opcode | ||
| 156 | |||
| 157 | print_ptrn = '%-28s%10s%10s%10s%10s' | ||
| 158 | |||
| 159 | def trace_end(): | ||
| 160 | print print_ptrn % ('hcall', 'count', 'min(ns)', 'max(ns)', 'avg(ns)') | ||
| 161 | print '-' * 68 | ||
| 162 | for opcode in output: | ||
| 163 | h_name = hcall_table_lookup(opcode) | ||
| 164 | time = output[opcode]['time'] | ||
| 165 | cnt = output[opcode]['cnt'] | ||
| 166 | min_t = output[opcode]['min'] | ||
| 167 | max_t = output[opcode]['max'] | ||
| 168 | |||
| 169 | print print_ptrn % (h_name, cnt, min_t, max_t, time/cnt) | ||
| 170 | |||
| 171 | def powerpc__hcall_exit(name, context, cpu, sec, nsec, pid, comm, callchain, | ||
| 172 | opcode, retval): | ||
| 173 | if (d_enter.has_key(cpu) and d_enter[cpu].has_key(opcode)): | ||
| 174 | diff = nsecs(sec, nsec) - d_enter[cpu][opcode] | ||
| 175 | |||
| 176 | if (output.has_key(opcode)): | ||
| 177 | output[opcode]['time'] += diff | ||
| 178 | output[opcode]['cnt'] += 1 | ||
| 179 | if (output[opcode]['min'] > diff): | ||
| 180 | output[opcode]['min'] = diff | ||
| 181 | if (output[opcode]['max'] < diff): | ||
| 182 | output[opcode]['max'] = diff | ||
| 183 | else: | ||
| 184 | output[opcode] = { | ||
| 185 | 'time': diff, | ||
| 186 | 'cnt': 1, | ||
| 187 | 'min': diff, | ||
| 188 | 'max': diff, | ||
| 189 | } | ||
| 190 | |||
| 191 | del d_enter[cpu][opcode] | ||
| 192 | # else: | ||
| 193 | # print "Can't find matching hcall_enter event. Ignoring sample" | ||
| 194 | |||
| 195 | def powerpc__hcall_entry(event_name, context, cpu, sec, nsec, pid, comm, | ||
| 196 | callchain, opcode): | ||
| 197 | if (d_enter.has_key(cpu)): | ||
| 198 | d_enter[cpu][opcode] = nsecs(sec, nsec) | ||
| 199 | else: | ||
| 200 | d_enter[cpu] = {opcode: nsecs(sec, nsec)} | ||
diff --git a/tools/perf/scripts/python/sched-migration.py b/tools/perf/scripts/python/sched-migration.py index de66cb3b72c9..3473e7f66081 100644 --- a/tools/perf/scripts/python/sched-migration.py +++ b/tools/perf/scripts/python/sched-migration.py | |||
| @@ -9,13 +9,17 @@ | |||
| 9 | # This software is distributed under the terms of the GNU General | 9 | # This software is distributed under the terms of the GNU General |
| 10 | # Public License ("GPL") version 2 as published by the Free Software | 10 | # Public License ("GPL") version 2 as published by the Free Software |
| 11 | # Foundation. | 11 | # Foundation. |
| 12 | 12 | from __future__ import print_function | |
| 13 | 13 | ||
| 14 | import os | 14 | import os |
| 15 | import sys | 15 | import sys |
| 16 | 16 | ||
| 17 | from collections import defaultdict | 17 | from collections import defaultdict |
| 18 | from UserList import UserList | 18 | try: |
| 19 | from UserList import UserList | ||
| 20 | except ImportError: | ||
| 21 | # Python 3: UserList moved to the collections package | ||
| 22 | from collections import UserList | ||
| 19 | 23 | ||
| 20 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | 24 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ |
| 21 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | 25 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') |
| @@ -300,7 +304,7 @@ class TimeSliceList(UserList): | |||
| 300 | if i == -1: | 304 | if i == -1: |
| 301 | return | 305 | return |
| 302 | 306 | ||
| 303 | for i in xrange(i, len(self.data)): | 307 | for i in range(i, len(self.data)): |
| 304 | timeslice = self.data[i] | 308 | timeslice = self.data[i] |
| 305 | if timeslice.start > end: | 309 | if timeslice.start > end: |
| 306 | return | 310 | return |
| @@ -336,8 +340,8 @@ class SchedEventProxy: | |||
| 336 | on_cpu_task = self.current_tsk[headers.cpu] | 340 | on_cpu_task = self.current_tsk[headers.cpu] |
| 337 | 341 | ||
| 338 | if on_cpu_task != -1 and on_cpu_task != prev_pid: | 342 | if on_cpu_task != -1 and on_cpu_task != prev_pid: |
| 339 | print "Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ | 343 | print("Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ |
| 340 | (headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) | 344 | headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) |
| 341 | 345 | ||
| 342 | threads[prev_pid] = prev_comm | 346 | threads[prev_pid] = prev_comm |
| 343 | threads[next_pid] = next_comm | 347 | threads[next_pid] = next_comm |
