From e6dbe1605d8ae52ee65a08e929ed1810bd07d45c Mon Sep 17 00:00:00 2001 From: Gary Bressler Date: Mon, 15 Mar 2010 14:27:24 -0400 Subject: Some fix-ups to viz, including with the scrolling --- unit_trace/viz/schedule.py | 94 ++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 71 deletions(-) (limited to 'unit_trace/viz/schedule.py') diff --git a/unit_trace/viz/schedule.py b/unit_trace/viz/schedule.py index ae7284b..ce062a3 100644 --- a/unit_trace/viz/schedule.py +++ b/unit_trace/viz/schedule.py @@ -21,13 +21,11 @@ class TimeSlotArray(object): TASK_LIST = 0 CPU_LIST = 1 - def __init__(self, start=None, end=None, time_per_maj=1, num_tasks=0, num_cpus=0): - if start is None or end is None: + def __init__(self, time_per_maj=None, num_tasks=0, num_cpus=0): + if time_per_maj is None: self.array = None return - self.start = start - self.end = end self.time_per_maj = time_per_maj self.list_sizes = { TimeSlotArray.TASK_LIST : num_tasks, TimeSlotArray.CPU_LIST : num_cpus } self.array = {} @@ -39,12 +37,11 @@ class TimeSlotArray(object): # for each slot in the array, we need a list of all events under this type # (for example, a list of all events that occur in this time slot, indexed # by task). - for i in range(0, num): - self.array[type].append(dict(zip(EVENT_LIST, \ - [{} for j in range(0, len(EVENT_LIST))]))) + self.array[type].append(dict(zip(EVENT_LIST, \ + [{} for j in range(0, len(EVENT_LIST))]))) def get_time_slot(self, time): - return int((time - self.start) // self.time_per_maj) + return int(time // self.time_per_maj) def _put_event_in_slot(self, list_type, no, klass, slot, event): if slot not in self.array[list_type][no][klass]: @@ -122,77 +119,26 @@ class Schedule(object): def get_selected(self): return copy.copy(self.selected) - def set_time_params(self, time_per_maj=None, max_num_slots=None): - def find_extreme_time_sched(sched, cmp): - def find_extreme_time_task(task, cmp): - def find_extreme_time_job(job, cmp): - extreme_time = None - for time in job.get_events(): - if (extreme_time is None) or cmp(time, extreme_time) < 0: - extreme_time = time - return extreme_time - - extreme_time = None - for job_no in task.get_jobs(): - time = find_extreme_time_job(task.get_jobs()[job_no], cmp) - if (time is not None) and ((extreme_time is None) or cmp(time, extreme_time) < 0): - extreme_time = time - return extreme_time - - extreme_time = None - for task in sched.get_task_list(): - time = find_extreme_time_task(task, cmp) - if (time is not None) and ((extreme_time is None) or cmp(time, extreme_time) < 0): - extreme_time = time - - return extreme_time - - def earliest_cmp(x, y): - diff = x - y - if diff > 0.0: - return 1 - elif diff == 0.0: - return 0 - elif diff < 0.0: - return -1 - - def latest_cmp(x, y): - diff = x - y - if diff < 0.0: - return 1 - elif diff == 0.0: - return 0 - elif diff > 0.0: - return -1 - - self.start = find_extreme_time_sched(self, earliest_cmp) - self.end = find_extreme_time_sched(self, latest_cmp) - if self.start is None or self.end is None: + def set_time_params(self, time_per_maj=None): + self.time_per_maj = time_per_maj + if self.time_per_maj is None: self.time_slot_array = TimeSlotArray() return - min_time_per_maj = (self.end - self.start) * 1.0 / max_num_slots - if max_num_slots is not None and time_per_maj is not None: - if time_per_maj < min_time_per_maj: - self.time_per_maj = min_time_per_maj - else: - self.time_per_maj = time_per_maj - else: - self.time_per_maj = time_per_maj - self.time_slot_array = None - if self.time_per_maj is not None: - self.time_slot_array = TimeSlotArray(self.start, self.end, self.time_per_maj, \ + self.time_slot_array = TimeSlotArray(self.time_per_maj, \ len(self.task_list), self.num_cpus) - def get_time_slot_array(self): return self.time_slot_array def get_time_bounds(self): return (self.start, self.end) - def scan(self, time_per_maj, max_num_slots): - self.set_time_params(time_per_maj, max_num_slots) + def scan(self, time_per_maj): + self.start = None + self.end = None + + self.set_time_params(time_per_maj) # we scan the graph task by task, and job by job switches = {} @@ -205,7 +151,7 @@ class Schedule(object): for event_time in sorted(job.get_events().keys()): # could have multiple events at the same time (unlikely but possible) for event in job.get_events()[event_time]: - print "task, job, event:", task.name, job.job_no, event.__class__.__name__ + print 'task, job, event:', task.name, job.job_no, event.__class__.__name__ event.scan(cur_cpu, switches) def add_task(self, task): @@ -358,8 +304,14 @@ class Event(DummyEvent): by scanning through the events. ``cur_cpu'' gives the current CPU at this time in the scan, and ``switches'' gives the last time a certain switch (e.g. SwitchToEvent, InversionStartEvent) occurred""" - - self.get_job().get_task().get_schedule().get_time_slot_array().add_event_to_time_slot(self) + time = self.get_time() + sched = self.get_job().get_task().get_schedule() + if sched.start is None or time < sched.start: + sched.start = time + if sched.end is None or time > sched.end: + sched.end = time + + sched.get_time_slot_array().add_event_to_time_slot(self) class ErrorEvent(Event): pass -- cgit v1.2.2