diff options
Diffstat (limited to 'viz/schedule.py')
-rw-r--r-- | viz/schedule.py | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/viz/schedule.py b/viz/schedule.py index e525b17..ae7284b 100644 --- a/viz/schedule.py +++ b/viz/schedule.py | |||
@@ -35,25 +35,29 @@ class TimeSlotArray(object): | |||
35 | for type in self.list_sizes: | 35 | for type in self.list_sizes: |
36 | num = self.list_sizes[type] | 36 | num = self.list_sizes[type] |
37 | self.array[type] = [] | 37 | self.array[type] = [] |
38 | for i in range(0, int((end - start) // self.time_per_maj + 1)): | 38 | for j in range(0, num): |
39 | # for each slot in the array, we need a list of all events under this type | 39 | # 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 | 40 | # (for example, a list of all events that occur in this time slot, indexed |
41 | # by task). | 41 | # by task). |
42 | self.array[type].append([]) | 42 | for i in range(0, num): |
43 | for j in range(0, num): | 43 | self.array[type].append(dict(zip(EVENT_LIST, \ |
44 | self.array[type][i].append(dict(zip(EVENT_LIST, \ | 44 | [{} for j in range(0, len(EVENT_LIST))]))) |
45 | [[] for j in range(0, len(EVENT_LIST))]))) | ||
46 | 45 | ||
47 | def get_time_slot(self, time): | 46 | def get_time_slot(self, time): |
48 | return int((time - self.start) // self.time_per_maj) | 47 | return int((time - self.start) // self.time_per_maj) |
49 | 48 | ||
49 | def _put_event_in_slot(self, list_type, no, klass, slot, event): | ||
50 | if slot not in self.array[list_type][no][klass]: | ||
51 | self.array[list_type][no][klass][slot] = [] | ||
52 | self.array[list_type][no][klass][slot].append(event) | ||
53 | |||
50 | def add_event_to_time_slot(self, event): | 54 | def add_event_to_time_slot(self, event): |
51 | task_no = event.get_job().get_task().get_task_no() | 55 | task_no = event.get_job().get_task().get_task_no() |
52 | cpu = event.get_cpu() | 56 | cpu = event.get_cpu() |
53 | time_slot = self.get_time_slot(event.get_time()) | 57 | time_slot = self.get_time_slot(event.get_time()) |
54 | 58 | ||
55 | self.array[TimeSlotArray.TASK_LIST][time_slot][task_no][event.__class__].append(event) | 59 | self._put_event_in_slot(TimeSlotArray.TASK_LIST, task_no, event.__class__, time_slot, event) |
56 | self.array[TimeSlotArray.CPU_LIST][time_slot][cpu][event.__class__].append(event) | 60 | self._put_event_in_slot(TimeSlotArray.CPU_LIST, cpu, event.__class__, time_slot, event) |
57 | 61 | ||
58 | span_events = { SwitchAwayEvent : IsRunningDummy, InversionEndEvent : InversionDummy} | 62 | span_events = { SwitchAwayEvent : IsRunningDummy, InversionEndEvent : InversionDummy} |
59 | 63 | ||
@@ -64,8 +68,9 @@ class TimeSlotArray(object): | |||
64 | for slot in range(start_slot + 1, end_slot): | 68 | for slot in range(start_slot + 1, end_slot): |
65 | dummy = span_events[span_event](task_no, cpu) | 69 | dummy = span_events[span_event](task_no, cpu) |
66 | dummy.corresp_start_event = event.corresp_start_event | 70 | dummy.corresp_start_event = event.corresp_start_event |
67 | self.array[TimeSlotArray.TASK_LIST][slot][task_no][dummy.__class__].append(dummy) | 71 | |
68 | self.array[TimeSlotArray.CPU_LIST][slot][cpu][dummy.__class__].append(dummy) | 72 | self._put_event_in_slot(TimeSlotArray.TASK_LIST, task_no, dummy.__class__, slot, dummy) |
73 | self._put_event_in_slot(TimeSlotArray.CPU_LIST, cpu, dummy.__class__, slot, dummy) | ||
69 | 74 | ||
70 | def iter_over_period(self, start, end, start_no, end_no, list_type, event_types): | 75 | def iter_over_period(self, start, end, start_no, end_no, list_type, event_types): |
71 | if self.array is None: | 76 | if self.array is None: |
@@ -76,17 +81,18 @@ class TimeSlotArray(object): | |||
76 | if start_no > end_no: | 81 | if start_no > end_no: |
77 | raise ValueError('start no should be less than end no') | 82 | raise ValueError('start no should be less than end no') |
78 | 83 | ||
79 | start_slot = max(0, self.get_time_slot(start)) | 84 | start_slot = self.get_time_slot(start) |
80 | end_slot = min(len(self.array[list_type]), self.get_time_slot(end) + 2) | 85 | end_slot = self.get_time_slot(end) + 2 |
81 | 86 | ||
82 | start_no = max(0, start_no) | 87 | start_no = max(0, start_no) |
83 | end_no = min(self.list_sizes[list_type] - 1, end_no) | 88 | end_no = min(self.list_sizes[list_type] - 1, end_no) |
84 | 89 | ||
85 | for slot in range(start_slot, end_slot): | 90 | for no in range(start_no, end_no + 1): |
86 | for no in range(start_no, end_no + 1): | 91 | for type in event_types: |
87 | for type in event_types: | 92 | for slot in range(start_slot, end_slot): |
88 | for event in self.array[list_type][slot][no][type]: | 93 | if slot in self.array[list_type][no][type]: |
89 | yield event | 94 | for event in self.array[list_type][no][type][slot]: |
95 | yield event | ||
90 | 96 | ||
91 | class Schedule(object): | 97 | class Schedule(object): |
92 | """The total schedule (task system), consisting of a certain number of | 98 | """The total schedule (task system), consisting of a certain number of |