1 # intel-pt-events.py: Print Intel PT Power Events and PTWRITE
2 # Copyright (c) 2017, Intel Corporation.
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.
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
13 from __future__
import print_function
19 sys
.path
.append(os
.environ
['PERF_EXEC_PATH'] + \
20 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
22 # These perf imports are not used at present
23 #from perf_trace_context import *
27 print("Intel PT Power Events and PTWRITE")
32 def trace_unhandled(event_name
, context
, event_fields_dict
):
33 print(' '.join(['%s=%s'%(k
,str(v
))for k
,v
in sorted(event_fields_dict
.items())]))
35 def print_ptwrite(raw_buf
):
36 data
= struct
.unpack_from("<IQ", raw_buf
)
40 print("IP: %u payload: %#x" % (exact_ip
, payload
), end
=' ')
42 def print_cbr(raw_buf
):
43 data
= struct
.unpack_from("<BBBBII", raw_buf
)
45 f
= (data
[4] + 500) / 1000
46 p
= ((cbr
* 1000 / data
[2]) + 5) / 10
47 print("%3u freq: %4u MHz (%3u%%)" % (cbr
, f
, p
), end
=' ')
49 def print_mwait(raw_buf
):
50 data
= struct
.unpack_from("<IQ", raw_buf
)
52 hints
= payload
& 0xff
53 extensions
= (payload
>> 32) & 0x3
54 print("hints: %#x extensions: %#x" % (hints
, extensions
), end
=' ')
56 def print_pwre(raw_buf
):
57 data
= struct
.unpack_from("<IQ", raw_buf
)
59 hw
= (payload
>> 7) & 1
60 cstate
= (payload
>> 12) & 0xf
61 subcstate
= (payload
>> 8) & 0xf
62 print("hw: %u cstate: %u sub-cstate: %u" % (hw
, cstate
, subcstate
),
65 def print_exstop(raw_buf
):
66 data
= struct
.unpack_from("<I", raw_buf
)
69 print("IP: %u" % (exact_ip
), end
=' ')
71 def print_pwrx(raw_buf
):
72 data
= struct
.unpack_from("<IQ", raw_buf
)
74 deepest_cstate
= payload
& 0xf
75 last_cstate
= (payload
>> 4) & 0xf
76 wake_reason
= (payload
>> 8) & 0xf
77 print("deepest cstate: %u last cstate: %u wake reason: %#x" %
78 (deepest_cstate
, last_cstate
, wake_reason
), end
=' ')
80 def print_common_start(comm
, sample
, name
):
85 print("%16s %5u/%-5u [%03u] %9u.%09u %7s:" %
86 (comm
, pid
, tid
, cpu
, ts
/ 1000000000, ts
%1000000000, name
),
89 def print_common_ip(sample
, symbol
, dso
):
91 print("%16x %s (%s)" % (ip
, symbol
, dso
))
93 def process_event(param_dict
):
94 event_attr
= param_dict
["attr"]
95 sample
= param_dict
["sample"]
96 raw_buf
= param_dict
["raw_buf"]
97 comm
= param_dict
["comm"]
98 name
= param_dict
["ev_name"]
100 # Symbol and dso info are not always resolved
101 if "dso" in param_dict
:
102 dso
= param_dict
["dso"]
106 if "symbol" in param_dict
:
107 symbol
= param_dict
["symbol"]
111 if name
== "ptwrite":
112 print_common_start(comm
, sample
, name
)
113 print_ptwrite(raw_buf
)
114 print_common_ip(sample
, symbol
, dso
)
116 print_common_start(comm
, sample
, name
)
118 print_common_ip(sample
, symbol
, dso
)
119 elif name
== "mwait":
120 print_common_start(comm
, sample
, name
)
122 print_common_ip(sample
, symbol
, dso
)
124 print_common_start(comm
, sample
, name
)
126 print_common_ip(sample
, symbol
, dso
)
127 elif name
== "exstop":
128 print_common_start(comm
, sample
, name
)
129 print_exstop(raw_buf
)
130 print_common_ip(sample
, symbol
, dso
)
132 print_common_start(comm
, sample
, name
)
134 print_common_ip(sample
, symbol
, dso
)