diff options
| author | Gary Bressler <garybressler@nc.rr.com> | 2010-03-15 14:27:24 -0400 |
|---|---|---|
| committer | Gary Bressler <garybressler@nc.rr.com> | 2010-03-15 14:27:24 -0400 |
| commit | e6dbe1605d8ae52ee65a08e929ed1810bd07d45c (patch) | |
| tree | 82e81bd86f5760137e9c6079b50c89b4615f1d6e /unit_trace/viz/schedule.py | |
| parent | 9f0f4526b7cc6829f371b6e4bafb874ef0caa56a (diff) | |
Some fix-ups to viz, including with the scrolling
Diffstat (limited to 'unit_trace/viz/schedule.py')
| -rw-r--r-- | unit_trace/viz/schedule.py | 94 |
1 files changed, 23 insertions, 71 deletions
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): | |||
| 21 | TASK_LIST = 0 | 21 | TASK_LIST = 0 |
| 22 | CPU_LIST = 1 | 22 | CPU_LIST = 1 |
| 23 | 23 | ||
| 24 | def __init__(self, start=None, end=None, time_per_maj=1, num_tasks=0, num_cpus=0): | 24 | def __init__(self, time_per_maj=None, num_tasks=0, num_cpus=0): |
| 25 | if start is None or end is None: | 25 | if time_per_maj is None: |
| 26 | self.array = None | 26 | self.array = None |
| 27 | return | 27 | return |
| 28 | 28 | ||
| 29 | self.start = start | ||
| 30 | self.end = end | ||
| 31 | self.time_per_maj = time_per_maj | 29 | self.time_per_maj = time_per_maj |
| 32 | self.list_sizes = { TimeSlotArray.TASK_LIST : num_tasks, TimeSlotArray.CPU_LIST : num_cpus } | 30 | self.list_sizes = { TimeSlotArray.TASK_LIST : num_tasks, TimeSlotArray.CPU_LIST : num_cpus } |
| 33 | self.array = {} | 31 | self.array = {} |
| @@ -39,12 +37,11 @@ class TimeSlotArray(object): | |||
| 39 | # for each slot in the array, we need a list of all events under this type | 37 | # for each slot in the array, we need a list of all events under this type |
| 40 | # (for example, a list of all events that occur in this time slot, indexed | 38 | # (for example, a list of all events that occur in this time slot, indexed |
| 41 | # by task). | 39 | # by task). |
| 42 | for i in range(0, num): | 40 | self.array[type].append(dict(zip(EVENT_LIST, \ |
| 43 | self.array[type].append(dict(zip(EVENT_LIST, \ | 41 | [{} for j in range(0, len(EVENT_LIST))]))) |
| 44 | [{} for j in range(0, len(EVENT_LIST))]))) | ||
| 45 | 42 | ||
| 46 | def get_time_slot(self, time): | 43 | def get_time_slot(self, time): |
| 47 | return int((time - self.start) // self.time_per_maj) | 44 | return int(time // self.time_per_maj) |
| 48 | 45 | ||
| 49 | def _put_event_in_slot(self, list_type, no, klass, slot, event): | 46 | def _put_event_in_slot(self, list_type, no, klass, slot, event): |
| 50 | if slot not in self.array[list_type][no][klass]: | 47 | if slot not in self.array[list_type][no][klass]: |
| @@ -122,77 +119,26 @@ class Schedule(object): | |||
| 122 | def get_selected(self): | 119 | def get_selected(self): |
| 123 | return copy.copy(self.selected) | 120 | return copy.copy(self.selected) |
| 124 | 121 | ||
| 125 | def set_time_params(self, time_per_maj=None, max_num_slots=None): | 122 | def set_time_params(self, time_per_maj=None): |
| 126 | def find_extreme_time_sched(sched, cmp): | 123 | self.time_per_maj = time_per_maj |
| 127 | def find_extreme_time_task(task, cmp): | 124 | if self.time_per_maj is None: |
| 128 | def find_extreme_time_job(job, cmp): | ||
| 129 | extreme_time = None | ||
| 130 | for time in job.get_events(): | ||
| 131 | if (extreme_time is None) or cmp(time, extreme_time) < 0: | ||
| 132 | extreme_time = time | ||
| 133 | return extreme_time | ||
| 134 | |||
| 135 | extreme_time = None | ||
| 136 | for job_no in task.get_jobs(): | ||
| 137 | time = find_extreme_time_job(task.get_jobs()[job_no], cmp) | ||
| 138 | if (time is not None) and ((extreme_time is None) or cmp(time, extreme_time) < 0): | ||
| 139 | extreme_time = time | ||
| 140 | return extreme_time | ||
| 141 | |||
| 142 | extreme_time = None | ||
| 143 | for task in sched.get_task_list(): | ||
| 144 | time = find_extreme_time_task(task, cmp) | ||
| 145 | if (time is not None) and ((extreme_time is None) or cmp(time, extreme_time) < 0): | ||
| 146 | extreme_time = time | ||
| 147 | |||
| 148 | return extreme_time | ||
| 149 | |||
| 150 | def earliest_cmp(x, y): | ||
| 151 | diff = x - y | ||
| 152 | if diff > 0.0: | ||
| 153 | return 1 | ||
| 154 | elif diff == 0.0: | ||
| 155 | return 0 | ||
| 156 | elif diff < 0.0: | ||
| 157 | return -1 | ||
| 158 | |||
| 159 | def latest_cmp(x, y): | ||
| 160 | diff = x - y | ||
| 161 | if diff < 0.0: | ||
| 162 | return 1 | ||
| 163 | elif diff == 0.0: | ||
| 164 | return 0 | ||
| 165 | elif diff > 0.0: | ||
| 166 | return -1 | ||
| 167 | |||
| 168 | self.start = find_extreme_time_sched(self, earliest_cmp) | ||
| 169 | self.end = find_extreme_time_sched(self, latest_cmp) | ||
| 170 | if self.start is None or self.end is None: | ||
| 171 | self.time_slot_array = TimeSlotArray() | 125 | self.time_slot_array = TimeSlotArray() |
| 172 | return | 126 | return |
| 173 | 127 | ||
| 174 | min_time_per_maj = (self.end - self.start) * 1.0 / max_num_slots | 128 | self.time_slot_array = TimeSlotArray(self.time_per_maj, \ |
| 175 | if max_num_slots is not None and time_per_maj is not None: | ||
| 176 | if time_per_maj < min_time_per_maj: | ||
| 177 | self.time_per_maj = min_time_per_maj | ||
| 178 | else: | ||
| 179 | self.time_per_maj = time_per_maj | ||
| 180 | else: | ||
| 181 | self.time_per_maj = time_per_maj | ||
| 182 | self.time_slot_array = None | ||
| 183 | if self.time_per_maj is not None: | ||
| 184 | self.time_slot_array = TimeSlotArray(self.start, self.end, self.time_per_maj, \ | ||
| 185 | len(self.task_list), self.num_cpus) | 129 | len(self.task_list), self.num_cpus) |
| 186 | 130 | ||
| 187 | |||
| 188 | def get_time_slot_array(self): | 131 | def get_time_slot_array(self): |
| 189 | return self.time_slot_array | 132 | return self.time_slot_array |
| 190 | 133 | ||
| 191 | def get_time_bounds(self): | 134 | def get_time_bounds(self): |
| 192 | return (self.start, self.end) | 135 | return (self.start, self.end) |
| 193 | 136 | ||
| 194 | def scan(self, time_per_maj, max_num_slots): | 137 | def scan(self, time_per_maj): |
| 195 | self.set_time_params(time_per_maj, max_num_slots) | 138 | self.start = None |
| 139 | self.end = None | ||
| 140 | |||
| 141 | self.set_time_params(time_per_maj) | ||
| 196 | 142 | ||
| 197 | # we scan the graph task by task, and job by job | 143 | # we scan the graph task by task, and job by job |
| 198 | switches = {} | 144 | switches = {} |
| @@ -205,7 +151,7 @@ class Schedule(object): | |||
| 205 | for event_time in sorted(job.get_events().keys()): | 151 | for event_time in sorted(job.get_events().keys()): |
| 206 | # could have multiple events at the same time (unlikely but possible) | 152 | # could have multiple events at the same time (unlikely but possible) |
| 207 | for event in job.get_events()[event_time]: | 153 | for event in job.get_events()[event_time]: |
| 208 | print "task, job, event:", task.name, job.job_no, event.__class__.__name__ | 154 | print 'task, job, event:', task.name, job.job_no, event.__class__.__name__ |
| 209 | event.scan(cur_cpu, switches) | 155 | event.scan(cur_cpu, switches) |
| 210 | 156 | ||
| 211 | def add_task(self, task): | 157 | def add_task(self, task): |
| @@ -358,8 +304,14 @@ class Event(DummyEvent): | |||
| 358 | by scanning through the events. ``cur_cpu'' gives the current CPU at this | 304 | by scanning through the events. ``cur_cpu'' gives the current CPU at this |
| 359 | time in the scan, and ``switches'' gives the last time a certain switch | 305 | time in the scan, and ``switches'' gives the last time a certain switch |
| 360 | (e.g. SwitchToEvent, InversionStartEvent) occurred""" | 306 | (e.g. SwitchToEvent, InversionStartEvent) occurred""" |
| 361 | 307 | time = self.get_time() | |
| 362 | self.get_job().get_task().get_schedule().get_time_slot_array().add_event_to_time_slot(self) | 308 | sched = self.get_job().get_task().get_schedule() |
| 309 | if sched.start is None or time < sched.start: | ||
| 310 | sched.start = time | ||
| 311 | if sched.end is None or time > sched.end: | ||
| 312 | sched.end = time | ||
| 313 | |||
| 314 | sched.get_time_slot_array().add_event_to_time_slot(self) | ||
| 363 | 315 | ||
| 364 | class ErrorEvent(Event): | 316 | class ErrorEvent(Event): |
| 365 | pass | 317 | pass |
