-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperf-script.py
More file actions
executable file
·81 lines (60 loc) · 3.07 KB
/
perf-script.py
File metadata and controls
executable file
·81 lines (60 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# perf script event handlers, generated by perf script -g python
# Licensed under the terms of the GNU GPL License version 2
# The common_* event handler fields are the most useful fields common to
# all events. They don't necessarily correspond to the 'common_*' fields
# in the format files. Those fields not available as handler params can
# be retrieved using Python functions of the form common_*(context).
# See the perf-script-python Documentation for the list of available functions.
from __future__ import print_function
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
def trace_begin():
print("in trace_begin")
def trace_end():
print("in trace_end")
start=0
def probe_evenodd__even(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, __probe_ip, perf_sample_dict):
global start
start=(common_secs * 1000000000) + common_nsecs
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print("__probe_ip=%u" % \
(__probe_ip))
print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
for node in common_callchain:
if 'sym' in node:
print("\t[%x] %s" % (node['ip'], node['sym']['name']))
else:
print(" [%x]" % (node['ip']))
print()
def probe_evenodd__even_end(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, __probe_ip, perf_sample_dict):
now=common_secs * 1000000000 + common_nsecs
duration=now - start
print("even runtime: " + str(duration) + " ns")
print_header(event_name, common_cpu, common_secs, common_nsecs,
common_pid, common_comm)
print("__probe_ip=%u" % \
(__probe_ip))
print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
for node in common_callchain:
if 'sym' in node:
print("\t[%x] %s" % (node['ip'], node['sym']['name']))
else:
print(" [%x]" % (node['ip']))
print()
def trace_unhandled(event_name, context, event_fields_dict, perf_sample_dict):
print(get_dict_as_string(event_fields_dict))
print('Sample: {'+get_dict_as_string(perf_sample_dict['sample'], ', ')+'}')
def print_header(event_name, cpu, secs, nsecs, pid, comm):
print("%-20s %5u %05u.%09u %8u %-20s " % \
(event_name, cpu, secs, nsecs, pid, comm), end="")
def get_dict_as_string(a_dict, delimiter=' '):
return delimiter.join(['%s=%s'%(k,str(v))for k,v in sorted(a_dict.items())])