diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2010-02-28 13:20:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-02-28 13:20:25 -0500 |
commit | 6556a6743549defc32e5f90ee2cb1ecd833a44c3 (patch) | |
tree | 622306583d4a3c13235a8bfc012854c125c597f1 /tools/perf/scripts/python/Perf-Trace-Util/lib/Perf | |
parent | e0d272429a34ff143bfa04ee8e29dd4eed2964c7 (diff) | |
parent | 1dd2980d990068e20045b90c424518cc7f3657ff (diff) |
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (172 commits)
perf_event, amd: Fix spinlock initialization
perf_event: Fix preempt warning in perf_clock()
perf tools: Flush maps on COMM events
perf_events, x86: Split PMU definitions into separate files
perf annotate: Handle samples not at objdump output addr boundaries
perf_events, x86: Remove superflous MSR writes
perf_events: Simplify code by removing cpu argument to hw_perf_group_sched_in()
perf_events, x86: AMD event scheduling
perf_events: Add new start/stop PMU callbacks
perf_events: Report the MMAP pgoff value in bytes
perf annotate: Defer allocating sym_priv->hist array
perf symbols: Improve debugging information about symtab origins
perf top: Use a macro instead of a constant variable
perf symbols: Check the right return variable
perf/scripts: Tag syscall_name helper as not yet available
perf/scripts: Add perf-trace-python Documentation
perf/scripts: Remove unnecessary PyTuple resizes
perf/scripts: Add syscall tracing scripts
perf/scripts: Add Python scripting engine
perf/scripts: Remove check-perf-trace from listed scripts
...
Fix trivial conflict in tools/perf/util/probe-event.c
Diffstat (limited to 'tools/perf/scripts/python/Perf-Trace-Util/lib/Perf')
-rw-r--r-- | tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py | 91 | ||||
-rw-r--r-- | tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | 25 |
2 files changed, 116 insertions, 0 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 new file mode 100644 index 000000000000..1dc464ee2ca8 --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py | |||
@@ -0,0 +1,91 @@ | |||
1 | # Core.py - Python extension for perf trace, core functions | ||
2 | # | ||
3 | # Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com> | ||
4 | # | ||
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 | ||
7 | # Foundation. | ||
8 | |||
9 | from collections import defaultdict | ||
10 | |||
11 | def autodict(): | ||
12 | return defaultdict(autodict) | ||
13 | |||
14 | flag_fields = autodict() | ||
15 | symbolic_fields = autodict() | ||
16 | |||
17 | def define_flag_field(event_name, field_name, delim): | ||
18 | flag_fields[event_name][field_name]['delim'] = delim | ||
19 | |||
20 | def define_flag_value(event_name, field_name, value, field_str): | ||
21 | flag_fields[event_name][field_name]['values'][value] = field_str | ||
22 | |||
23 | def define_symbolic_field(event_name, field_name): | ||
24 | # nothing to do, really | ||
25 | pass | ||
26 | |||
27 | def define_symbolic_value(event_name, field_name, value, field_str): | ||
28 | symbolic_fields[event_name][field_name]['values'][value] = field_str | ||
29 | |||
30 | def flag_str(event_name, field_name, value): | ||
31 | string = "" | ||
32 | |||
33 | if flag_fields[event_name][field_name]: | ||
34 | print_delim = 0 | ||
35 | keys = flag_fields[event_name][field_name]['values'].keys() | ||
36 | keys.sort() | ||
37 | for idx in keys: | ||
38 | if not value and not idx: | ||
39 | string += flag_fields[event_name][field_name]['values'][idx] | ||
40 | break | ||
41 | if idx and (value & idx) == idx: | ||
42 | if print_delim and flag_fields[event_name][field_name]['delim']: | ||
43 | string += " " + flag_fields[event_name][field_name]['delim'] + " " | ||
44 | string += flag_fields[event_name][field_name]['values'][idx] | ||
45 | print_delim = 1 | ||
46 | value &= ~idx | ||
47 | |||
48 | return string | ||
49 | |||
50 | def symbol_str(event_name, field_name, value): | ||
51 | string = "" | ||
52 | |||
53 | if symbolic_fields[event_name][field_name]: | ||
54 | keys = symbolic_fields[event_name][field_name]['values'].keys() | ||
55 | keys.sort() | ||
56 | for idx in keys: | ||
57 | if not value and not idx: | ||
58 | string = symbolic_fields[event_name][field_name]['values'][idx] | ||
59 | break | ||
60 | if (value == idx): | ||
61 | string = symbolic_fields[event_name][field_name]['values'][idx] | ||
62 | break | ||
63 | |||
64 | return string | ||
65 | |||
66 | trace_flags = { 0x00: "NONE", \ | ||
67 | 0x01: "IRQS_OFF", \ | ||
68 | 0x02: "IRQS_NOSUPPORT", \ | ||
69 | 0x04: "NEED_RESCHED", \ | ||
70 | 0x08: "HARDIRQ", \ | ||
71 | 0x10: "SOFTIRQ" } | ||
72 | |||
73 | def trace_flag_str(value): | ||
74 | string = "" | ||
75 | print_delim = 0 | ||
76 | |||
77 | keys = trace_flags.keys() | ||
78 | |||
79 | for idx in keys: | ||
80 | if not value and not idx: | ||
81 | string += "NONE" | ||
82 | break | ||
83 | |||
84 | if idx and (value & idx) == idx: | ||
85 | if print_delim: | ||
86 | string += " | "; | ||
87 | string += trace_flags[idx] | ||
88 | print_delim = 1 | ||
89 | value &= ~idx | ||
90 | |||
91 | return string | ||
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 new file mode 100644 index 000000000000..83e91435ed09 --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | |||
@@ -0,0 +1,25 @@ | |||
1 | # Util.py - Python extension for perf trace, miscellaneous utility code | ||
2 | # | ||
3 | # Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com> | ||
4 | # | ||
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 | ||
7 | # Foundation. | ||
8 | |||
9 | NSECS_PER_SEC = 1000000000 | ||
10 | |||
11 | def avg(total, n): | ||
12 | return total / n | ||
13 | |||
14 | def nsecs(secs, nsecs): | ||
15 | return secs * NSECS_PER_SEC + nsecs | ||
16 | |||
17 | def nsecs_secs(nsecs): | ||
18 | return nsecs / NSECS_PER_SEC | ||
19 | |||
20 | def nsecs_nsecs(nsecs): | ||
21 | return nsecs % NSECS_PER_SEC | ||
22 | |||
23 | def nsecs_str(nsecs): | ||
24 | str = "%5u.%09u" % (nsecs_secs(nsecs), nsecs_nsecs(nsecs)), | ||
25 | return str | ||