aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/scripts/python
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/scripts/python')
-rw-r--r--tools/perf/scripts/python/bin/sched-migration-record2
-rw-r--r--tools/perf/scripts/python/bin/sched-migration-report3
-rw-r--r--tools/perf/scripts/python/sched-migration.py634
3 files changed, 639 insertions, 0 deletions
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
2perf 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
3perf trace $@ -s ~/libexec/perf-core/scripts/python/sched-migration.py
diff --git a/tools/perf/scripts/python/sched-migration.py b/tools/perf/scripts/python/sched-migration.py
new file mode 100644
index 000000000000..f73e1c736a34
--- /dev/null
+++ b/tools/perf/scripts/python/sched-migration.py
@@ -0,0 +1,634 @@
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# The whole is licensed under the terms of the GNU GPL License version 2
10
11
12try:
13 import wx
14except ImportError:
15 raise ImportError, "You need to install the wxpython lib for this script"
16
17import os
18import sys
19
20from collections import defaultdict
21from UserList import UserList
22
23sys.path.append(os.environ['PERF_EXEC_PATH'] + \
24 '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
25
26from perf_trace_context import *
27from Core import *
28
29class RootFrame(wx.Frame):
30 def __init__(self, timeslices, parent = None, id = -1, title = "Migration"):
31 wx.Frame.__init__(self, parent, id, title)
32
33 (self.screen_width, self.screen_height) = wx.GetDisplaySize()
34 self.screen_width -= 10
35 self.screen_height -= 10
36 self.zoom = 0.5
37 self.scroll_scale = 20
38 self.timeslices = timeslices
39 (self.ts_start, self.ts_end) = timeslices.interval()
40 self.update_width_virtual()
41
42 # whole window panel
43 self.panel = wx.Panel(self, size=(self.screen_width, self.screen_height))
44
45 # scrollable container
46 self.scroll = wx.ScrolledWindow(self.panel)
47 self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, 100 / 10)
48 self.scroll.EnableScrolling(True, True)
49 self.scroll.SetFocus()
50
51 # scrollable drawing area
52 self.scroll_panel = wx.Panel(self.scroll, size=(self.screen_width, self.screen_height / 2))
53 self.scroll_panel.Bind(wx.EVT_PAINT, self.on_paint)
54 self.scroll_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press)
55 self.scroll_panel.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down)
56 self.scroll.Bind(wx.EVT_PAINT, self.on_paint)
57
58 self.scroll.Fit()
59 self.Fit()
60
61 self.scroll_panel.SetDimensions(-1, -1, self.width_virtual, -1, wx.SIZE_USE_EXISTING)
62
63 self.max_cpu = -1
64 self.txt = None
65
66 self.Show(True)
67
68 def us_to_px(self, val):
69 return val / (10 ** 3) * self.zoom
70
71 def px_to_us(self, val):
72 return (val / self.zoom) * (10 ** 3)
73
74 def scroll_start(self):
75 (x, y) = self.scroll.GetViewStart()
76 return (x * self.scroll_scale, y * self.scroll_scale)
77
78 def scroll_start_us(self):
79 (x, y) = self.scroll_start()
80 return self.px_to_us(x)
81
82 def update_rectangle_cpu(self, dc, slice, cpu, offset_time):
83 rq = slice.rqs[cpu]
84
85 if slice.total_load != 0:
86 load_rate = rq.load() / float(slice.total_load)
87 else:
88 load_rate = 0
89
90
91 offset_px = self.us_to_px(slice.start - offset_time)
92 width_px = self.us_to_px(slice.end - slice.start)
93 (x, y) = self.scroll_start()
94
95 if width_px == 0:
96 return
97
98 offset_py = 100 + (cpu * 150)
99 width_py = 100
100
101 if cpu in slice.event_cpus:
102 rgb = rq.event.color()
103 if rgb is not None:
104 (r, g, b) = rgb
105 color = wx.Colour(r, g, b)
106 brush = wx.Brush(color, wx.SOLID)
107 dc.SetBrush(brush)
108 dc.DrawRectangle(offset_px, offset_py, width_px, 5)
109 width_py -= 5
110 offset_py += 5
111
112 red_power = int(0xff - (0xff * load_rate))
113 color = wx.Colour(0xff, red_power, red_power)
114 brush = wx.Brush(color, wx.SOLID)
115 dc.SetBrush(brush)
116 dc.DrawRectangle(offset_px, offset_py, width_px, width_py)
117
118 def update_rectangles(self, dc, start, end):
119 if len(self.timeslices) == 0:
120 return
121 start += self.timeslices[0].start
122 end += self.timeslices[0].start
123
124 color = wx.Colour(0, 0, 0)
125 brush = wx.Brush(color, wx.SOLID)
126 dc.SetBrush(brush)
127
128 i = self.timeslices.find_time_slice(start)
129 if i == -1:
130 return
131
132 for i in xrange(i, len(self.timeslices)):
133 timeslice = self.timeslices[i]
134 if timeslice.start > end:
135 return
136
137 for cpu in timeslice.rqs:
138 self.update_rectangle_cpu(dc, timeslice, cpu, self.timeslices[0].start)
139 if cpu > self.max_cpu:
140 self.max_cpu = cpu
141
142 def on_paint(self, event):
143 color = wx.Colour(0xff, 0xff, 0xff)
144 brush = wx.Brush(color, wx.SOLID)
145 dc = wx.PaintDC(self.scroll_panel)
146 dc.SetBrush(brush)
147
148 width = min(self.width_virtual, self.screen_width)
149 (x, y) = self.scroll_start()
150 start = self.px_to_us(x)
151 end = self.px_to_us(x + width)
152 self.update_rectangles(dc, start, end)
153
154 def cpu_from_ypixel(self, y):
155 y -= 100
156 cpu = y / 150
157 height = y % 150
158
159 if cpu < 0 or cpu > self.max_cpu or height > 100:
160 return -1
161
162 return cpu
163
164 def update_summary(self, cpu, t):
165 idx = self.timeslices.find_time_slice(t)
166 if idx == -1:
167 return
168
169 ts = self.timeslices[idx]
170 rq = ts.rqs[cpu]
171 raw = "CPU: %d\n" % cpu
172 raw += "Last event : %s\n" % rq.event.__repr__()
173 raw += "Timestamp : %d.%06d\n" % (ts.start / (10 ** 9), (ts.start % (10 ** 9)) / 1000)
174 raw += "Duration : %6d us\n" % ((ts.end - ts.start) / (10 ** 6))
175 raw += "Load = %d\n" % rq.load()
176 for t in rq.tasks:
177 raw += "%s \n" % thread_name(t)
178
179 if self.txt:
180 self.txt.Destroy()
181 self.txt = wx.StaticText(self.panel, -1, raw, (0, (self.screen_height / 2) + 50))
182
183
184 def on_mouse_down(self, event):
185 (x, y) = event.GetPositionTuple()
186 cpu = self.cpu_from_ypixel(y)
187 if cpu == -1:
188 return