]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py
1 # Core.py - Python extension for perf trace, core functions
3 # Copyright (C) 2010 by Tom Zanussi <tzanussi@gmail.com>
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
9 from collections
import defaultdict
12 return defaultdict(autodict
)
14 flag_fields
= autodict()
15 symbolic_fields
= autodict()
17 def define_flag_field(event_name
, field_name
, delim
):
18 flag_fields
[event_name
][field_name
]['delim'] = delim
20 def define_flag_value(event_name
, field_name
, value
, field_str
):
21 flag_fields
[event_name
][field_name
]['values'][value
] = field_str
23 def define_symbolic_field(event_name
, field_name
):
24 # nothing to do, really
27 def define_symbolic_value(event_name
, field_name
, value
, field_str
):
28 symbolic_fields
[event_name
][field_name
]['values'][value
] = field_str
30 def flag_str(event_name
, field_name
, value
):
33 if flag_fields
[event_name
][field_name
]:
35 keys
= flag_fields
[event_name
][field_name
]['values'].keys()
38 if not value
and not idx
:
39 string
+= flag_fields
[event_name
][field_name
]['values'][idx
]
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
]
50 def symbol_str(event_name
, field_name
, value
):
53 if symbolic_fields
[event_name
][field_name
]:
54 keys
= symbolic_fields
[event_name
][field_name
]['values'].keys()
57 if not value
and not idx
:
58 string
= symbolic_fields
[event_name
][field_name
]['values'][idx
]
61 string
= symbolic_fields
[event_name
][field_name
]['values'][idx
]
66 trace_flags
= { 0x00: "NONE", \
68 0x02: "IRQS_NOSUPPORT", \
69 0x04: "NEED_RESCHED", \
73 def trace_flag_str(value
):
77 keys
= trace_flags
.keys()
80 if not value
and not idx
:
84 if idx
and (value
& idx
) == idx
:
87 string
+= trace_flags
[idx
]
102 if state
not in states
:
109 def __init__(self
, common_cpu
, common_secs
, common_nsecs
,
110 common_pid
, common_comm
):
111 self
.cpu
= common_cpu
112 self
.secs
= common_secs
113 self
.nsecs
= common_nsecs
114 self
.pid
= common_pid
115 self
.comm
= common_comm
118 return (self
.secs
* (10 ** 9)) + self
.nsecs
121 return "%d.%d" % (self
.secs
, int(self
.nsecs
/ 1000))