Librarize the task state and event headers helpers as they can be generally useful.
Showing the changes to tools/perf/scripts/python (2 of 2 files). Show all
Unified · Split
| @@ -89,3 +89,33 @@ def trace_flag_str(value): · 88 unmodified lines | ||
| 89 | 89 | value &= ~idx |
| 90 | 90 | |
| 91 | 91 | return string |
| 92 | + | |
| 93 | + | |
| 94 | +def taskState(state): | |
| 95 | + states = { | |
| 96 | + 0 : "R", | |
| 97 | + 1 : "S", | |
| 98 | + 2 : "D", | |
| 99 | + 64: "DEAD" | |
| 100 | + } | |
| 101 | + | |
| 102 | + if state not in states: | |
| 103 | + return "Unknown" | |
| 104 | + | |
| 105 | + return states[state] | |
| 106 | + | |
| 107 | + | |
| 108 | +class EventHeaders: | |
| 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 | |
| 116 | + | |
| 117 | + def ts(self): | |
| 118 | + return (self.secs * (10 ** 9)) + self.nsecs | |
| 119 | + | |
| 120 | + def ts_format(self): | |
| 121 | + return "%d.%d" % (self.secs, int(self.nsecs / 1000)) | |
| @@ -31,36 +31,6 @@ threads = { 0 : "idle"} · 30 unmodified lines | ||
| 31 | 31 | def thread_name(pid): |
| 32 | 32 | return "%s:%d" % (threads[pid], pid) |
| 33 | 33 | |
| 34 | −class EventHeaders: | |
| 35 | − def __init__(self, common_cpu, common_secs, common_nsecs, | |
| 36 | − common_pid, common_comm): | |
| 37 | − self.cpu = common_cpu | |
| 38 | − self.secs = common_secs | |
| 39 | − self.nsecs = common_nsecs | |
| 40 | − self.pid = common_pid | |
| 41 | − self.comm = common_comm | |
| 42 | − | |
| 43 | − def ts(self): | |
| 44 | − return (self.secs * (10 ** 9)) + self.nsecs | |
| 45 | − | |
| 46 | − def ts_format(self): | |
| 47 | − return "%d.%d" % (self.secs, int(self.nsecs / 1000)) | |
| 48 | − | |
| 49 | − | |
| 50 | −def taskState(state): | |
| 51 | − states = { | |
| 52 | − 0 : "R", | |
| 53 | − 1 : "S", | |
| 54 | − 2 : "D", | |
| 55 | − 64: "DEAD" | |
| 56 | − } | |
| 57 | − | |
| 58 | − if state not in states: | |
| 59 | − return "Unknown" | |
| 60 | − | |
| 61 | − return states[state] | |
| 62 | − | |
| 63 | − | |
| 64 | 34 | class RunqueueEventUnknown: |
| 65 | 35 | @staticmethod |
| 66 | 36 | def color(): |