17 from collections
import defaultdict
18 from UserList
import UserList
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')
24 from perf_trace_context
import *
26 from SchedGui
import *
29 threads = { 0 :
"idle"}
32 return "%s:%d" % (threads[pid], pid)
56 return (0xff, 0xff, 0)
78 return (0, 0xf0, 0xff)
89 return (0xff, 0, 0xff)
98 def __init__(self, tasks = [0], event = RunqueueEventUnknown()):
105 if taskState(prev_state) ==
"R" and next in self.tasks \ 106 and prev in self.tasks: 112 next_tasks = list(self.tasks[:]) 113 if prev
in self.
tasks:
115 next_tasks.remove(prev) 117 next_tasks.append(prev) 119 if next
not in next_tasks:
120 next_tasks.append(next)
125 if old
not in self.
tasks:
127 next_tasks = [task
for task
in self.
tasks if task != old]
132 if new
in self.
tasks:
135 next_tasks = self.
tasks[:] + tuple([new])
149 """ Provide the number of tasks on the runqueue. 151 return len(self.
tasks) - 1
155 ret += self.origin_tostring()
168 self.
rqs = prev.rqs.copy()
170 self.
rqs = defaultdict(RunqueueSnapshot)
174 diff = new_rq.load() - old_rq.load()
178 old_rq = self.
prev.rqs[cpu]
179 new_rq = old_rq.sched_switch(prev, prev_state, next)
184 self.
rqs[cpu] = new_rq
189 def migrate(self, ts_list, new, old_cpu, new_cpu):
190 if old_cpu == new_cpu:
192 old_rq = self.
prev.rqs[old_cpu]
193 out_rq = old_rq.migrate_out(new)
194 self.
rqs[old_cpu] = out_rq
197 new_rq = self.
prev.rqs[new_cpu]
198 in_rq = new_rq.migrate_in(new)
199 self.
rqs[new_cpu] = in_rq
204 if old_rq
is not out_rq:
209 old_rq = self.
prev.rqs[cpu]
211 new_rq = old_rq.wake_up_new(pid)
213 new_rq = old_rq.wake_up(pid)
217 self.
rqs[cpu] = new_rq
231 if len(self.
data) == 0:
234 slice = self.
data[-1].next(ts)
243 if start == end
or start == end - 1:
246 i = (end + start) / 2
247 if self.
data[i].start <= ts
and self.
data[i].end >= ts:
252 if self.
data[i].end < ts:
255 elif self.
data[i].start > ts:
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()
283 if slice.total_load != 0:
284 load_rate = rq.load() / float(slice.total_load)
288 red_power = int(0xff - (0xff * load_rate))
289 color = (0xff, red_power, red_power)
293 if cpu
in slice.event_cpus:
294 top_color = rq.event.color()
296 self.
root_win.paint_rectangle_zone(cpu, color, top_color, slice.start, slice.end)
303 for i
in xrange(i, len(self.
data)):
304 timeslice = self.
data[i]
305 if timeslice.start > end:
308 for cpu
in timeslice.rqs:
312 if len(self.
data) == 0:
315 return (self.
data[0].start, self.
data[-1].end)
318 last_ts = self.
data[-1]
320 for cpu
in last_ts.rqs:
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 """ 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)
342 threads[prev_pid] = prev_comm
343 threads[next_pid] = next_comm
346 ts = self.
timeslices.get_time_slice(headers.ts())
347 ts.sched_switch(self.
timeslices, prev_pid, prev_state, next_pid, headers.cpu)
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)
353 def wake_up(self, headers, comm, pid, success, target_cpu, fork):
356 ts = self.
timeslices.get_time_slice(headers.ts())
357 ts.wake_up(self.
timeslices, pid, target_cpu, fork)
366 timeslices = parser.timeslices
367 frame =
RootFrame(timeslices,
"Migration")
371 common_secs, common_nsecs, common_pid, common_comm,
372 common_callchain, comm, pid, runtime, vruntime):
376 common_secs, common_nsecs, common_pid, common_comm,
377 common_callchain, comm, pid, delay):
381 common_secs, common_nsecs, common_pid, common_comm,
382 common_callchain, comm, pid, delay):
386 common_secs, common_nsecs, common_pid, common_comm,
387 common_callchain, comm, pid, delay):
391 common_secs, common_nsecs, common_pid, common_comm,
392 common_callchain, parent_comm, parent_pid, child_comm, child_pid):
396 common_secs, common_nsecs, common_pid, common_comm,
397 common_callchain, comm, pid, prio):
401 common_secs, common_nsecs, common_pid, common_comm,
402 common_callchain, comm, pid, prio):
406 common_secs, common_nsecs, common_pid, common_comm,
407 common_callchain, comm, pid, prio):
411 common_secs, common_nsecs, common_pid, common_comm,
412 common_callchain, comm, pid, prio, orig_cpu,
414 headers =
EventHeaders(common_cpu, common_secs, common_nsecs,
415 common_pid, common_comm, common_callchain)
416 parser.migrate(headers, pid, prio, orig_cpu, dest_cpu)
419 common_secs, common_nsecs, common_pid, common_comm, common_callchain,
420 prev_comm, prev_pid, prev_prio, prev_state,
421 next_comm, next_pid, next_prio):
423 headers =
EventHeaders(common_cpu, common_secs, common_nsecs,
424 common_pid, common_comm, common_callchain)
425 parser.sched_switch(headers, prev_comm, prev_pid, prev_prio, prev_state,
426 next_comm, next_pid, next_prio)
429 common_secs, common_nsecs, common_pid, common_comm,
430 common_callchain, comm, pid, prio, success,
432 headers =
EventHeaders(common_cpu, common_secs, common_nsecs,
433 common_pid, common_comm, common_callchain)
434 parser.wake_up(headers, comm, pid, success, target_cpu, 1)
437 common_secs, common_nsecs, common_pid, common_comm,
438 common_callchain, comm, pid, prio, success,
440 headers =
EventHeaders(common_cpu, common_secs, common_nsecs,
441 common_pid, common_comm, common_callchain)
442 parser.wake_up(headers, comm, pid, success, target_cpu, 0)
445 common_secs, common_nsecs, common_pid, common_comm,
446 common_callchain, comm, pid, prio):
450 common_secs, common_nsecs, common_pid, common_comm,
451 common_callchain, ret):
455 common_secs, common_nsecs, common_pid, common_comm,
456 common_callchain, comm, pid):
def sched__sched_stat_iowait(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, delay)
def set_root_win(self, win)
def get_time_slice(self, ts)
def __init__(self, start, prev)
def sched__sched_stat_sleep(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, delay)
def sched_switch(self, headers, prev_comm, prev_pid, prev_prio, prev_state, next_comm, next_pid, next_prio)
def wake_up_new(self, new)
def migrate_out(self, old)
def __init__(self, child)
def wake_up(self, headers, comm, pid, success, target_cpu, fork)
def sched__sched_wakeup(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio, success, target_cpu)
def sched__sched_process_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio)
def wake_up(self, ts_list, pid, cpu, fork)
def sched__sched_stat_wait(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, delay)
def __init__(self, tasks=[0], event=RunqueueEventUnknown())
def update_rectangle_cpu(self, slice, cpu)
def __init__(self, sleeper)
def sched__sched_process_free(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio)
def migrate_in(self, new)
def __init__(self, arg=[])
def mouse_down(self, cpu, t)
def migrate(self, headers, pid, prio, orig_cpu, dest_cpu)
def sched_switch(self, ts_list, prev, prev_state, next, cpu)
def sched__sched_wakeup_new(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio, success, target_cpu)
def trace_unhandled(event_name, context, event_fields_dict)
def fill_zone(self, start, end)
def sched__sched_wait_task(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio)
def __update_total_load(self, old_rq, new_rq)
def __migrate_in(self, new, event)
def sched__sched_process_fork(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, parent_comm, parent_pid, child_comm, child_pid)
def sched__sched_process_wait(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio)
def sched__sched_switch(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, prev_comm, prev_pid, prev_prio, prev_state, next_comm, next_pid, next_prio)
def sched__sched_stat_runtime(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, runtime, vruntime)
def sched__sched_kthread_stop(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid)
def find_time_slice(self, ts)
def migrate(self, ts_list, new, old_cpu, new_cpu)
def sched_switch(self, prev, prev_state, next)
def sched__sched_kthread_stop_ret(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, ret)
def __init__(self, wakee)
def sched__sched_migrate_task(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, comm, pid, prio, orig_cpu, dest_cpu)