diff options
| author | Mac Mollison <mollison@cs.unc.edu> | 2011-01-31 16:40:54 -0500 |
|---|---|---|
| committer | Mac Mollison <mollison@cs.unc.edu> | 2011-01-31 16:40:54 -0500 |
| commit | d2240e7a9b15d18dfd0f3cbe75f3adf1c9e7fabf (patch) | |
| tree | f7d164c21716b55f3d9195f055db73505bbf951d /unit_trace/viz/graph.py | |
| parent | 85a089c42749e1394ae12321564109f25fa8154f (diff) | |
Added support for visualizing arbitrary actions.
(By Jonathan, cherry-picked by Mac)
Conflicts:
unit_trace/trace_reader.py
unit_trace/viz/canvas.py
unit_trace/viz/graph.py
unit_trace/viz/schedule.py
Diffstat (limited to 'unit_trace/viz/graph.py')
| -rw-r--r-- | unit_trace/viz/graph.py | 94 |
1 files changed, 87 insertions, 7 deletions
diff --git a/unit_trace/viz/graph.py b/unit_trace/viz/graph.py index a10d9bd..f2021ce 100644 --- a/unit_trace/viz/graph.py +++ b/unit_trace/viz/graph.py | |||
| @@ -8,11 +8,12 @@ than the canvas classes (time and task/cpu number rather than plain coordinates) | |||
| 8 | update themselves, unlike the Canvas which can only overwrite itself.""" | 8 | update themselves, unlike the Canvas which can only overwrite itself.""" |
| 9 | 9 | ||
| 10 | class Graph(object): | 10 | class Graph(object): |
| 11 | DEF_BAR_PLIST = [Pattern([(0.0, 0.9, 0.9)]), Pattern([(0.9, 0.3, 0.0)]), Pattern([(0.9, 0.7, 0.0)]), | 11 | DEF_BAR_PLIST = [Pattern([(0.0, 0.9, 0.9)]), Pattern([(0.9, 0.3, 0.0)]), |
| 12 | Pattern([(0.0, 0.0, 0.8)]), Pattern([(0.0, 0.2, 0.9)]), Pattern([(0.0, 0.6, 0.6)]), | 12 | Pattern([(0.9, 0.7, 0.0)]), Pattern([(0.0, 0.0, 0.8)]), |
| 13 | Pattern([(0.0, 0.2, 0.9)]), Pattern([(0.0, 0.6, 0.6)]), | ||
| 13 | Pattern([(0.75, 0.75, 0.75)])] | 14 | Pattern([(0.75, 0.75, 0.75)])] |
| 14 | DEF_ITEM_CLIST = [(0.3, 0.0, 0.0), (0.0, 0.3, 0.0), (0.0, 0.0, 0.3), (0.3, 0.3, 0.0), (0.0, 0.3, 0.3), | 15 | DEF_ITEM_CLIST = [(0.3, 0.0, 0.0), (0.0, 0.3, 0.0), (0.0, 0.0, 0.3), |
| 15 | (0.3, 0.0, 0.3)] | 16 | (0.3, 0.3, 0.0), (0.0, 0.3, 0.3), (0.3, 0.0, 0.3)] |
| 16 | 17 | ||
| 17 | def __init__(self, CanvasType, surface, start_time, end_time, y_item_list, attrs=GraphFormat(), | 18 | def __init__(self, CanvasType, surface, start_time, end_time, y_item_list, attrs=GraphFormat(), |
| 18 | item_clist=DEF_ITEM_CLIST, bar_plist=DEF_BAR_PLIST): | 19 | item_clist=DEF_ITEM_CLIST, bar_plist=DEF_BAR_PLIST): |
| @@ -106,9 +107,12 @@ class Graph(object): | |||
| 106 | """get x so that x is at instant ``time'' on the graph""" | 107 | """get x so that x is at instant ``time'' on the graph""" |
| 107 | return self.origin[0] + GraphFormat.X_AXIS_MEASURE_OFS + 1.0 * (time - self.start_time) / self.attrs.time_per_maj * self.attrs.maj_sep | 108 | return self.origin[0] + GraphFormat.X_AXIS_MEASURE_OFS + 1.0 * (time - self.start_time) / self.attrs.time_per_maj * self.attrs.maj_sep |
| 108 | 109 | ||
| 110 | def get_item_yorigin(self, item_no): | ||
| 111 | return self.origin[1] - self._get_y_axis_height() + self.attrs.y_item_size * item_no; | ||
| 112 | |||
| 109 | def get_item_ypos(self, item_no): | 113 | def get_item_ypos(self, item_no): |
| 110 | """get y so that y is where the top of a bar would be in item #n's area""" | 114 | """get y so that y is where the top of a bar would be in item #n's area""" |
| 111 | return self.origin[1] - self._get_y_axis_height() + self.attrs.y_item_size * (item_no + 0.5 - GraphFormat.BAR_SIZE_FACTOR / 2.0) | 115 | return self.get_item_yorigin(item_no) + self.attrs.y_item_size * (0.5 - GraphFormat.BAR_SIZE_FACTOR / 2.0) |
| 112 | 116 | ||
| 113 | def _get_bar_width(self, start_time, end_time): | 117 | def _get_bar_width(self, start_time, end_time): |
| 114 | return 1.0 * (end_time - start_time) / self.attrs.time_per_maj * self.attrs.maj_sep | 118 | return 1.0 * (end_time - start_time) / self.attrs.time_per_maj * self.attrs.maj_sep |
| @@ -167,7 +171,29 @@ class Graph(object): | |||
| 167 | raise NotImplementedError | 171 | raise NotImplementedError |
| 168 | 172 | ||
| 169 | def get_events_to_render(self, sched, regions, selectable=False): | 173 | def get_events_to_render(self, sched, regions, selectable=False): |
| 170 | raise NotImplementedError | 174 | slots = {} |
| 175 | |||
| 176 | self.min_time, self.max_time, self.min_item, self.max_item = None, None, None, None | ||
| 177 | for region in regions: | ||
| 178 | x, y, width, height = region | ||
| 179 | start_time, end_time, start_item, end_item = self.get_offset_params(x, y, width, height) | ||
| 180 | self._recomp_min_max(start_time, end_time, start_item, end_item) | ||
| 181 | |||
| 182 | sched.get_time_slot_array().get_slots(slots, | ||
| 183 | start_time, end_time, start_item, end_item, | ||
| 184 | self.list_type) | ||
| 185 | |||
| 186 | events_to_render = {} | ||
| 187 | for layer in Canvas.LAYERS: | ||
| 188 | events_to_render[layer] = {} | ||
| 189 | |||
| 190 | for event in sched.get_time_slot_array().get_events(slots, | ||
| 191 | self.list_type, schedule.EVENT_LIST): | ||
| 192 | events_to_render[event.get_layer()][event] = None | ||
| 193 | for event in sched.get_jobless(): | ||
| 194 | events_to_render[event.get_layer()][event] = None | ||
| 195 | |||
| 196 | return events_to_render | ||
| 171 | 197 | ||
| 172 | def render_surface(self, sched, regions, selectable=False): | 198 | def render_surface(self, sched, regions, selectable=False): |
| 173 | if not selectable: | 199 | if not selectable: |
| @@ -269,6 +295,16 @@ class Graph(object): | |||
| 269 | a certain time.""" | 295 | a certain time.""" |
| 270 | raise NotImplementedError | 296 | raise NotImplementedError |
| 271 | 297 | ||
| 298 | def draw_action_symbol_at_time(self, time, task_no, cpu_no, action, | ||
| 299 | job_no, selected=False): | ||
| 300 | """Draws an action symbol at a certain time for some task and job""" | ||
| 301 | raise NotImplementedError | ||
| 302 | |||
| 303 | def add_sel_action_symbol_at_time(self, time, task_no, cpu_no, event): | ||
| 304 | """Same as above, except instead of drawing adds a selectable region at | ||
| 305 | a certain time.""" | ||
| 306 | raise NotImplementedError | ||
| 307 | |||
| 272 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None): | 308 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None): |
| 273 | """Draws a bar over a certain time period for some task, optionally labelling it.""" | 309 | """Draws a bar over a certain time period for some task, optionally labelling it.""" |
| 274 | raise NotImplementedError | 310 | raise NotImplementedError |
| @@ -391,6 +427,33 @@ class TaskGraph(Graph): | |||
| 391 | 427 | ||
| 392 | self.canvas.add_sel_deadline_arrow_big(x, y, height, event) | 428 | self.canvas.add_sel_deadline_arrow_big(x, y, height, event) |
| 393 | 429 | ||
| 430 | def draw_action_symbol_at_time(self, time, task_no, cpu_no, action, | ||
| 431 | job_no=None, selected=False): | ||
| 432 | x = self.get_time_xpos(time) | ||
| 433 | y = None | ||
| 434 | |||
| 435 | if task_no != -1: | ||
| 436 | y = self.get_item_ypos(task_no) | ||
| 437 | else: | ||
| 438 | y = self.origin[1] | ||
| 439 | |||
| 440 | height = 1.5 * (self.get_item_ypos(0) - self.get_item_yorigin(0)) | ||
| 441 | |||
| 442 | self.canvas.draw_action_symbol(cpu_no, action, x, y, height, selected) | ||
| 443 | |||
| 444 | def add_sel_action_symbol_at_time(self, time, task_no, cpu_no, event): | ||
| 445 | x = self.get_time_xpos(time) | ||
| 446 | y = None | ||
| 447 | |||
| 448 | if task_no != -1: | ||
| 449 | y = self.get_item_ypos(task_no) | ||
| 450 | else: | ||
| 451 | y = self.origin[1] | ||
| 452 | |||
| 453 | height = 1.5 * (self.get_item_ypos(0) - self.get_item_yorigin(0)) | ||
| 454 | |||
| 455 | self.canvas.add_sel_action_symbol(x, y, height, event) | ||
| 456 | |||
| 394 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 457 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): |
| 395 | if start_time > end_time: | 458 | if start_time > end_time: |
| 396 | raise ValueError("Litmus is not a time machine") | 459 | raise ValueError("Litmus is not a time machine") |
| @@ -599,10 +662,27 @@ class CpuGraph(Graph): | |||
| 599 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR | 662 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR |
| 600 | 663 | ||
| 601 | x = self.get_time_xpos(time) | 664 | x = self.get_time_xpos(time) |
| 602 | y = self.origin[1] - height | 665 | y = self.get_item_ypos(task_no) |
| 603 | 666 | ||
| 604 | self.canvas.add_sel_deadline_arrow_small(x, y, height, event) | 667 | self.canvas.add_sel_deadline_arrow_small(x, y, height, event) |
| 605 | 668 | ||
| 669 | def draw_action_symbol_at_time(self, time, task_no, cpu_no, action, | ||
| 670 | job_no=None, selected=False): | ||
| 671 | x = self.get_time_xpos(time) | ||
| 672 | y = self.get_item_ypos(cpu_no) | ||
| 673 | |||
| 674 | height = 1.5 * (y - self.get_item_yorigin(cpu_no)) | ||
| 675 | |||
| 676 | self.canvas.draw_action_symbol(task_no, action, x, y, height, selected) | ||
| 677 | |||
| 678 | def add_sel_action_symbol_at_time(self, time, task_no, cpu_no, event): | ||
| 679 | x = self.get_time_xpos(time) | ||
| 680 | y = self.get_item_ypos(cpu_no) | ||
| 681 | |||
| 682 | height = 1.5 * (y - self.get_item_yorigin(cpu_no)) | ||
| 683 | |||
| 684 | self.canvas.add_sel_action_symbol(x, y, height, event) | ||
| 685 | |||
| 606 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 686 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): |
| 607 | if start_time > end_time: | 687 | if start_time > end_time: |
| 608 | raise ValueError("Litmus is not a time machine") | 688 | raise ValueError("Litmus is not a time machine") |
