diff options
| author | Michal Marek <mmarek@suse.cz> | 2010-10-27 18:15:57 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2010-10-27 18:15:57 -0400 |
| commit | b74b953b998bcc2db91b694446f3a2619ec32de6 (patch) | |
| tree | 6ce24caabd730f6ae9287ed0676ec32e6ff31e9d /tools/perf/scripts/python | |
| parent | abb438526201c6a79949ad45375c051b6681c253 (diff) | |
| parent | f6f94e2ab1b33f0082ac22d71f66385a60d8157f (diff) | |
Merge commit 'v2.6.36' into kbuild/misc
Update to be able to fix a recent change to scripts/basic/docproc.c
(commit eda603f).
Diffstat (limited to 'tools/perf/scripts/python')
20 files changed, 1299 insertions, 0 deletions
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/Context.c b/tools/perf/scripts/python/Perf-Trace-Util/Context.c new file mode 100644 index 000000000000..957085dd5d8d --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/Context.c | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* | ||
| 2 | * Context.c. Python interfaces for perf trace. | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Tom Zanussi <tzanussi@gmail.com> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 19 | * | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <Python.h> | ||
| 23 | #include "../../../perf.h" | ||
| 24 | #include "../../../util/trace-event.h" | ||
| 25 | |||
| 26 | PyMODINIT_FUNC initperf_trace_context(void); | ||
| 27 | |||
| 28 | static PyObject *perf_trace_context_common_pc(PyObject *self, PyObject *args) | ||
| 29 | { | ||
| 30 | static struct scripting_context *scripting_context; | ||
| 31 | PyObject *context; | ||
| 32 | int retval; | ||
| 33 | |||
| 34 | if (!PyArg_ParseTuple(args, "O", &context)) | ||
| 35 | return NULL; | ||
| 36 | |||
| 37 | scripting_context = PyCObject_AsVoidPtr(context); | ||
| 38 | retval = common_pc(scripting_context); | ||
| 39 | |||
| 40 | return Py_BuildValue("i", retval); | ||
| 41 | } | ||
| 42 | |||
| 43 | static PyObject *perf_trace_context_common_flags(PyObject *self, | ||
| 44 | PyObject *args) | ||
| 45 | { | ||
| 46 | static struct scripting_context *scripting_context; | ||
| 47 | PyObject *context; | ||
| 48 | int retval; | ||
| 49 | |||
| 50 | if (!PyArg_ParseTuple(args, "O", &context)) | ||
| 51 | return NULL; | ||
| 52 | |||
| 53 | scripting_context = PyCObject_AsVoidPtr(context); | ||
| 54 | retval = common_flags(scripting_context); | ||
| 55 | |||
| 56 | return Py_BuildValue("i", retval); | ||
| 57 | } | ||
| 58 | |||
| 59 | static PyObject *perf_trace_context_common_lock_depth(PyObject *self, | ||
| 60 | PyObject *args) | ||
| 61 | { | ||
| 62 | static struct scripting_context *scripting_context; | ||
| 63 | PyObject *context; | ||
| 64 | int retval; | ||
| 65 | |||
| 66 | if (!PyArg_ParseTuple(args, "O", &context)) | ||
| 67 | return NULL; | ||
| 68 | |||
| 69 | scripting_context = PyCObject_AsVoidPtr(context); | ||
| 70 | retval = common_lock_depth(scripting_context); | ||
| 71 | |||
| 72 | return Py_BuildValue("i", retval); | ||
| 73 | } | ||
| 74 | |||
| 75 | static PyMethodDef ContextMethods[] = { | ||
| 76 | { "common_pc", perf_trace_context_common_pc, METH_VARARGS, | ||
| 77 | "Get the common preempt count event field value."}, | ||
| 78 | { "common_flags", perf_trace_context_common_flags, METH_VARARGS, | ||
| 79 | "Get the common flags event field value."}, | ||
| 80 | { "common_lock_depth", perf_trace_context_common_lock_depth, | ||
| 81 | METH_VARARGS, "Get the common lock depth event field value."}, | ||
| 82 | { NULL, NULL, 0, NULL} | ||
| 83 | }; | ||
| 84 | |||
| 85 | PyMODINIT_FUNC initperf_trace_context(void) | ||
| 86 | { | ||
| 87 | (void) Py_InitModule("perf_trace_context", ContextMethods); | ||
| 88 | } | ||
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..aad7525bca1d --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Core.py | |||
| @@ -0,0 +1,121 @@ | |||
| 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 | ||
| 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)) | ||
diff --git a/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py new file mode 100644 index 000000000000..ae9a56e43e05 --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | # SchedGui.py - Python extension for perf trace, basic GUI code for | ||
| 2 | # traces drawing and overview. | ||
| 3 | # | ||
| 4 | # Copyright (C) 2010 by Frederic Weisbecker <fweisbec@gmail.com> | ||
| 5 | # | ||
| 6 | # This software is distributed under the terms of the GNU General | ||
| 7 | # Public License ("GPL") version 2 as published by the Free Software | ||
| 8 | # Foundation. | ||
| 9 | |||
| 10 | |||
| 11 | try: | ||
| 12 | import wx | ||
| 13 | except ImportError: | ||
| 14 | raise ImportError, "You need to install the wxpython lib for this script" | ||
| 15 | |||
| 16 | |||
| 17 | class RootFrame(wx.Frame): | ||
| 18 | Y_OFFSET = 100 | ||
| 19 | RECT_HEIGHT = 100 | ||
| 20 | RECT_SPACE = 50 | ||
| 21 | EVENT_MARKING_WIDTH = 5 | ||
| 22 | |||
| 23 | def __init__(self, sched_tracer, title, parent = None, id = -1): | ||
| 24 | wx.Frame.__init__(self, parent, id, title) | ||
| 25 | |||
| 26 | (self.screen_width, self.screen_height) = wx.GetDisplaySize() | ||
| 27 | self.screen_width -= 10 | ||
| 28 | self.screen_height -= 10 | ||
| 29 | self.zoom = 0.5 | ||
| 30 | self.scroll_scale = 20 | ||
| 31 | self.sched_tracer = sched_tracer | ||
| 32 | self.sched_tracer.set_root_win(self) | ||
| 33 | (self.ts_start, self.ts_end) = sched_tracer.interval() | ||
| 34 | self.update_width_virtual() | ||
| 35 | self.nr_rects = sched_tracer.nr_rectangles() + 1 | ||
| 36 | self.height_virtual = RootFrame.Y_OFFSET + (self.nr_rects * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) | ||
| 37 | |||
| 38 | # whole window panel | ||
| 39 | self.panel = wx.Panel(self, size=(self.screen_width, self.screen_height)) | ||
| 40 | |||
| 41 | # scrollable container | ||
| 42 | self.scroll = wx.ScrolledWindow(self.panel) | ||
| 43 | self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale) | ||
| 44 | self.scroll.EnableScrolling(True, True) | ||
| 45 | self.scroll.SetFocus() | ||
| 46 | |||
| 47 | # scrollable drawing area | ||
| 48 | self.scroll_panel = wx.Panel(self.scroll, size=(self.screen_width - 15, self.screen_height / 2)) | ||
| 49 | self.scroll_panel.Bind(wx.EVT_PAINT, self.on_paint) | ||
| 50 | self.scroll_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press) | ||
| 51 | self.scroll_panel.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) | ||
| 52 | self.scroll.Bind(wx.EVT_PAINT, self.on_paint) | ||
| 53 | self.scroll.Bind(wx.EVT_KEY_DOWN, self.on_key_press) | ||
| 54 | self.scroll.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) | ||
| 55 | |||
| 56 | self.scroll.Fit() | ||
| 57 | self.Fit() | ||
| 58 | |||
| 59 | self.scroll_panel.SetDimensions(-1, -1, self.width_virtual, self.height_virtual, wx.SIZE_USE_EXISTING) | ||
| 60 | |||
| 61 | self.txt = None | ||
| 62 | |||
| 63 | self.Show(True) | ||
| 64 | |||
| 65 | def us_to_px(self, val): | ||
| 66 | return val / (10 ** 3) * self.zoom | ||
| 67 | |||
| 68 | def px_to_us(self, val): | ||
| 69 | return (val / self.zoom) * (10 ** 3) | ||
| 70 | |||
| 71 | def scroll_start(self): | ||
| 72 | (x, y) = self.scroll.GetViewStart() | ||
| 73 | return (x * self.scroll_scale, y * self.scroll_scale) | ||
| 74 | |||
| 75 | def scroll_start_us(self): | ||
| 76 | (x, y) = self.scroll_start() | ||
| 77 | return self.px_to_us(x) | ||
| 78 | |||
| 79 | def paint_rectangle_zone(self, nr, color, top_color, start, end): | ||
| 80 | offset_px = self.us_to_px(start - self.ts_start) | ||
| 81 | width_px = self.us_to_px(end - self.ts_start) | ||
| 82 | |||
| 83 | offset_py = RootFrame.Y_OFFSET + (nr * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) | ||
| 84 | width_py = RootFrame.RECT_HEIGHT | ||
| 85 | |||
| 86 | dc = self.dc | ||
| 87 | |||
| 88 | if top_color is not None: | ||
| 89 | (r, g, b) = top_color | ||
| 90 | top_color = wx.Colour(r, g, b) | ||
| 91 | brush = wx.Brush(top_color, wx.SOLID) | ||
| 92 | dc.SetBrush(brush) | ||
| 93 | dc.DrawRectangle(offset_px, offset_py, width_px, RootFrame.EVENT_MARKING_WIDTH) | ||
| 94 | width_py -= RootFrame.EVENT_MARKING_WIDTH | ||
| 95 | offset_py += RootFrame.EVENT_MARKING_WIDTH | ||
| 96 | |||
| 97 | (r ,g, b) = color | ||
| 98 | color = wx.Colour(r, g, b) | ||
| 99 | brush = wx.Brush(color, wx.SOLID) | ||
| 100 | dc.SetBrush(brush) | ||
| 101 | dc.DrawRectangle(offset_px, offset_py, width_px, width_py) | ||
| 102 | |||
| 103 | def update_rectangles(self, dc, start, end): | ||
| 104 | start += self.ts_start | ||
| 105 | end += self.ts_start | ||
| 106 | self.sched_tracer.fill_zone(start, end) | ||
| 107 | |||
| 108 | def on_paint(self, event): | ||
| 109 | dc = wx.PaintDC(self.scroll_panel) | ||
| 110 | self.dc = dc | ||
| 111 | |||
| 112 | width = min(self.width_virtual, self.screen_width) | ||
| 113 | (x, y) = self.scroll_start() | ||
| 114 | start = self.px_to_us(x) | ||
| 115 | end = self.px_to_us(x + width) | ||
| 116 | self.update_rectangles(dc, start, end) | ||
| 117 | |||
| 118 | def rect_from_ypixel(self, y): | ||
| 119 | y -= RootFrame.Y_OFFSET | ||
| 120 | rect = y / (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) | ||
| 121 | height = y % (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) | ||
| 122 | |||
| 123 | if rect < 0 or rect > self.nr_rects - 1 or height > RootFrame.RECT_HEIGHT: | ||
| 124 | return -1 | ||
| 125 | |||
| 126 | return rect | ||
| 127 | |||
| 128 | def update_summary(self, txt): | ||
| 129 | if self.txt: | ||
| 130 | self.txt.Destroy() | ||
| 131 | self.txt = wx.StaticText(self.panel, -1, txt, (0, (self.screen_height / 2) + 50)) | ||
| 132 | |||
| 133 | |||
| 134 | def on_mouse_down(self, event): | ||
| 135 | (x, y) = event.GetPositionTuple() | ||
| 136 | rect = self.rect_from_ypixel(y) | ||
| 137 | if rect == -1: | ||
| 138 | return | ||
| 139 | |||
| 140 | t = self.px_to_us(x) + self.ts_start | ||
| 141 | |||
| 142 | self.sched_tracer.mouse_down(rect, t) | ||
| 143 | |||
| 144 | |||
| 145 | def update_width_virtual(self): | ||
| 146 | self.width_virtual = self.us_to_px(self.ts_end - self.ts_start) | ||
| 147 | |||
| 148 | def __zoom(self, x): | ||
| 149 | self.update_width_virtual() | ||
| 150 | (xpos, ypos) = self.scroll.GetViewStart() | ||
| 151 | xpos = self.us_to_px(x) / self.scroll_scale | ||
| 152 | self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale, xpos, ypos) | ||
| 153 | self.Refresh() | ||
| 154 | |||
| 155 | def zoom_in(self): | ||
| 156 | x = self.scroll_start_us() | ||
| 157 | self.zoom *= 2 | ||
| 158 | self.__zoom(x) | ||
| 159 | |||
| 160 | def zoom_out(self): | ||
| 161 | x = self.scroll_start_us() | ||
| 162 | self.zoom /= 2 | ||
| 163 | self.__zoom(x) | ||
| 164 | |||
| 165 | |||
| 166 | def on_key_press(self, event): | ||
| 167 | key = event.GetRawKeyCode() | ||
| 168 | if key == ord("+"): | ||
| 169 | self.zoom_in() | ||
| 170 | return | ||
| 171 | if key == ord("-"): | ||
| 172 | self.zoom_out() | ||
| 173 | return | ||
| 174 | |||
| 175 | key = event.GetKeyCode() | ||
| 176 | (x, y) = self.scroll.GetViewStart() | ||
| 177 | if key == wx.WXK_RIGHT: | ||
| 178 | self.scroll.Scroll(x + 1, y) | ||
| 179 | elif key == wx.WXK_LEFT: | ||
| 180 | self.scroll.Scroll(x - 1, y) | ||
| 181 | elif key == wx.WXK_DOWN: | ||
| 182 | self.scroll.Scroll(x, y + 1) | ||
| 183 | elif key == wx.WXK_UP: | ||
| 184 | self.scroll.Scroll(x, y - 1) | ||
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..9689bc0acd9f --- /dev/null +++ b/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/Util.py | |||
| @@ -0,0 +1,28 @@ | |||
| 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 | ||
| 26 | |||
| 27 | def clear_term(): | ||
| 28 | print("\x1b[H\x1b[2J") | ||
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record new file mode 100644 index 000000000000..eb5846bcb565 --- /dev/null +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -a -e raw_syscalls:sys_exit $@ | ||
diff --git a/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report new file mode 100644 index 000000000000..30293545fcc2 --- /dev/null +++ b/tools/perf/scripts/python/bin/failed-syscalls-by-pid-report | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # description: system-wide failed syscalls, by pid | ||
| 3 | # args: [comm] | ||
| 4 | if [ $# -gt 0 ] ; then | ||
| 5 | if ! expr match "$1" "-" > /dev/null ; then | ||
| 6 | comm=$1 | ||
| 7 | shift | ||
| 8 | fi | ||
| 9 | fi | ||
| 10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/failed-syscalls-by-pid.py $comm | ||
diff --git a/tools/perf/scripts/python/bin/sched-migration-record b/tools/perf/scripts/python/bin/sched-migration-record new file mode 100644 index 000000000000..17a3e9bd9e8f --- /dev/null +++ b/tools/perf/scripts/python/bin/sched-migration-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -m 16384 -a -e sched:sched_wakeup -e sched:sched_wakeup_new -e sched:sched_switch -e sched:sched_migrate_task $@ | ||
diff --git a/tools/perf/scripts/python/bin/sched-migration-report b/tools/perf/scripts/python/bin/sched-migration-report new file mode 100644 index 000000000000..61d05f72e443 --- /dev/null +++ b/tools/perf/scripts/python/bin/sched-migration-report | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # description: sched migration overview | ||
| 3 | perf trace $@ -s ~/libexec/perf-core/scripts/python/sched-migration.py | ||
diff --git a/tools/perf/scripts/python/bin/sctop-record b/tools/perf/scripts/python/bin/sctop-record new file mode 100644 index 000000000000..1fc5998b721d --- /dev/null +++ b/tools/perf/scripts/python/bin/sctop-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -a -e raw_syscalls:sys_enter $@ | ||
diff --git a/tools/perf/scripts/python/bin/sctop-report b/tools/perf/scripts/python/bin/sctop-report new file mode 100644 index 000000000000..b01c842ae7b4 --- /dev/null +++ b/tools/perf/scripts/python/bin/sctop-report | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # description: syscall top | ||
| 3 | # args: [comm] [interval] | ||
| 4 | n_args=0 | ||
| 5 | for i in "$@" | ||
| 6 | do | ||
| 7 | if expr match "$i" "-" > /dev/null ; then | ||
| 8 | break | ||
| 9 | fi | ||
| 10 | n_args=$(( $n_args + 1 )) | ||
| 11 | done | ||
| 12 | if [ "$n_args" -gt 2 ] ; then | ||
| 13 | echo "usage: sctop-report [comm] [interval]" | ||
| 14 | exit | ||
| 15 | fi | ||
| 16 | if [ "$n_args" -gt 1 ] ; then | ||
| 17 | comm=$1 | ||
| 18 | interval=$2 | ||
| 19 | shift 2 | ||
| 20 | elif [ "$n_args" -gt 0 ] ; then | ||
| 21 | interval=$1 | ||
| 22 | shift | ||
| 23 | fi | ||
| 24 | perf trace $@ -s ~/libexec/perf-core/scripts/python/sctop.py $comm $interval | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-record b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record new file mode 100644 index 000000000000..1fc5998b721d --- /dev/null +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -a -e raw_syscalls:sys_enter $@ | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-by-pid-report b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report new file mode 100644 index 000000000000..9e9d8ddd72ce --- /dev/null +++ b/tools/perf/scripts/python/bin/syscall-counts-by-pid-report | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # description: system-wide syscall counts, by pid | ||
| 3 | # args: [comm] | ||
| 4 | if [ $# -gt 0 ] ; then | ||
| 5 | if ! expr match "$1" "-" > /dev/null ; then | ||
| 6 | comm=$1 | ||
| 7 | shift | ||
| 8 | fi | ||
| 9 | fi | ||
| 10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts-by-pid.py $comm | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-record b/tools/perf/scripts/python/bin/syscall-counts-record new file mode 100644 index 000000000000..1fc5998b721d --- /dev/null +++ b/tools/perf/scripts/python/bin/syscall-counts-record | |||
| @@ -0,0 +1,2 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | perf record -a -e raw_syscalls:sys_enter $@ | ||
diff --git a/tools/perf/scripts/python/bin/syscall-counts-report b/tools/perf/scripts/python/bin/syscall-counts-report new file mode 100644 index 000000000000..dc076b618796 --- /dev/null +++ b/tools/perf/scripts/python/bin/syscall-counts-report | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # description: system-wide syscall counts | ||
| 3 | # args: [comm] | ||
| 4 | if [ $# -gt 0 ] ; then | ||
| 5 | if ! expr match "$1" "-" > /dev/null ; then | ||
| 6 | comm=$1 | ||
| 7 | shift | ||
| 8 | fi | ||
| 9 | fi | ||
| 10 | perf trace $@ -s ~/libexec/perf-core/scripts/python/syscall-counts.py $comm | ||
diff --git a/tools/perf/scripts/python/check-perf-trace.py b/tools/perf/scripts/python/check-perf-trace.py new file mode 100644 index 000000000000..d9f7893e315c --- /dev/null +++ b/tools/perf/scripts/python/check-perf-trace.py | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | # perf trace event handlers, generated by perf trace -g python | ||
| 2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
| 3 | # Licensed under the terms of the GNU GPL License version 2 | ||
| 4 | # | ||
| 5 | # This script tests basic functionality such as flag and symbol | ||
| 6 | # strings, common_xxx() calls back into perf, begin, end, unhandled | ||
| 7 | # events, etc. Basically, if this script runs successfully and | ||
| 8 | # displays expected results, Python scripting support should be ok. | ||
| 9 | |||
| 10 | import os | ||
| 11 | import sys | ||
| 12 | |||
| 13 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 14 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 15 | |||
| 16 | from Core import * | ||
| 17 | from perf_trace_context import * | ||
| 18 | |||
| 19 | unhandled = autodict() | ||
| 20 | |||
| 21 | def trace_begin(): | ||
| 22 | print "trace_begin" | ||
| 23 | pass | ||
| 24 | |||
| 25 | def trace_end(): | ||
| 26 | print_unhandled() | ||
| 27 | |||
| 28 | def irq__softirq_entry(event_name, context, common_cpu, | ||
| 29 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 30 | vec): | ||
| 31 | print_header(event_name, common_cpu, common_secs, common_nsecs, | ||
| 32 | common_pid, common_comm) | ||
| 33 | |||
| 34 | print_uncommon(context) | ||
| 35 | |||
| 36 | print "vec=%s\n" % \ | ||
| 37 | (symbol_str("irq__softirq_entry", "vec", vec)), | ||
| 38 | |||
| 39 | def kmem__kmalloc(event_name, context, common_cpu, | ||
| 40 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 41 | call_site, ptr, bytes_req, bytes_alloc, | ||
| 42 | gfp_flags): | ||
| 43 | print_header(event_name, common_cpu, common_secs, common_nsecs, | ||
| 44 | common_pid, common_comm) | ||
| 45 | |||
| 46 | print_uncommon(context) | ||
| 47 | |||
| 48 | print "call_site=%u, ptr=%u, bytes_req=%u, " \ | ||
| 49 | "bytes_alloc=%u, gfp_flags=%s\n" % \ | ||
| 50 | (call_site, ptr, bytes_req, bytes_alloc, | ||
| 51 | |||
| 52 | flag_str("kmem__kmalloc", "gfp_flags", gfp_flags)), | ||
| 53 | |||
| 54 | def trace_unhandled(event_name, context, event_fields_dict): | ||
| 55 | try: | ||
| 56 | unhandled[event_name] += 1 | ||
| 57 | except TypeError: | ||
| 58 | unhandled[event_name] = 1 | ||
| 59 | |||
| 60 | def print_header(event_name, cpu, secs, nsecs, pid, comm): | ||
| 61 | print "%-20s %5u %05u.%09u %8u %-20s " % \ | ||
| 62 | (event_name, cpu, secs, nsecs, pid, comm), | ||
| 63 | |||
| 64 | # print trace fields not included in handler args | ||
| 65 | def print_uncommon(context): | ||
| 66 | print "common_preempt_count=%d, common_flags=%s, common_lock_depth=%d, " \ | ||
| 67 | % (common_pc(context), trace_flag_str(common_flags(context)), \ | ||
| 68 | common_lock_depth(context)) | ||
| 69 | |||
| 70 | def print_unhandled(): | ||
| 71 | keys = unhandled.keys() | ||
| 72 | if not keys: | ||
| 73 | return | ||
| 74 | |||
| 75 | print "\nunhandled events:\n\n", | ||
| 76 | |||
| 77 | print "%-40s %10s\n" % ("event", "count"), | ||
| 78 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
| 79 | "-----------"), | ||
| 80 | |||
| 81 | for event_name in keys: | ||
| 82 | print "%-40s %10d\n" % (event_name, unhandled[event_name]) | ||
diff --git a/tools/perf/scripts/python/failed-syscalls-by-pid.py b/tools/perf/scripts/python/failed-syscalls-by-pid.py new file mode 100644 index 000000000000..0ca02278fe69 --- /dev/null +++ b/tools/perf/scripts/python/failed-syscalls-by-pid.py | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | # failed system call counts, by pid | ||
| 2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
| 3 | # Licensed under the terms of the GNU GPL License version 2 | ||
| 4 | # | ||
| 5 | # Displays system-wide failed system call totals, broken down by pid. | ||
| 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. | ||
| 7 | |||
| 8 | import os | ||
| 9 | import sys | ||
| 10 | |||
| 11 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 12 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 13 | |||
| 14 | from perf_trace_context import * | ||
| 15 | from Core import * | ||
| 16 | |||
| 17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; | ||
| 18 | |||
| 19 | for_comm = None | ||
| 20 | |||
| 21 | if len(sys.argv) > 2: | ||
| 22 | sys.exit(usage) | ||
| 23 | |||
| 24 | if len(sys.argv) > 1: | ||
| 25 | for_comm = sys.argv[1] | ||
| 26 | |||
| 27 | syscalls = autodict() | ||
| 28 | |||
| 29 | def trace_begin(): | ||
| 30 | pass | ||
| 31 | |||
| 32 | def trace_end(): | ||
| 33 | print_error_totals() | ||
| 34 | |||
| 35 | def raw_syscalls__sys_exit(event_name, context, common_cpu, | ||
| 36 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 37 | id, ret): | ||
| 38 | if for_comm is not None: | ||
| 39 | if common_comm != for_comm: | ||
| 40 | return | ||
| 41 | |||
| 42 | if ret < 0: | ||
| 43 | try: | ||
| 44 | syscalls[common_comm][common_pid][id][ret] += 1 | ||
| 45 | except TypeError: | ||
| 46 | syscalls[common_comm][common_pid][id][ret] = 1 | ||
| 47 | |||
| 48 | def print_error_totals(): | ||
| 49 | if for_comm is not None: | ||
| 50 | print "\nsyscall errors for %s:\n\n" % (for_comm), | ||
| 51 | else: | ||
| 52 | print "\nsyscall errors:\n\n", | ||
| 53 | |||
| 54 | print "%-30s %10s\n" % ("comm [pid]", "count"), | ||
| 55 | print "%-30s %10s\n" % ("------------------------------", \ | ||
| 56 | "----------"), | ||
| 57 | |||
| 58 | comm_keys = syscalls.keys() | ||
| 59 | for comm in comm_keys: | ||
| 60 | pid_keys = syscalls[comm].keys() | ||
| 61 | for pid in pid_keys: | ||
| 62 | print "\n%s [%d]\n" % (comm, pid), | ||
| 63 | id_keys = syscalls[comm][pid].keys() | ||
| 64 | for id in id_keys: | ||
| 65 | print " syscall: %-16d\n" % (id), | ||
| 66 | ret_keys = syscalls[comm][pid][id].keys() | ||
| 67 | for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): | ||
| 68 | print " err = %-20d %10d\n" % (ret, val), | ||
diff --git a/tools/perf/scripts/python/sched-migration.py b/tools/perf/scripts/python/sched-migration.py new file mode 100644 index 000000000000..b934383c3364 --- /dev/null +++ b/tools/perf/scripts/python/sched-migration.py | |||
| @@ -0,0 +1,461 @@ | |||
| 1 | #!/usr/bin/python | ||
| 2 | # | ||
| 3 | # Cpu task migration overview toy | ||
| 4 | # | ||
| 5 | # Copyright (C) 2010 Frederic Weisbecker <fweisbec@gmail.com> | ||
| 6 | # | ||
| 7 | # perf trace event handlers have been generated by perf trace -g python | ||
| 8 | # | ||
| 9 | # This software is distributed under the terms of the GNU General | ||
| 10 | # Public License ("GPL") version 2 as published by the Free Software | ||
| 11 | # Foundation. | ||
| 12 | |||
| 13 | |||
| 14 | import os | ||
| 15 | import sys | ||
| 16 | |||
| 17 | from collections import defaultdict | ||
| 18 | from UserList import UserList | ||
| 19 | |||
| 20 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 21 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 22 | sys.path.append('scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 23 | |||
| 24 | from perf_trace_context import * | ||
| 25 | from Core import * | ||
| 26 | from SchedGui import * | ||
| 27 | |||
| 28 | |||
| 29 | threads = { 0 : "idle"} | ||
| 30 | |||
| 31 | def thread_name(pid): | ||
| 32 | return "%s:%d" % (threads[pid], pid) | ||
| 33 | |||
| 34 | class RunqueueEventUnknown: | ||
| 35 | @staticmethod | ||
| 36 | def color(): | ||
| 37 | return None | ||
| 38 | |||
| 39 | def __repr__(self): | ||
| 40 | return "unknown" | ||
| 41 | |||
| 42 | class RunqueueEventSleep: | ||
| 43 | @staticmethod | ||
| 44 | def color(): | ||
| 45 | return (0, 0, 0xff) | ||
| 46 | |||
| 47 | def __init__(self, sleeper): | ||
| 48 | self.sleeper = sleeper | ||
| 49 | |||
| 50 | def __repr__(self): | ||
| 51 | return "%s gone to sleep" % thread_name(self.sleeper) | ||
| 52 | |||
| 53 | class RunqueueEventWakeup: | ||
| 54 | @staticmethod | ||
| 55 | def color(): | ||
| 56 | return (0xff, 0xff, 0) | ||
| 57 | |||
| 58 | def __init__(self, wakee): | ||
| 59 | self.wakee = wakee | ||
| 60 | |||
| 61 | def __repr__(self): | ||
| 62 | return "%s woke up" % thread_name(self.wakee) | ||
| 63 | |||
| 64 | class RunqueueEventFork: | ||
| 65 | @staticmethod | ||
| 66 | def color(): | ||
| 67 | return (0, 0xff, 0) | ||
| 68 | |||
| 69 | def __init__(self, child): | ||
| 70 | self.child = child | ||
| 71 | |||
| 72 | def __repr__(self): | ||
| 73 | return "new forked task %s" % thread_name(self.child) | ||
| 74 | |||
| 75 | class RunqueueMigrateIn: | ||
| 76 | @staticmethod | ||
| 77 | def color(): | ||
| 78 | return (0, 0xf0, 0xff) | ||
| 79 | |||
| 80 | def __init__(self, new): | ||
| 81 | self.new = new | ||
| 82 | |||
| 83 | def __repr__(self): | ||
| 84 | return "task migrated in %s" % thread_name(self.new) | ||
| 85 | |||
| 86 | class RunqueueMigrateOut: | ||
| 87 | @staticmethod | ||
| 88 | def color(): | ||
| 89 | return (0xff, 0, 0xff) | ||
| 90 | |||
| 91 | def __init__(self, old): | ||
| 92 | self.old = old | ||
| 93 | |||
| 94 | def __repr__(self): | ||
| 95 | return "task migrated out %s" % thread_name(self.old) | ||
| 96 | |||
| 97 | class RunqueueSnapshot: | ||
| 98 | def __init__(self, tasks = [0], event = RunqueueEventUnknown()): | ||
| 99 | self.tasks = tuple(tasks) | ||
| 100 | self.event = event | ||
| 101 | |||
| 102 | def sched_switch(self, prev, prev_state, next): | ||
| 103 | event = RunqueueEventUnknown() | ||
| 104 | |||
| 105 | if taskState(prev_state) == "R" and next in self.tasks \ | ||
| 106 | and prev in self.tasks: | ||
| 107 | return self | ||
| 108 | |||
| 109 | if taskState(prev_state) != "R": | ||
| 110 | event = RunqueueEventSleep(prev) | ||
| 111 | |||
| 112 | next_tasks = list(self.tasks[:]) | ||
| 113 | if prev in self.tasks: | ||
| 114 | if taskState(prev_state) != "R": | ||
| 115 | next_tasks.remove(prev) | ||
| 116 | elif taskState(prev_state) == "R": | ||
| 117 | next_tasks.append(prev) | ||
| 118 | |||
| 119 | if next not in next_tasks: | ||
| 120 | next_tasks.append(next) | ||
| 121 | |||
| 122 | return RunqueueSnapshot(next_tasks, event) | ||
| 123 | |||
| 124 | def migrate_out(self, old): | ||
| 125 | if old not in self.tasks: | ||
| 126 | return self | ||
| 127 | next_tasks = [task for task in self.tasks if task != old] | ||
| 128 | |||
| 129 | return RunqueueSnapshot(next_tasks, RunqueueMigrateOut(old)) | ||
| 130 | |||
| 131 | def __migrate_in(self, new, event): | ||
| 132 | if new in self.tasks: | ||
| 133 | self.event = event | ||
| 134 | return self | ||
| 135 | next_tasks = self.tasks[:] + tuple([new]) | ||
| 136 | |||
| 137 | return RunqueueSnapshot(next_tasks, event) | ||
| 138 | |||
| 139 | def migrate_in(self, new): | ||
| 140 | return self.__migrate_in(new, RunqueueMigrateIn(new)) | ||
| 141 | |||
| 142 | def wake_up(self, new): | ||
| 143 | return self.__migrate_in(new, RunqueueEventWakeup(new)) | ||
| 144 | |||
| 145 | def wake_up_new(self, new): | ||
| 146 | return self.__migrate_in(new, RunqueueEventFork(new)) | ||
| 147 | |||
| 148 | def load(self): | ||
| 149 | """ Provide the number of tasks on the runqueue. | ||
| 150 | Don't count idle""" | ||
| 151 | return len(self.tasks) - 1 | ||
| 152 | |||
| 153 | def __repr__(self): | ||
| 154 | ret = self.tasks.__repr__() | ||
| 155 | ret += self.origin_tostring() | ||
| 156 | |||
| 157 | return ret | ||
| 158 | |||
| 159 | class TimeSlice: | ||
| 160 | def __init__(self, start, prev): | ||
| 161 | self.start = start | ||
| 162 | self.prev = prev | ||
| 163 | self.end = start | ||
| 164 | # cpus that triggered the event | ||
| 165 | self.event_cpus = [] | ||
| 166 | if prev is not None: | ||
| 167 | self.total_load = prev.total_load | ||
| 168 | self.rqs = prev.rqs.copy() | ||
| 169 | else: | ||
| 170 | self.rqs = defaultdict(RunqueueSnapshot) | ||
| 171 | self.total_load = 0 | ||
| 172 | |||
| 173 | def __update_total_load(self, old_rq, new_rq): | ||
| 174 | diff = new_rq.load() - old_rq.load() | ||
| 175 | self.total_load += diff | ||
| 176 | |||
| 177 | def sched_switch(self, ts_list, prev, prev_state, next, cpu): | ||
| 178 | old_rq = self.prev.rqs[cpu] | ||
| 179 | new_rq = old_rq.sched_switch(prev, prev_state, next) | ||
| 180 | |||
| 181 | if old_rq is new_rq: | ||
| 182 | return | ||
| 183 | |||
| 184 | self.rqs[cpu] = new_rq | ||
| 185 | self.__update_total_load(old_rq, new_rq) | ||
| 186 | ts_list.append(self) | ||
| 187 | self.event_cpus = [cpu] | ||
| 188 | |||
| 189 | def migrate(self, ts_list, new, old_cpu, new_cpu): | ||
| 190 | if old_cpu == new_cpu: | ||
| 191 | return | ||
| 192 | old_rq = self.prev.rqs[old_cpu] | ||
| 193 | out_rq = old_rq.migrate_out(new) | ||
| 194 | self.rqs[old_cpu] = out_rq | ||
| 195 | self.__update_total_load(old_rq, out_rq) | ||
| 196 | |||
| 197 | new_rq = self.prev.rqs[new_cpu] | ||
| 198 | in_rq = new_rq.migrate_in(new) | ||
| 199 | self.rqs[new_cpu] = in_rq | ||
| 200 | self.__update_total_load(new_rq, in_rq) | ||
| 201 | |||
| 202 | ts_list.append(self) | ||
| 203 | |||
| 204 | if old_rq is not out_rq: | ||
| 205 | self.event_cpus.append(old_cpu) | ||
| 206 | self.event_cpus.append(new_cpu) | ||
| 207 | |||
| 208 | def wake_up(self, ts_list, pid, cpu, fork): | ||
| 209 | old_rq = self.prev.rqs[cpu] | ||
| 210 | if fork: | ||
| 211 | new_rq = old_rq.wake_up_new(pid) | ||
| 212 | else: | ||
| 213 | new_rq = old_rq.wake_up(pid) | ||
| 214 | |||
| 215 | if new_rq is old_rq: | ||
| 216 | return | ||
| 217 | self.rqs[cpu] = new_rq | ||
| 218 | self.__update_total_load(old_rq, new_rq) | ||
| 219 | ts_list.append(self) | ||
| 220 | self.event_cpus = [cpu] | ||
| 221 | |||
| 222 | def next(self, t): | ||
| 223 | self.end = t | ||
| 224 | return TimeSlice(t, self) | ||
| 225 | |||
| 226 | class TimeSliceList(UserList): | ||
| 227 | def __init__(self, arg = []): | ||
| 228 | self.data = arg | ||
| 229 | |||
| 230 | def get_time_slice(self, ts): | ||
| 231 | if len(self.data) == 0: | ||
| 232 | slice = TimeSlice(ts, TimeSlice(-1, None)) | ||
| 233 | else: | ||
| 234 | slice = self.data[-1].next(ts) | ||
| 235 | return slice | ||
| 236 | |||
| 237 | def find_time_slice(self, ts): | ||
| 238 | start = 0 | ||
| 239 | end = len(self.data) | ||
| 240 | found = -1 | ||
| 241 | searching = True | ||
| 242 | while searching: | ||
| 243 | if start == end or start == end - 1: | ||
| 244 | searching = False | ||
| 245 | |||
| 246 | i = (end + start) / 2 | ||
| 247 | if self.data[i].start <= ts and self.data[i].end >= ts: | ||
| 248 | found = i | ||
| 249 | end = i | ||
| 250 | continue | ||
| 251 | |||
| 252 | if self.data[i].end < ts: | ||
| 253 | start = i | ||
| 254 | |||
| 255 | elif self.data[i].start > ts: | ||
| 256 | end = i | ||
| 257 | |||
| 258 | return found | ||
| 259 | |||
| 260 | def set_root_win(self, win): | ||
| 261 | self.root_win = win | ||
| 262 | |||
| 263 | def mouse_down(self, cpu, t): | ||
| 264 | idx = self.find_time_slice(t) | ||
| 265 | if idx == -1: | ||
| 266 | return | ||
| 267 | |||
| 268 | ts = self[idx] | ||
| 269 | rq = ts.rqs[cpu] | ||
| 270 | raw = "CPU: %d\n" % cpu | ||
| 271 | raw += "Last event : %s\n" % rq.event.__repr__() | ||
| 272 | raw += "Timestamp : %d.%06d\n" % (ts.start / (10 ** 9), (ts.start % (10 ** 9)) / 1000) | ||
| 273 | raw += "Duration : %6d us\n" % ((ts.end - ts.start) / (10 ** 6)) | ||
| 274 | raw += "Load = %d\n" % rq.load() | ||
| 275 | for t in rq.tasks: | ||
| 276 | raw += "%s \n" % thread_name(t) | ||
| 277 | |||
| 278 | self.root_win.update_summary(raw) | ||
| 279 | |||
| 280 | def update_rectangle_cpu(self, slice, cpu): | ||
| 281 | rq = slice.rqs[cpu] | ||
| 282 | |||
| 283 | if slice.total_load != 0: | ||
| 284 | load_rate = rq.load() / float(slice.total_load) | ||
| 285 | else: | ||
| 286 | load_rate = 0 | ||
| 287 | |||
| 288 | red_power = int(0xff - (0xff * load_rate)) | ||
| 289 | color = (0xff, red_power, red_power) | ||
| 290 | |||
| 291 | top_color = None | ||
| 292 | |||
| 293 | if cpu in slice.event_cpus: | ||
| 294 | top_color = rq.event.color() | ||
| 295 | |||
| 296 | self.root_win.paint_rectangle_zone(cpu, color, top_color, slice.start, slice.end) | ||
| 297 | |||
| 298 | def fill_zone(self, start, end): | ||
| 299 | i = self.find_time_slice(start) | ||
| 300 | if i == -1: | ||
| 301 | return | ||
| 302 | |||
| 303 | for i in xrange(i, len(self.data)): | ||
| 304 | timeslice = self.data[i] | ||
| 305 | if timeslice.start > end: | ||
| 306 | return | ||
| 307 | |||
| 308 | for cpu in timeslice.rqs: | ||
| 309 | self.update_rectangle_cpu(timeslice, cpu) | ||
| 310 | |||
| 311 | def interval(self): | ||
| 312 | if len(self.data) == 0: | ||
| 313 | return (0, 0) | ||
| 314 | |||
| 315 | return (self.data[0].start, self.data[-1].end) | ||
| 316 | |||
| 317 | def nr_rectangles(self): | ||
| 318 | last_ts = self.data[-1] | ||
| 319 | max_cpu = 0 | ||
| 320 | for cpu in last_ts.rqs: | ||
| 321 | if cpu > max_cpu: | ||
| 322 | max_cpu = cpu | ||
| 323 | return max_cpu | ||
| 324 | |||
| 325 | |||
| 326 | class SchedEventProxy: | ||
| 327 | def __init__(self): | ||
| 328 | self.current_tsk = defaultdict(lambda : -1) | ||
| 329 | self.timeslices = TimeSliceList() | ||
| 330 | |||
| 331 | def sched_switch(self, headers, prev_comm, prev_pid, prev_prio, prev_state, | ||
| 332 | next_comm, next_pid, next_prio): | ||
| 333 | """ Ensure the task we sched out this cpu is really the one | ||
| 334 | we logged. Otherwise we may have missed traces """ | ||
| 335 | |||
| 336 | on_cpu_task = self.current_tsk[headers.cpu] | ||
| 337 | |||
| 338 | if on_cpu_task != -1 and on_cpu_task != prev_pid: | ||
| 339 | print "Sched switch event rejected ts: %s cpu: %d prev: %s(%d) next: %s(%d)" % \ | ||
| 340 | (headers.ts_format(), headers.cpu, prev_comm, prev_pid, next_comm, next_pid) | ||
| 341 | |||
| 342 | threads[prev_pid] = prev_comm | ||
| 343 | threads[next_pid] = next_comm | ||
| 344 | self.current_tsk[headers.cpu] = next_pid | ||
| 345 | |||
| 346 | ts = self.timeslices.get_time_slice(headers.ts()) | ||
| 347 | ts.sched_switch(self.timeslices, prev_pid, prev_state, next_pid, headers.cpu) | ||
| 348 | |||
| 349 | def migrate(self, headers, pid, prio, orig_cpu, dest_cpu): | ||
| 350 | ts = self.timeslices.get_time_slice(headers.ts()) | ||
| 351 | ts.migrate(self.timeslices, pid, orig_cpu, dest_cpu) | ||
| 352 | |||
| 353 | def wake_up(self, headers, comm, pid, success, target_cpu, fork): | ||
| 354 | if success == 0: | ||
| 355 | return | ||
| 356 | ts = self.timeslices.get_time_slice(headers.ts()) | ||
| 357 | ts.wake_up(self.timeslices, pid, target_cpu, fork) | ||
| 358 | |||
| 359 | |||
| 360 | def trace_begin(): | ||
| 361 | global parser | ||
| 362 | parser = SchedEventProxy() | ||
| 363 | |||
| 364 | def trace_end(): | ||
| 365 | app = wx.App(False) | ||
| 366 | timeslices = parser.timeslices | ||
| 367 | frame = RootFrame(timeslices, "Migration") | ||
| 368 | app.MainLoop() | ||
| 369 | |||
| 370 | def sched__sched_stat_runtime(event_name, context, common_cpu, | ||
| 371 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 372 | comm, pid, runtime, vruntime): | ||
| 373 | pass | ||
| 374 | |||
| 375 | def sched__sched_stat_iowait(event_name, context, common_cpu, | ||
| 376 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 377 | comm, pid, delay): | ||
| 378 | pass | ||
| 379 | |||
| 380 | def sched__sched_stat_sleep(event_name, context, common_cpu, | ||
| 381 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 382 | comm, pid, delay): | ||
| 383 | pass | ||
| 384 | |||
| 385 | def sched__sched_stat_wait(event_name, context, common_cpu, | ||
| 386 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 387 | comm, pid, delay): | ||
| 388 | pass | ||
| 389 | |||
| 390 | def sched__sched_process_fork(event_name, context, common_cpu, | ||
| 391 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 392 | parent_comm, parent_pid, child_comm, child_pid): | ||
| 393 | pass | ||
| 394 | |||
| 395 | def sched__sched_process_wait(event_name, context, common_cpu, | ||
| 396 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 397 | comm, pid, prio): | ||
| 398 | pass | ||
| 399 | |||
| 400 | def sched__sched_process_exit(event_name, context, common_cpu, | ||
| 401 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 402 | comm, pid, prio): | ||
| 403 | pass | ||
| 404 | |||
| 405 | def sched__sched_process_free(event_name, context, common_cpu, | ||
| 406 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 407 | comm, pid, prio): | ||
| 408 | pass | ||
| 409 | |||
| 410 | def sched__sched_migrate_task(event_name, context, common_cpu, | ||
| 411 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 412 | comm, pid, prio, orig_cpu, | ||
| 413 | dest_cpu): | ||
| 414 | headers = EventHeaders(common_cpu, common_secs, common_nsecs, | ||
| 415 | common_pid, common_comm) | ||
| 416 | parser.migrate(headers, pid, prio, orig_cpu, dest_cpu) | ||
| 417 | |||
| 418 | def sched__sched_switch(event_name, context, common_cpu, | ||
| 419 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 420 | prev_comm, prev_pid, prev_prio, prev_state, | ||
| 421 | next_comm, next_pid, next_prio): | ||
| 422 | |||
| 423 | headers = EventHeaders(common_cpu, common_secs, common_nsecs, | ||
| 424 | common_pid, common_comm) | ||
| 425 | parser.sched_switch(headers, prev_comm, prev_pid, prev_prio, prev_state, | ||
| 426 | next_comm, next_pid, next_prio) | ||
| 427 | |||
| 428 | def sched__sched_wakeup_new(event_name, context, common_cpu, | ||
| 429 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 430 | comm, pid, prio, success, | ||
| 431 | target_cpu): | ||
| 432 | headers = EventHeaders(common_cpu, common_secs, common_nsecs, | ||
| 433 | common_pid, common_comm) | ||
| 434 | parser.wake_up(headers, comm, pid, success, target_cpu, 1) | ||
| 435 | |||
| 436 | def sched__sched_wakeup(event_name, context, common_cpu, | ||
| 437 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 438 | comm, pid, prio, success, | ||
| 439 | target_cpu): | ||
| 440 | headers = EventHeaders(common_cpu, common_secs, common_nsecs, | ||
| 441 | common_pid, common_comm) | ||
| 442 | parser.wake_up(headers, comm, pid, success, target_cpu, 0) | ||
| 443 | |||
| 444 | def sched__sched_wait_task(event_name, context, common_cpu, | ||
| 445 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 446 | comm, pid, prio): | ||
| 447 | pass | ||
| 448 | |||
| 449 | def sched__sched_kthread_stop_ret(event_name, context, common_cpu, | ||
| 450 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 451 | ret): | ||
| 452 | pass | ||
| 453 | |||
| 454 | def sched__sched_kthread_stop(event_name, context, common_cpu, | ||
| 455 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 456 | comm, pid): | ||
| 457 | pass | ||
| 458 | |||
| 459 | def trace_unhandled(event_name, context, common_cpu, common_secs, common_nsecs, | ||
| 460 | common_pid, common_comm): | ||
| 461 | pass | ||
diff --git a/tools/perf/scripts/python/sctop.py b/tools/perf/scripts/python/sctop.py new file mode 100644 index 000000000000..6cafad40c296 --- /dev/null +++ b/tools/perf/scripts/python/sctop.py | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | # system call top | ||
| 2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
| 3 | # Licensed under the terms of the GNU GPL License version 2 | ||
| 4 | # | ||
| 5 | # Periodically displays system-wide system call totals, broken down by | ||
| 6 | # syscall. If a [comm] arg is specified, only syscalls called by | ||
| 7 | # [comm] are displayed. If an [interval] arg is specified, the display | ||
| 8 | # will be refreshed every [interval] seconds. The default interval is | ||
| 9 | # 3 seconds. | ||
| 10 | |||
| 11 | import thread | ||
| 12 | import time | ||
| 13 | import os | ||
| 14 | import sys | ||
| 15 | |||
| 16 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 17 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 18 | |||
| 19 | from perf_trace_context import * | ||
| 20 | from Core import * | ||
| 21 | from Util import * | ||
| 22 | |||
| 23 | usage = "perf trace -s syscall-counts.py [comm] [interval]\n"; | ||
| 24 | |||
| 25 | for_comm = None | ||
| 26 | default_interval = 3 | ||
| 27 | interval = default_interval | ||
| 28 | |||
| 29 | if len(sys.argv) > 3: | ||
| 30 | sys.exit(usage) | ||
| 31 | |||
| 32 | if len(sys.argv) > 2: | ||
| 33 | for_comm = sys.argv[1] | ||
| 34 | interval = int(sys.argv[2]) | ||
| 35 | elif len(sys.argv) > 1: | ||
| 36 | try: | ||
| 37 | interval = int(sys.argv[1]) | ||
| 38 | except ValueError: | ||
| 39 | for_comm = sys.argv[1] | ||
| 40 | interval = default_interval | ||
| 41 | |||
| 42 | syscalls = autodict() | ||
| 43 | |||
| 44 | def trace_begin(): | ||
| 45 | thread.start_new_thread(print_syscall_totals, (interval,)) | ||
| 46 | pass | ||
| 47 | |||
| 48 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | ||
| 49 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 50 | id, args): | ||
| 51 | if for_comm is not None: | ||
| 52 | if common_comm != for_comm: | ||
| 53 | return | ||
| 54 | try: | ||
| 55 | syscalls[id] += 1 | ||
| 56 | except TypeError: | ||
| 57 | syscalls[id] = 1 | ||
| 58 | |||
| 59 | def print_syscall_totals(interval): | ||
| 60 | while 1: | ||
| 61 | clear_term() | ||
| 62 | if for_comm is not None: | ||
| 63 | print "\nsyscall events for %s:\n\n" % (for_comm), | ||
| 64 | else: | ||
| 65 | print "\nsyscall events:\n\n", | ||
| 66 | |||
| 67 | print "%-40s %10s\n" % ("event", "count"), | ||
| 68 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
| 69 | "----------"), | ||
| 70 | |||
| 71 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | ||
| 72 | reverse = True): | ||
| 73 | try: | ||
| 74 | print "%-40d %10d\n" % (id, val), | ||
| 75 | except TypeError: | ||
| 76 | pass | ||
| 77 | syscalls.clear() | ||
| 78 | time.sleep(interval) | ||
diff --git a/tools/perf/scripts/python/syscall-counts-by-pid.py b/tools/perf/scripts/python/syscall-counts-by-pid.py new file mode 100644 index 000000000000..af722d6a4b3f --- /dev/null +++ b/tools/perf/scripts/python/syscall-counts-by-pid.py | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | # system call counts, by pid | ||
| 2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
| 3 | # Licensed under the terms of the GNU GPL License version 2 | ||
| 4 | # | ||
| 5 | # Displays system-wide system call totals, broken down by syscall. | ||
| 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. | ||
| 7 | |||
| 8 | import os | ||
| 9 | import sys | ||
| 10 | |||
| 11 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 12 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 13 | |||
| 14 | from perf_trace_context import * | ||
| 15 | from Core import * | ||
| 16 | |||
| 17 | usage = "perf trace -s syscall-counts-by-pid.py [comm]\n"; | ||
| 18 | |||
| 19 | for_comm = None | ||
| 20 | |||
| 21 | if len(sys.argv) > 2: | ||
| 22 | sys.exit(usage) | ||
| 23 | |||
| 24 | if len(sys.argv) > 1: | ||
| 25 | for_comm = sys.argv[1] | ||
| 26 | |||
| 27 | syscalls = autodict() | ||
| 28 | |||
| 29 | def trace_begin(): | ||
| 30 | pass | ||
| 31 | |||
| 32 | def trace_end(): | ||
| 33 | print_syscall_totals() | ||
| 34 | |||
| 35 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | ||
| 36 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 37 | id, args): | ||
| 38 | if for_comm is not None: | ||
| 39 | if common_comm != for_comm: | ||
| 40 | return | ||
| 41 | try: | ||
| 42 | syscalls[common_comm][common_pid][id] += 1 | ||
| 43 | except TypeError: | ||
| 44 | syscalls[common_comm][common_pid][id] = 1 | ||
| 45 | |||
| 46 | def print_syscall_totals(): | ||
| 47 | if for_comm is not None: | ||
| 48 | print "\nsyscall events for %s:\n\n" % (for_comm), | ||
| 49 | else: | ||
| 50 | print "\nsyscall events by comm/pid:\n\n", | ||
| 51 | |||
| 52 | print "%-40s %10s\n" % ("comm [pid]/syscalls", "count"), | ||
| 53 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
| 54 | "----------"), | ||
| 55 | |||
| 56 | comm_keys = syscalls.keys() | ||
| 57 | for comm in comm_keys: | ||
| 58 | pid_keys = syscalls[comm].keys() | ||
| 59 | for pid in pid_keys: | ||
| 60 | print "\n%s [%d]\n" % (comm, pid), | ||
| 61 | id_keys = syscalls[comm][pid].keys() | ||
| 62 | for id, val in sorted(syscalls[comm][pid].iteritems(), \ | ||
| 63 | key = lambda(k, v): (v, k), reverse = True): | ||
| 64 | print " %-38d %10d\n" % (id, val), | ||
diff --git a/tools/perf/scripts/python/syscall-counts.py b/tools/perf/scripts/python/syscall-counts.py new file mode 100644 index 000000000000..f977e85ff049 --- /dev/null +++ b/tools/perf/scripts/python/syscall-counts.py | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | # system call counts | ||
| 2 | # (c) 2010, Tom Zanussi <tzanussi@gmail.com> | ||
| 3 | # Licensed under the terms of the GNU GPL License version 2 | ||
| 4 | # | ||
| 5 | # Displays system-wide system call totals, broken down by syscall. | ||
| 6 | # If a [comm] arg is specified, only syscalls called by [comm] are displayed. | ||
| 7 | |||
| 8 | import os | ||
| 9 | import sys | ||
| 10 | |||
| 11 | sys.path.append(os.environ['PERF_EXEC_PATH'] + \ | ||
| 12 | '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') | ||
| 13 | |||
| 14 | from perf_trace_context import * | ||
| 15 | from Core import * | ||
| 16 | |||
| 17 | usage = "perf trace -s syscall-counts.py [comm]\n"; | ||
| 18 | |||
| 19 | for_comm = None | ||
| 20 | |||
| 21 | if len(sys.argv) > 2: | ||
| 22 | sys.exit(usage) | ||
| 23 | |||
| 24 | if len(sys.argv) > 1: | ||
| 25 | for_comm = sys.argv[1] | ||
| 26 | |||
| 27 | syscalls = autodict() | ||
| 28 | |||
| 29 | def trace_begin(): | ||
| 30 | pass | ||
| 31 | |||
| 32 | def trace_end(): | ||
| 33 | print_syscall_totals() | ||
| 34 | |||
| 35 | def raw_syscalls__sys_enter(event_name, context, common_cpu, | ||
| 36 | common_secs, common_nsecs, common_pid, common_comm, | ||
| 37 | id, args): | ||
| 38 | if for_comm is not None: | ||
| 39 | if common_comm != for_comm: | ||
| 40 | return | ||
| 41 | try: | ||
| 42 | syscalls[id] += 1 | ||
| 43 | except TypeError: | ||
| 44 | syscalls[id] = 1 | ||
| 45 | |||
| 46 | def print_syscall_totals(): | ||
| 47 | if for_comm is not None: | ||
| 48 | print "\nsyscall events for %s:\n\n" % (for_comm), | ||
| 49 | else: | ||
| 50 | print "\nsyscall events:\n\n", | ||
| 51 | |||
| 52 | print "%-40s %10s\n" % ("event", "count"), | ||
| 53 | print "%-40s %10s\n" % ("----------------------------------------", \ | ||
| 54 | "-----------"), | ||
| 55 | |||
| 56 | for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \ | ||
| 57 | reverse = True): | ||
| 58 | print "%-40d %10d\n" % (id, val), | ||
