diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-03 15:40:46 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-07-03 15:40:46 -0400 |
| commit | 7447d56217e215e50317f308aee1ed293ac4f749 (patch) | |
| tree | 903832ecb206ae83160992c6aec40c624821941f /tools/perf/scripts/python/intel-pt-events.py | |
| parent | 892ad5acca0b2ddb514fae63fa4686bf726d2471 (diff) | |
| parent | 23acd3e1a0a377cf3730ccb753aa1fdc50378396 (diff) | |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar:
"Most of the changes are for tooling, the main changes in this cycle were:
- Improve Intel-PT hardware tracing support, both on the kernel and
on the tooling side: PTWRITE instruction support, power events for
C-state tracing, etc. (Adrian Hunter)
- Add support to measure SMI cost to the x86 architecture, with
tooling support in 'perf stat' (Kan Liang)
- Support function filtering in 'perf ftrace', plus related
improvements (Namhyung Kim)
- Allow adding and removing fields to the default 'perf script'
columns, using + or - as field prefixes to do so (Andi Kleen)
- Allow resolving the DSO name with 'perf script -F brstack{sym,off},dso'
(Mark Santaniello)
- Add perf tooling unwind support for PowerPC (Paolo Bonzini)
- ... and various other improvements as well"
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (84 commits)
perf auxtrace: Add CPU filter support
perf intel-pt: Do not use TSC packets for calculating CPU cycles to TSC
perf intel-pt: Update documentation to include new ptwrite and power events
perf intel-pt: Add example script for power events and PTWRITE
perf intel-pt: Synthesize new power and "ptwrite" events
perf intel-pt: Move code in intel_pt_synth_events() to simplify attr setting
perf intel-pt: Factor out intel_pt_set_event_name()
perf intel-pt: Tidy messages into called function intel_pt_synth_event()
perf intel-pt: Tidy Intel PT evsel lookup into separate function
perf intel-pt: Join needlessly wrapped lines
perf intel-pt: Remove unused instructions_sample_period
perf intel-pt: Factor out common code synthesizing event samples
perf script: Add synthesized Intel PT power and ptwrite events
perf/x86/intel: Constify the 'lbr_desc[]' array and make a function static
perf script: Add 'synth' field for synthesized event payloads
perf auxtrace: Add itrace option to output power events
perf auxtrace: Add itrace option to output ptwrite events
tools include: Add byte-swapping macros to kernel.h
perf script: Add 'synth' event type for synthesized events
x86/insn: perf tools: Add new ptwrite instruction
...
Diffstat (limited to 'tools/perf/scripts/python/intel-pt-events.py')
| -rw-r--r-- | tools/perf/scripts/python/intel-pt-events.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py new file mode 100644 index 000000000000..b19172d673af --- /dev/null +++ b/tools/perf/scripts/python/intel-pt-events.py | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | # intel-pt-events.py: Print Intel PT Power Events and PTWRITE | ||
| 2 | # Copyright (c) 2017, Intel Corporation. | ||
| 3 | # | ||
| 4 | # This program is free software; you can redistribute it and/or modify it | ||
| 5 | # under the terms and conditions of the GNU General Public License, | ||
| 6 | # version 2, as published by the Free Software Foundation. | ||
| 7 | # | ||
| 8 | # This program is distributed in the hope it will be useful, but WITHOUT | ||
| 9 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 10 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 11 | # more details. | ||
| 12 | |||
| 13 | import os | ||
| 14 | import sys | ||
| 15 | import struct | ||
| 16 | |||
| 17 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 18 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 19 | |||
| 20 | # These perf imports are not used at present | ||
| 21 | #from perf_trace_context import * | ||
| 22 | #from Core import * | ||
| 23 | |||
| 24 | def trace_begin(): | ||
| 25 | print "Intel PT Power Events and PTWRITE" | ||
| 26 | |||
| 27 | def trace_end(): | ||
| 28 | print "End" | ||
| 29 | |||
| 30 | def trace_unhandled(event_name, context, event_fields_dict): | ||
| 31 | print ' '.join(['%s=%s'%(k,str(v))for k,v in sorted(event_fields_dict.items())]) | ||
| 32 | |||
| 33 | def print_ptwrite(raw_buf): | ||
| 34 | data = struct.unpack_from("<IQ", raw_buf) | ||
| 35 | flags = data[0] | ||
| 36 | payload = data[1] | ||
| 37 | exact_ip = flags & 1 | ||
| 38 | print "IP: %u payload: %#x" % (exact_ip, payload), | ||
| 39 | |||
| 40 | def print_cbr(raw_buf): | ||
| 41 | data = struct.unpack_from("<BBBBII", raw_buf) | ||
| 42 | cbr = data[0] | ||
| 43 | f = (data[4] + 500) / 1000 | ||
| 44 | p = ((cbr * 1000 / data[2]) + 5) / 10 | ||
| 45 | print "%3u freq: %4u MHz (%3u%%)" % (cbr, f, p), | ||
| 46 | |||
| 47 | def print_mwait(raw_buf): | ||
| 48 | data = struct.unpack_from("<IQ", raw_buf) | ||
| 49 | payload = data[1] | ||
| 50 | hints = payload & 0xff | ||
| 51 | extensions = (payload >> 32) & 0x3 | ||
| 52 | print "hints: %#x extensions: %#x" % (hints, extensions), | ||
| 53 | |||
| 54 | def print_pwre(raw_buf): | ||
| 55 | data = struct.unpack_from("<IQ", raw_buf) | ||
| 56 | payload = data[1] | ||
| 57 | hw = (payload >> 7) & 1 | ||
| 58 | cstate = (payload >> 12) & 0xf | ||
| 59 | subcstate = (payload >> 8) & 0xf | ||
| 60 | print "hw: %u cstate: %u sub-cstate: %u" % (hw, cstate, subcstate), | ||
| 61 | |||
| 62 | def print_exstop(raw_buf): | ||
| 63 | data = struct.unpack_from("<I", raw_buf) | ||
| 64 | flags = data[0] | ||
| 65 | exact_ip = flags & 1 | ||
| 66 | print "IP: %u" % (exact_ip), | ||
| 67 | |||
| 68 | def print_pwrx(raw_buf): | ||
| 69 | data = struct.unpack_from("<IQ", raw_buf) | ||
| 70 | payload = data[1] | ||
| 71 | deepest_cstate = payload & 0xf | ||
| 72 | last_cstate = (payload >> 4) & 0xf | ||
| 73 | wake_reason = (payload >> 8) & 0xf | ||
| 74 | print "deepest cstate: %u last cstate: %u wake reason: %#x" % (deepest_cstate, last_cstate, wake_reason), | ||
| 75 | |||
| 76 | def print_common_start(comm, sample, name): | ||
| 77 | ts = sample["time"] | ||
| 78 | cpu = sample["cpu"] | ||
| 79 | pid = sample["pid"] | ||
| 80 | tid = sample["tid"] | ||
| 81 | print "%16s %5u/%-5u [%03u] %9u.%09u %7s:" % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000, name), | ||
| 82 | |||
| 83 | def print_common_ip(sample, symbol, dso): | ||
| 84 | ip = sample["ip"] | ||
| 85 | print "%16x %s (%s)" % (ip, symbol, dso) | ||
| 86 | |||
| 87 | def process_event(param_dict): | ||
| 88 | event_attr = param_dict["attr"] | ||
| 89 | sample = param_dict["sample"] | ||
| 90 | raw_buf = param_dict["raw_buf"] | ||
| 91 | comm = param_dict["comm"] | ||
| 92 | name = param_dict["ev_name"] | ||
| 93 | |||
| 94 | # Symbol and dso info are not always resolved | ||
| 95 | if (param_dict.has_key("dso")): | ||
| 96 | dso = param_dict["dso"] | ||
| 97 | else: | ||
| 98 | dso = "[unknown]" | ||
| 99 | |||
| 100 | if (param_dict.has_key("symbol")): | ||
| 101 | symbol = param_dict["symbol"] | ||
| 102 | else: | ||
| 103 | symbol = "[unknown]" | ||
| 104 | |||
| 105 | if name == "ptwrite": | ||
| 106 | print_common_start(comm, sample, name) | ||
| 107 | print_ptwrite(raw_buf) | ||
| 108 | print_common_ip(sample, symbol, dso) | ||
| 109 | elif name == "cbr": | ||
| 110 | print_common_start(comm, sample, name) | ||
| 111 | print_cbr(raw_buf) | ||
| 112 | print_common_ip(sample, symbol, dso) | ||
| 113 | elif name == "mwait": | ||
| 114 | print_common_start(comm, sample, name) | ||
| 115 | print_mwait(raw_buf) | ||
| 116 | print_common_ip(sample, symbol, dso) | ||
| 117 | elif name == "pwre": | ||
| 118 | print_common_start(comm, sample, name) | ||
| 119 | print_pwre(raw_buf) | ||
| 120 | print_common_ip(sample, symbol, dso) | ||
| 121 | elif name == "exstop": | ||
| 122 | print_common_start(comm, sample, name) | ||
| 123 | print_exstop(raw_buf) | ||
| 124 | print_common_ip(sample, symbol, dso) | ||
| 125 | elif name == "pwrx": | ||
| 126 | print_common_start(comm, sample, name) | ||
| 127 | print_pwrx(raw_buf) | ||
| 128 | print_common_ip(sample, symbol, dso) | ||
