From c7e3aaebdba7bf880534abd91a383b5543cf0be4 Mon Sep 17 00:00:00 2001 From: Gary Bressler Date: Tue, 6 Apr 2010 12:45:04 -0400 Subject: Making sure everything committed --- unit_trace/viz/schedule.py | 74 ++++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 26 deletions(-) (limited to 'unit_trace/viz/schedule.py') diff --git a/unit_trace/viz/schedule.py b/unit_trace/viz/schedule.py index f134562..81269fa 100644 --- a/unit_trace/viz/schedule.py +++ b/unit_trace/viz/schedule.py @@ -5,7 +5,7 @@ the job releases and other events that have occurred for each task. This gives a high-level representation of a schedule that can be converted to, say, a graphic.""" -from draw import * +from graph import * import util import copy @@ -97,8 +97,16 @@ class TimeSlotArray(object): self._put_event_in_slot(TimeSlotArray.TASK_LIST, task_no, dummy.__class__, slot, dummy) self._put_event_in_slot(TimeSlotArray.CPU_LIST, cpu, dummy.__class__, slot, dummy) - - def iter_over_period(self, start, end, start_no, end_no, list_type, event_types): + + def get_events(self, slots, list_type, event_types): + for type in event_types: + for slot in slots: + for no in slots[slot]: + if slot in self.array[list_type][no][type]: + for event in self.array[list_type][no][type][slot]: + yield event + + def get_slots(self, slots, start, end, start_no, end_no, list_type): if self.array is None: return # empty schedule @@ -106,19 +114,17 @@ class TimeSlotArray(object): raise ValueError('Litmus is not a time machine') if start_no > end_no: raise ValueError('start no should be less than end no') - + start_slot = self.get_time_slot(start) - end_slot = self.get_time_slot(end) + 2 - + end_slot = self.get_time_slot(end) + 1 start_no = max(0, start_no) end_no = min(self.list_sizes[list_type] - 1, end_no) - for no in range(start_no, end_no + 1): - for type in event_types: - for slot in range(start_slot, end_slot): - if slot in self.array[list_type][no][type]: - for event in self.array[list_type][no][type][slot]: - yield event + for slot in xrange(start_slot, end_slot + 1): + if slot not in slots: + slots[slot] = {} + for no in xrange(start_no, end_no + 1): + slots[slot][no] = None class Schedule(object): """The total schedule (task system), consisting of a certain number of @@ -138,16 +144,26 @@ class Schedule(object): def get_selected(self): return self.selected - def set_selected(self, new_selected): - for event in self.selected: - event.selected = False - for event in new_selected: - event.selected = True - self.selected = new_selected - - def get_selected(self): - return copy.copy(self.selected) + def set_selected(self, selected): + self.selected = selected + + def add_selected(self, selected): + for layer in selected: + if layer not in self.selected: + self.selected[layer] = {} + for event in selected[layer]: + if event not in self.selected: + self.selected[layer][event] = {} + for graph in selected[layer][event]: + self.selected[layer][event][graph] = selected[layer][event][graph] + def remove_selected(self, selected): + for layer in selected: + if layer in self.selected: + for event in selected[layer]: + if event in self.selected[layer]: + del self.selected[layer][event] + def set_time_params(self, time_per_maj=None): self.time_per_maj = time_per_maj if self.time_per_maj is None: @@ -212,7 +228,13 @@ class Schedule(object): def get_num_cpus(self): return self.num_cpus - + +def deepcopy_selected(selected): + selected_copy = {} + for layer in selected: + selected_copy[layer] = copy.copy(selected[layer]) + return selected_copy + class Task(object): """Represents a task, including the set of jobs that were run under this task.""" @@ -313,7 +335,6 @@ class Event(DummyEvent): def __init__(self, time, cpu): super(Event, self).__init__(time, cpu) self.erroneous = False - self.selected = False def __str__(self): return '[Event]' @@ -332,7 +353,8 @@ class Event(DummyEvent): def is_selected(self): """Returns whether the event has been selected by the user. (needed for rendering)""" - return self.selected + selected = self.get_job().get_task().get_schedule().get_selected() + return self.get_layer() in selected and self in selected[self.get_layer()] def scan(self, cur_cpu, switches): """Part of the procedure that walks through all the events and sets @@ -480,7 +502,7 @@ class SwitchAwayEvent(Event): def __str__(self): if self.corresp_start_event is None: - return 'Switch Away (w/o Switch To)' + self._common_str() + 'TIME=' \ + return 'Switch Away (w/o Switch To)' + self._common_str() + ', TIME=' \ + str(self.get_time()) return str(self.corresp_start_event) @@ -641,7 +663,7 @@ class InversionEndEvent(ErrorEvent): if self.corresp_start_event is None: self.erroneous = True - print "inversion end was not matched by a corresponding inversion start" + #print "inversion end was not matched by a corresponding inversion start" super(InversionEndEvent, self).scan(cur_cpu, switches) -- cgit v1.2.2