diff options
Diffstat (limited to 'tools/perf/scripts/python')
-rwxr-xr-x | tools/perf/scripts/python/bin/stackcollapse-record | 8 | ||||
-rwxr-xr-x | tools/perf/scripts/python/bin/stackcollapse-report | 3 | ||||
-rw-r--r-- | tools/perf/scripts/python/netdev-times.py | 11 | ||||
-rwxr-xr-x | tools/perf/scripts/python/stackcollapse.py | 125 |
4 files changed, 143 insertions, 4 deletions
diff --git a/tools/perf/scripts/python/bin/stackcollapse-record b/tools/perf/scripts/python/bin/stackcollapse-record new file mode 100755 index 000000000000..9d8f9f0f3a17 --- /dev/null +++ b/tools/perf/scripts/python/bin/stackcollapse-record | |||
@@ -0,0 +1,8 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # | ||
4 | # stackcollapse.py can cover all type of perf samples including | ||
5 | # the tracepoints, so no special record requirements, just record what | ||
6 | # you want to analyze. | ||
7 | # | ||
8 | perf record "$@" | ||
diff --git a/tools/perf/scripts/python/bin/stackcollapse-report b/tools/perf/scripts/python/bin/stackcollapse-report new file mode 100755 index 000000000000..356b9656393d --- /dev/null +++ b/tools/perf/scripts/python/bin/stackcollapse-report | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/bin/sh | ||
2 | # description: produce callgraphs in short form for scripting use | ||
3 | perf script -s "$PERF_EXEC_PATH"/scripts/python/stackcollapse.py -- "$@" | ||
diff --git a/tools/perf/scripts/python/netdev-times.py b/tools/perf/scripts/python/netdev-times.py index 4d21ef2d601d..4c6f09ac7d12 100644 --- a/tools/perf/scripts/python/netdev-times.py +++ b/tools/perf/scripts/python/netdev-times.py | |||
@@ -252,9 +252,10 @@ def irq__irq_handler_exit(name, context, cpu, sec, nsec, pid, comm, callchain, i | |||
252 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret) | 252 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, irq, ret) |
253 | all_event_list.append(event_info) | 253 | all_event_list.append(event_info) |
254 | 254 | ||
255 | def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, callchain, napi, dev_name): | 255 | def napi__napi_poll(name, context, cpu, sec, nsec, pid, comm, callchain, napi, |
256 | dev_name, work=None, budget=None): | ||
256 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, | 257 | event_info = (name, context, cpu, nsecs(sec, nsec), pid, comm, |
257 | napi, dev_name) | 258 | napi, dev_name, work, budget) |
258 | all_event_list.append(event_info) | 259 | all_event_list.append(event_info) |
259 | 260 | ||
260 | def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr, | 261 | def net__netif_receive_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr, |
@@ -354,11 +355,13 @@ def handle_irq_softirq_exit(event_info): | |||
354 | receive_hunk_list.append(rec_data) | 355 | receive_hunk_list.append(rec_data) |
355 | 356 | ||
356 | def handle_napi_poll(event_info): | 357 | def handle_napi_poll(event_info): |
357 | (name, context, cpu, time, pid, comm, napi, dev_name) = event_info | 358 | (name, context, cpu, time, pid, comm, napi, dev_name, |
359 | work, budget) = event_info | ||
358 | if cpu in net_rx_dic.keys(): | 360 | if cpu in net_rx_dic.keys(): |
359 | event_list = net_rx_dic[cpu]['event_list'] | 361 | event_list = net_rx_dic[cpu]['event_list'] |
360 | rec_data = {'event_name':'napi_poll', | 362 | rec_data = {'event_name':'napi_poll', |
361 | 'dev':dev_name, 'event_t':time} | 363 | 'dev':dev_name, 'event_t':time, |
364 | 'work':work, 'budget':budget} | ||
362 | event_list.append(rec_data) | 365 | event_list.append(rec_data) |
363 | 366 | ||
364 | def handle_netif_rx(event_info): | 367 | def handle_netif_rx(event_info): |
diff --git a/tools/perf/scripts/python/stackcollapse.py b/tools/perf/scripts/python/stackcollapse.py new file mode 100755 index 000000000000..5a605f70ef32 --- /dev/null +++ b/tools/perf/scripts/python/stackcollapse.py | |||
@@ -0,0 +1,125 @@ | |||
1 | # stackcollapse.py - format perf samples with one line per distinct call stack | ||
2 | # | ||
3 | # This script's output has two space-separated fields. The first is a semicolon | ||
4 | # separated stack including the program name (from the "comm" field) and the | ||
5 | # function names from the call stack. The second is a count: | ||
6 | # | ||
7 | # swapper;start_kernel;rest_init;cpu_idle;default_idle;native_safe_halt 2 | ||
8 | # | ||
9 | # The file is sorted according to the first field. | ||
10 | # | ||
11 | # Input may be created and processed using: | ||
12 | # | ||
13 | # perf record -a -g -F 99 sleep 60 | ||
14 | # perf script report stackcollapse > out.stacks-folded | ||
15 | # | ||
16 | # (perf script record stackcollapse works too). | ||
17 | # | ||
18 | # Written by Paolo Bonzini <pbonzini@redhat.com> | ||
19 | # Based on Brendan Gregg's stackcollapse-perf.pl script. | ||
20 | |||
21 | import os | ||
22 | import sys | ||
23 | from collections import defaultdict | ||
24 | from optparse import OptionParser, make_option | ||
25 | |||
26 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
27 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
28 | |||
29 | from perf_trace_context import * | ||
30 | from Core import * | ||
31 | from EventClass import * | ||
32 | |||
33 | # command line parsing | ||
34 | |||
35 | option_list = [ | ||
36 | # formatting options for the bottom entry of the stack | ||
37 | make_option("--include-tid", dest="include_tid", | ||
38 | action="store_true", default=False, | ||
39 | help="include thread id in stack"), | ||
40 | make_option("--include-pid", dest="include_pid", | ||
41 | action="store_true", default=False, | ||
42 | help="include process id in stack"), | ||
43 | make_option("--no-comm", dest="include_comm", | ||
44 | action="store_false", default=True, | ||
45 | help="do not separate stacks according to comm"), | ||
46 | make_option("--tidy-java", dest="tidy_java", | ||
47 | action="store_true", default=False, | ||
48 | help="beautify Java signatures"), | ||
49 | make_option("--kernel", dest="annotate_kernel", | ||
50 | action="store_true", default=False, | ||
51 | help="annotate kernel functions with _[k]") | ||
52 | ] | ||
53 | |||
54 | parser = OptionParser(option_list=option_list) | ||
55 | (opts, args) = parser.parse_args() | ||
56 | |||
57 | if len(args) != 0: | ||
58 | parser.error("unexpected command line argument") | ||
59 | if opts.include_tid and not opts.include_comm: | ||
60 | parser.error("requesting tid but not comm is invalid") | ||
61 | if opts.include_pid and not opts.include_comm: | ||
62 | parser.error("requesting pid but not comm is invalid") | ||
63 | |||
64 | # event handlers | ||
65 | |||
66 | lines = defaultdict(lambda: 0) | ||
67 | |||
68 | def process_event(param_dict): | ||
69 | def tidy_function_name(sym, dso): | ||
70 | if sym is None: | ||
71 | sym = '[unknown]' | ||
72 | |||
73 | sym = sym.replace(';', ':') | ||
74 | if opts.tidy_java: | ||
75 | # the original stackcollapse-perf.pl script gives the | ||
76 | # example of converting this: | ||
77 | # Lorg/mozilla/javascript/MemberBox;.<init>(Ljava/lang/reflect/Method;)V | ||
78 | # to this: | ||
79 | # org/mozilla/javascript/MemberBox:.init | ||
80 | sym = sym.replace('<', '') | ||
81 | sym = sym.replace('>', '') | ||
82 | if sym[0] == 'L' and sym.find('/'): | ||
83 | sym = sym[1:] | ||
84 | try: | ||
85 | sym = sym[:sym.index('(')] | ||
86 | except ValueError: | ||
87 | pass | ||
88 | |||
89 | if opts.annotate_kernel and dso == '[kernel.kallsyms]': | ||
90 | return sym + '_[k]' | ||
91 | else: | ||
92 | return sym | ||
93 | |||
94 | stack = list() | ||
95 | if 'callchain' in param_dict: | ||
96 | for entry in param_dict['callchain']: | ||
97 | entry.setdefault('sym', dict()) | ||
98 | entry['sym'].setdefault('name', None) | ||
99 | entry.setdefault('dso', None) | ||
100 | stack.append(tidy_function_name(entry['sym']['name'], | ||
101 | entry['dso'])) | ||
102 | else: | ||
103 | param_dict.setdefault('symbol', None) | ||
104 | param_dict.setdefault('dso', None) | ||
105 | stack.append(tidy_function_name(param_dict['symbol'], | ||
106 | param_dict['dso'])) | ||
107 | |||
108 | if opts.include_comm: | ||
109 | comm = param_dict["comm"].replace(' ', '_') | ||
110 | sep = "-" | ||
111 | if opts.include_pid: | ||
112 | comm = comm + sep + str(param_dict['sample']['pid']) | ||
113 | sep = "/" | ||
114 | if opts.include_tid: | ||
115 | comm = comm + sep + str(param_dict['sample']['tid']) | ||
116 | stack.append(comm) | ||
117 | |||
118 | stack_string = ';'.join(reversed(stack)) | ||
119 | lines[stack_string] = lines[stack_string] + 1 | ||
120 | |||
121 | def trace_end(): | ||
122 | list = lines.keys() | ||
123 | list.sort() | ||
124 | for stack in list: | ||
125 | print "%s %d" % (stack, lines[stack]) | ||