diff options
Diffstat (limited to 'unit_trace/viz/graph.py')
-rw-r--r-- | unit_trace/viz/graph.py | 444 |
1 files changed, 222 insertions, 222 deletions
diff --git a/unit_trace/viz/graph.py b/unit_trace/viz/graph.py index 6982e7c..a10d9bd 100644 --- a/unit_trace/viz/graph.py +++ b/unit_trace/viz/graph.py | |||
@@ -13,7 +13,7 @@ class Graph(object): | |||
13 | Pattern([(0.75, 0.75, 0.75)])] | 13 | 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), | 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 | (0.3, 0.0, 0.3)] | 15 | (0.3, 0.0, 0.3)] |
16 | 16 | ||
17 | def __init__(self, CanvasType, surface, start_time, end_time, y_item_list, attrs=GraphFormat(), | 17 | 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): | 18 | item_clist=DEF_ITEM_CLIST, bar_plist=DEF_BAR_PLIST): |
19 | # deal with possibly blank schedules | 19 | # deal with possibly blank schedules |
@@ -21,16 +21,16 @@ class Graph(object): | |||
21 | start_time = 0 | 21 | start_time = 0 |
22 | if end_time is None: | 22 | if end_time is None: |
23 | end_time = 0 | 23 | end_time = 0 |
24 | 24 | ||
25 | if start_time > end_time: | 25 | if start_time > end_time: |
26 | raise ValueError("Litmus is not a time machine") | 26 | raise ValueError("Litmus is not a time machine") |
27 | 27 | ||
28 | self.attrs = attrs | 28 | self.attrs = attrs |
29 | self.start_time = start_time | 29 | self.start_time = start_time |
30 | self.end_time = end_time | 30 | self.end_time = end_time |
31 | self.y_item_list = y_item_list | 31 | self.y_item_list = y_item_list |
32 | self.num_maj = int(math.ceil((self.end_time - self.start_time) * 1.0 / self.attrs.time_per_maj)) + 1 | 32 | self.num_maj = int(math.ceil((self.end_time - self.start_time) * 1.0 / self.attrs.time_per_maj)) + 1 |
33 | 33 | ||
34 | width = self.num_maj * self.attrs.maj_sep + GraphFormat.X_AXIS_MEASURE_OFS + GraphFormat.WIDTH_PAD | 34 | width = self.num_maj * self.attrs.maj_sep + GraphFormat.X_AXIS_MEASURE_OFS + GraphFormat.WIDTH_PAD |
35 | height = (len(self.y_item_list) + 1) * self.attrs.y_item_size + GraphFormat.HEIGHT_PAD | 35 | height = (len(self.y_item_list) + 1) * self.attrs.y_item_size + GraphFormat.HEIGHT_PAD |
36 | 36 | ||
@@ -40,7 +40,7 @@ class Graph(object): | |||
40 | extra_width = 0.0 | 40 | extra_width = 0.0 |
41 | dummy_surface = surface.__class__() | 41 | dummy_surface = surface.__class__() |
42 | dummy_surface.renew(10, 10) | 42 | dummy_surface.renew(10, 10) |
43 | 43 | ||
44 | dummy_surface.ctx.select_font_face(self.attrs.item_fopts.name, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) | 44 | dummy_surface.ctx.select_font_face(self.attrs.item_fopts.name, cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) |
45 | dummy_surface.ctx.set_font_size(self.attrs.item_fopts.size) | 45 | dummy_surface.ctx.set_font_size(self.attrs.item_fopts.size) |
46 | for item in self.y_item_list: | 46 | for item in self.y_item_list: |
@@ -49,49 +49,49 @@ class Graph(object): | |||
49 | cur_width = te[2] | 49 | cur_width = te[2] |
50 | if cur_width > extra_width: | 50 | if cur_width > extra_width: |
51 | extra_width = cur_width | 51 | extra_width = cur_width |
52 | 52 | ||
53 | width += extra_width | 53 | width += extra_width |
54 | 54 | ||
55 | self.origin = (extra_width + GraphFormat.WIDTH_PAD / 2.0, height - GraphFormat.HEIGHT_PAD / 2.0) | 55 | self.origin = (extra_width + GraphFormat.WIDTH_PAD / 2.0, height - GraphFormat.HEIGHT_PAD / 2.0) |
56 | 56 | ||
57 | self.width = width | 57 | self.width = width |
58 | self.height = height | 58 | self.height = height |
59 | 59 | ||
60 | #if surface.ctx is None: | 60 | #if surface.ctx is None: |
61 | # surface.renew(width, height) | 61 | # surface.renew(width, height) |
62 | 62 | ||
63 | self.canvas = CanvasType(width, height, item_clist, bar_plist, surface) | 63 | self.canvas = CanvasType(width, height, item_clist, bar_plist, surface) |
64 | 64 | ||
65 | def get_selected_regions(self, real_x, real_y, width, height): | 65 | def get_selected_regions(self, real_x, real_y, width, height): |
66 | return self.canvas.get_selected_regions(real_x, real_y, width, height) | 66 | return self.canvas.get_selected_regions(real_x, real_y, width, height) |
67 | 67 | ||
68 | def get_width(self): | 68 | def get_width(self): |
69 | return self.width | 69 | return self.width |
70 | 70 | ||
71 | def get_height(self): | 71 | def get_height(self): |
72 | return self.height | 72 | return self.height |
73 | 73 | ||
74 | def get_origin(self): | 74 | def get_origin(self): |
75 | return self.origin | 75 | return self.origin |
76 | 76 | ||
77 | def get_attrs(self): | 77 | def get_attrs(self): |
78 | return self.attrs | 78 | return self.attrs |
79 | 79 | ||
80 | def add_sel_region(self, region): | 80 | def add_sel_region(self, region): |
81 | self.canvas.add_sel_region(region) | 81 | self.canvas.add_sel_region(region) |
82 | 82 | ||
83 | def get_sel_region(self, event): | 83 | def get_sel_region(self, event): |
84 | return self.canvas.get_sel_region(event) | 84 | return self.canvas.get_sel_region(event) |
85 | 85 | ||
86 | def has_sel_region(self, event): | 86 | def has_sel_region(self, event): |
87 | return self.canvas.has_sel_region(event) | 87 | return self.canvas.has_sel_region(event) |
88 | 88 | ||
89 | def update_view(self, x, y, width, height, scale, ctx): | 89 | def update_view(self, x, y, width, height, scale, ctx): |
90 | """Proxy into the surface's pan.""" | 90 | """Proxy into the surface's pan.""" |
91 | self.canvas.surface.pan(x, y, width, height) | 91 | self.canvas.surface.pan(x, y, width, height) |
92 | self.canvas.set_scale(scale) | 92 | self.canvas.set_scale(scale) |
93 | self.canvas.surface.change_ctx(ctx) | 93 | self.canvas.surface.change_ctx(ctx) |
94 | 94 | ||
95 | def _recomp_min_max(self, start_time, end_time, start_item, end_item): | 95 | def _recomp_min_max(self, start_time, end_time, start_item, end_item): |
96 | if self.min_time is None or start_time < self.min_time: | 96 | if self.min_time is None or start_time < self.min_time: |
97 | self.min_time = start_time | 97 | self.min_time = start_time |
@@ -101,93 +101,93 @@ class Graph(object): | |||
101 | self.min_item = start_item | 101 | self.min_item = start_item |
102 | if self.max_item is None or end_item > self.max_item: | 102 | if self.max_item is None or end_item > self.max_item: |
103 | self.max_item = end_item | 103 | self.max_item = end_item |
104 | 104 | ||
105 | def _get_time_xpos(self, time): | 105 | def get_time_xpos(self, time): |
106 | """get x so that x is at instant ``time'' on the graph""" | 106 | """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 | 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 | 108 | ||
109 | def _get_item_ypos(self, item_no): | 109 | 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""" | 110 | """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) | 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) |
112 | 112 | ||
113 | def _get_bar_width(self, start_time, end_time): | 113 | 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 | 114 | return 1.0 * (end_time - start_time) / self.attrs.time_per_maj * self.attrs.maj_sep |
115 | 115 | ||
116 | def _get_bar_height(self): | 116 | def _get_bar_height(self): |
117 | return self.attrs.y_item_size * GraphFormat.BAR_SIZE_FACTOR | 117 | return self.attrs.y_item_size * GraphFormat.BAR_SIZE_FACTOR |
118 | 118 | ||
119 | def _get_mini_bar_height(self): | 119 | def _get_mini_bar_height(self): |
120 | return self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR | 120 | return self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR |
121 | 121 | ||
122 | def _get_mini_bar_ofs(self): | 122 | def _get_mini_bar_ofs(self): |
123 | return self.attrs.y_item_size * (GraphFormat.MINI_BAR_SIZE_FACTOR + GraphFormat.BAR_MINI_BAR_GAP_FACTOR) | 123 | return self.attrs.y_item_size * (GraphFormat.MINI_BAR_SIZE_FACTOR + GraphFormat.BAR_MINI_BAR_GAP_FACTOR) |
124 | 124 | ||
125 | def _get_y_axis_height(self): | 125 | def _get_y_axis_height(self): |
126 | return (len(self.y_item_list) + 1) * self.attrs.y_item_size | 126 | return (len(self.y_item_list) + 1) * self.attrs.y_item_size |
127 | 127 | ||
128 | def _get_bottom_tick(self, time): | 128 | def _get_bottom_tick(self, time): |
129 | return int(math.floor((time - self.start_time) / self.attrs.time_per_maj)) | 129 | return int(math.floor((time - self.start_time) / self.attrs.time_per_maj)) |
130 | 130 | ||
131 | def _get_top_tick(self, time): | 131 | def _get_top_tick(self, time): |
132 | return int(math.ceil((time - self.start_time) / self.attrs.time_per_maj)) | 132 | return int(math.ceil((time - self.start_time) / self.attrs.time_per_maj)) |
133 | 133 | ||
134 | def get_surface(self): | 134 | def get_surface(self): |
135 | """Gets the underlying surface.""" | 135 | """Gets the underlying surface.""" |
136 | return self.canvas.get_surface() | 136 | return self.canvas.get_surface() |
137 | 137 | ||
138 | def xcoor_to_time(self, x): | 138 | def xcoor_to_time(self, x): |
139 | #x = self.origin[0] + GraphFormat.X_AXIS_MEASURE_OFS + (time - self.start) / self.attrs.time_per_maj * self.attrs.maj_sep | 139 | #x = self.origin[0] + GraphFormat.X_AXIS_MEASURE_OFS + (time - self.start) / self.attrs.time_per_maj * self.attrs.maj_sep |
140 | return (x - self.origin[0] - GraphFormat.X_AXIS_MEASURE_OFS) / self.attrs.maj_sep \ | 140 | return (x - self.origin[0] - GraphFormat.X_AXIS_MEASURE_OFS) / self.attrs.maj_sep \ |
141 | * self.attrs.time_per_maj + self.start_time | 141 | * self.attrs.time_per_maj + self.start_time |
142 | 142 | ||
143 | def ycoor_to_item_no(self, y): | 143 | def ycoor_to_item_no(self, y): |
144 | return int((y - self.origin[1] + self._get_y_axis_height()) // self.attrs.y_item_size) | 144 | return int((y - self.origin[1] + self._get_y_axis_height()) // self.attrs.y_item_size) |
145 | 145 | ||
146 | def get_offset_params(self, real_x, real_y, width, height): | 146 | def get_offset_params(self, real_x, real_y, width, height): |
147 | x_start, y_start = self.canvas.surface.get_virt_coor_unscaled(real_x, real_y) | 147 | x_start, y_start = self.canvas.surface.get_virt_coor_unscaled(real_x, real_y) |
148 | x_end, y_end = self.canvas.surface.get_virt_coor_unscaled(real_x + width, real_y + height) | 148 | x_end, y_end = self.canvas.surface.get_virt_coor_unscaled(real_x + width, real_y + height) |
149 | 149 | ||
150 | start_time = self.xcoor_to_time(x_start) | 150 | start_time = self.xcoor_to_time(x_start) |
151 | end_time = self.xcoor_to_time(x_end) | 151 | end_time = self.xcoor_to_time(x_end) |
152 | 152 | ||
153 | start_item = self.ycoor_to_item_no(y_start) | 153 | start_item = self.ycoor_to_item_no(y_start) |
154 | end_item = 1 + self.ycoor_to_item_no(y_end) | 154 | end_item = 1 + self.ycoor_to_item_no(y_end) |
155 | 155 | ||
156 | return (start_time, end_time, start_item, end_item) | 156 | return (start_time, end_time, start_item, end_item) |
157 | 157 | ||
158 | def draw_skeleton(self, start_time, end_time, start_item, end_item): | 158 | def draw_skeleton(self, start_time, end_time, start_item, end_item): |
159 | self.draw_grid_at_time(start_time, end_time, start_item, end_item) | 159 | self.draw_grid_at_time(start_time, end_time, start_item, end_item) |
160 | self.draw_x_axis_with_labels_at_time(start_time, end_time) | 160 | self.draw_x_axis_with_labels_at_time(start_time, end_time) |
161 | self.draw_y_axis_with_labels() | 161 | self.draw_y_axis_with_labels() |
162 | 162 | ||
163 | def render_surface(self, sched, regions, selectable=False): | 163 | def render_surface(self, sched, regions, selectable=False): |
164 | raise NotImplementedError | 164 | raise NotImplementedError |
165 | 165 | ||
166 | def render_all(self, schedule): | 166 | def render_all(self, schedule): |
167 | raise NotImplementedError | 167 | raise NotImplementedError |
168 | 168 | ||
169 | def get_events_to_render(self, sched, regions, selectable=False): | 169 | def get_events_to_render(self, sched, regions, selectable=False): |
170 | raise NotImplementedError | 170 | raise NotImplementedError |
171 | 171 | ||
172 | def render_surface(self, sched, regions, selectable=False): | 172 | def render_surface(self, sched, regions, selectable=False): |
173 | if not selectable: | 173 | if not selectable: |
174 | self.canvas.whiteout() | 174 | self.canvas.whiteout() |
175 | else: | 175 | else: |
176 | self.canvas.clear_selectable_regions() | 176 | self.canvas.clear_selectable_regions() |
177 | self.render_events(self.get_events_to_render(sched, regions, selectable), selectable) | 177 | self.render_events(self.get_events_to_render(sched, regions, selectable), selectable) |
178 | 178 | ||
179 | def render_events(self, events, selectable=False): | 179 | def render_events(self, events, selectable=False): |
180 | for layer in Canvas.LAYERS: | 180 | for layer in Canvas.LAYERS: |
181 | prev_events = {} | 181 | prev_events = {} |
182 | if layer in events: | 182 | if layer in events: |
183 | for event in events[layer]: | 183 | for event in events[layer]: |
184 | event.render(self, layer, prev_events, selectable) | 184 | event.render(self, layer, prev_events, selectable) |
185 | 185 | ||
186 | def draw_axes(self, x_axis_label, y_axis_label): | 186 | def draw_axes(self, x_axis_label, y_axis_label): |
187 | """Draws and labels the axes according to the parameters that we were initialized | 187 | """Draws and labels the axes according to the parameters that we were initialized |
188 | with.""" | 188 | with.""" |
189 | self.draw_grid_at_time(self.start_time, self.end_time, 0, len(self.attrs.y_item_list) - 1) | 189 | self.draw_grid_at_time(self.start_time, self.end_time, 0, len(self.attrs.y_item_list) - 1) |
190 | 190 | ||
191 | self.canvas.draw_x_axis(self.origin[0], self.origin[1], self.num_maj, self.attrs.maj_sep, self.attrs.min_per_maj) | 191 | self.canvas.draw_x_axis(self.origin[0], self.origin[1], self.num_maj, self.attrs.maj_sep, self.attrs.min_per_maj) |
192 | self.canvas.draw_y_axis(self.origin[0], self.origin[1], self._get_y_axis_height()) | 192 | self.canvas.draw_y_axis(self.origin[0], self.origin[1], self._get_y_axis_height()) |
193 | self.canvas.draw_x_axis_labels(self.origin[0], self.origin[1], 0, self.num_maj - 1,\ | 193 | self.canvas.draw_x_axis_labels(self.origin[0], self.origin[1], 0, self.num_maj - 1,\ |
@@ -195,425 +195,425 @@ class Graph(object): | |||
195 | self.attrs.time_per_maj, self.attrs.show_min, self.attrs.majfopts, self.attrs.minfopts) | 195 | self.attrs.time_per_maj, self.attrs.show_min, self.attrs.majfopts, self.attrs.minfopts) |
196 | self.canvas.draw_y_axis_labels(self.origin[0], self.origin[1], self._get_y_axis_height(), self.y_item_list, \ | 196 | self.canvas.draw_y_axis_labels(self.origin[0], self.origin[1], self._get_y_axis_height(), self.y_item_list, \ |
197 | self.attrs.y_item_size, self.attrs.item_fopts) | 197 | self.attrs.y_item_size, self.attrs.item_fopts) |
198 | 198 | ||
199 | def draw_grid_at_time(self, start_time, end_time, start_item, end_item): | 199 | def draw_grid_at_time(self, start_time, end_time, start_item, end_item): |
200 | """Draws the grid, but only in a certain time and item range.""" | 200 | """Draws the grid, but only in a certain time and item range.""" |
201 | start_tick = max(0, self._get_bottom_tick(start_time)) | 201 | start_tick = max(0, self._get_bottom_tick(start_time)) |
202 | end_tick = min(self.num_maj - 1, self._get_top_tick(end_time)) | 202 | end_tick = min(self.num_maj - 1, self._get_top_tick(end_time)) |
203 | 203 | ||
204 | start_item = max(0, start_item) | 204 | start_item = max(0, start_item) |
205 | end_item = min(len(self.y_item_list), end_item) | 205 | end_item = min(len(self.y_item_list), end_item) |
206 | 206 | ||
207 | self.canvas.draw_grid(self.origin[0], self.origin[1], self._get_y_axis_height(), | 207 | self.canvas.draw_grid(self.origin[0], self.origin[1], self._get_y_axis_height(), |
208 | start_tick, end_tick, start_item, end_item, self.attrs.maj_sep, self.attrs.y_item_size, \ | 208 | start_tick, end_tick, start_item, end_item, self.attrs.maj_sep, self.attrs.y_item_size, \ |
209 | self.attrs.min_per_maj, True) | 209 | self.attrs.min_per_maj, True) |
210 | 210 | ||
211 | def draw_x_axis_with_labels_at_time(self, start_time, end_time): | 211 | def draw_x_axis_with_labels_at_time(self, start_time, end_time): |
212 | start_tick = max(0, self._get_bottom_tick(start_time)) | 212 | start_tick = max(0, self._get_bottom_tick(start_time)) |
213 | end_tick = min(self.num_maj - 1, self._get_top_tick(end_time)) | 213 | end_tick = min(self.num_maj - 1, self._get_top_tick(end_time)) |
214 | 214 | ||
215 | self.canvas.draw_x_axis(self.origin[0], self.origin[1], start_tick, end_tick, \ | 215 | self.canvas.draw_x_axis(self.origin[0], self.origin[1], start_tick, end_tick, \ |
216 | self.attrs.maj_sep, self.attrs.min_per_maj) | 216 | self.attrs.maj_sep, self.attrs.min_per_maj) |
217 | self.canvas.draw_x_axis_labels(self.origin[0], self.origin[1], start_tick, \ | 217 | self.canvas.draw_x_axis_labels(self.origin[0], self.origin[1], start_tick, \ |
218 | end_tick, self.attrs.maj_sep, self.attrs.min_per_maj, | 218 | end_tick, self.attrs.maj_sep, self.attrs.min_per_maj, |
219 | self.start_time + start_tick * self.attrs.time_per_maj, | 219 | self.start_time + start_tick * self.attrs.time_per_maj, |
220 | self.attrs.time_per_maj, False) | 220 | self.attrs.time_per_maj, False) |
221 | 221 | ||
222 | def draw_y_axis_with_labels(self): | 222 | def draw_y_axis_with_labels(self): |
223 | self.canvas.draw_y_axis(self.origin[0], self.origin[1], self._get_y_axis_height()) | 223 | self.canvas.draw_y_axis(self.origin[0], self.origin[1], self._get_y_axis_height()) |
224 | self.canvas.draw_y_axis_labels(self.origin[0], self.origin[1], self._get_y_axis_height(), \ | 224 | self.canvas.draw_y_axis_labels(self.origin[0], self.origin[1], self._get_y_axis_height(), \ |
225 | self.y_item_list, self.attrs.y_item_size) | 225 | self.y_item_list, self.attrs.y_item_size) |
226 | 226 | ||
227 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 227 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
228 | """Draws a suspension symbol for a dcertain task at an instant in time.""" | 228 | """Draws a suspension symbol for a dcertain task at an instant in time.""" |
229 | raise NotImplementedError | 229 | raise NotImplementedError |
230 | 230 | ||
231 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): | 231 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): |
232 | """Same as above, except instead of drawing adds a selectable region at | 232 | """Same as above, except instead of drawing adds a selectable region at |
233 | a certain time.""" | 233 | a certain time.""" |
234 | raise NotImplementedError | 234 | raise NotImplementedError |
235 | 235 | ||
236 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 236 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
237 | """Draws a resumption symbol for a certain task at an instant in time.""" | 237 | """Draws a resumption symbol for a certain task at an instant in time.""" |
238 | raise NotImplementedError | 238 | raise NotImplementedError |
239 | 239 | ||
240 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): | 240 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): |
241 | """Same as above, except instead of drawing adds a selectable region at | 241 | """Same as above, except instead of drawing adds a selectable region at |
242 | a certain time.""" | 242 | a certain time.""" |
243 | raise NotImplementedError | 243 | raise NotImplementedError |
244 | 244 | ||
245 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): | 245 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): |
246 | """Draws a completion marker for a certain task at an instant in time.""" | 246 | """Draws a completion marker for a certain task at an instant in time.""" |
247 | raise NotImplementedError | 247 | raise NotImplementedError |
248 | 248 | ||
249 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): | 249 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): |
250 | """Same as above, except instead of drawing adds a selectable region at | 250 | """Same as above, except instead of drawing adds a selectable region at |
251 | a certain time.""" | 251 | a certain time.""" |
252 | raise NotImplementedError | 252 | raise NotImplementedError |
253 | 253 | ||
254 | def draw_release_arrow_at_time(self, time, task_no, job_no, selected=False): | 254 | def draw_release_arrow_at_time(self, time, task_no, job_no, selected=False): |
255 | """Draws a release arrow at a certain time for some task and job""" | 255 | """Draws a release arrow at a certain time for some task and job""" |
256 | raise NotImplementedError | 256 | raise NotImplementedError |
257 | 257 | ||
258 | def add_sel_release_arrow_at_time(self, time, task_no, event): | 258 | def add_sel_release_arrow_at_time(self, time, task_no, event): |
259 | """Same as above, except instead of drawing adds a selectable region at | 259 | """Same as above, except instead of drawing adds a selectable region at |
260 | a certain time.""" | 260 | a certain time.""" |
261 | raise NotImplementedError | 261 | raise NotImplementedError |
262 | 262 | ||
263 | def draw_deadline_arrow_at_time(self, time, task_no, job_no, selected=False): | 263 | def draw_deadline_arrow_at_time(self, time, task_no, job_no, selected=False): |
264 | """Draws a deadline arrow at a certain time for some task and job""" | 264 | """Draws a deadline arrow at a certain time for some task and job""" |
265 | raise NotImplementedError | 265 | raise NotImplementedError |
266 | 266 | ||
267 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): | 267 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): |
268 | """Same as above, except instead of drawing adds a selectable region at | 268 | """Same as above, except instead of drawing adds a selectable region at |
269 | a certain time.""" | 269 | a certain time.""" |
270 | raise NotImplementedError | 270 | raise NotImplementedError |
271 | 271 | ||
272 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None): | 272 | 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.""" | 273 | """Draws a bar over a certain time period for some task, optionally labelling it.""" |
274 | raise NotImplementedError | 274 | raise NotImplementedError |
275 | 275 | ||
276 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 276 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
277 | """Same as above, except instead of drawing adds a selectable region at | 277 | """Same as above, except instead of drawing adds a selectable region at |
278 | a certain time.""" | 278 | a certain time.""" |
279 | raise NotImplementedError | 279 | raise NotImplementedError |
280 | 280 | ||
281 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, clip_side=None, job_no=None): | 281 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, clip_side=None, job_no=None): |
282 | """Draws a mini bar over a certain time period for some task, optionally labelling it.""" | 282 | """Draws a mini bar over a certain time period for some task, optionally labelling it.""" |
283 | raise NotImplementedError | 283 | raise NotImplementedError |
284 | 284 | ||
285 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 285 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
286 | """Same as above, except instead of drawing adds a selectable region at | 286 | """Same as above, except instead of drawing adds a selectable region at |
287 | a certain time.""" | 287 | a certain time.""" |
288 | raise NotImplementedError | 288 | raise NotImplementedError |
289 | 289 | ||
290 | class TaskGraph(Graph): | 290 | class TaskGraph(Graph): |
291 | def get_events_to_render(self, sched, regions, selectable=False): | 291 | def get_events_to_render(self, sched, regions, selectable=False): |
292 | slots = {} | 292 | slots = {} |
293 | 293 | ||
294 | self.min_time, self.max_time, self.min_item, self.max_item = None, None, None, None | 294 | self.min_time, self.max_time, self.min_item, self.max_item = None, None, None, None |
295 | for region in regions: | 295 | for region in regions: |
296 | x, y, width, height = region | 296 | x, y, width, height = region |
297 | start_time, end_time, start_item, end_item = self.get_offset_params(x, y, width, height) | 297 | start_time, end_time, start_item, end_item = self.get_offset_params(x, y, width, height) |
298 | self._recomp_min_max(start_time, end_time, start_item, end_item) | 298 | self._recomp_min_max(start_time, end_time, start_item, end_item) |
299 | 299 | ||
300 | sched.get_time_slot_array().get_slots(slots, | 300 | sched.get_time_slot_array().get_slots(slots, |
301 | start_time, end_time, start_item, end_item, | 301 | start_time, end_time, start_item, end_item, |
302 | schedule.TimeSlotArray.TASK_LIST) | 302 | schedule.TimeSlotArray.TASK_LIST) |
303 | 303 | ||
304 | 304 | ||
305 | if not selectable: | 305 | if not selectable: |
306 | self.draw_skeleton(self.min_time, self.max_time, | 306 | self.draw_skeleton(self.min_time, self.max_time, |
307 | self.min_item, self.max_item) | 307 | self.min_item, self.max_item) |
308 | 308 | ||
309 | events_to_render = {} | 309 | events_to_render = {} |
310 | for layer in Canvas.LAYERS: | 310 | for layer in Canvas.LAYERS: |
311 | events_to_render[layer] = {} | 311 | events_to_render[layer] = {} |
312 | 312 | ||
313 | for event in sched.get_time_slot_array().get_events(slots, | 313 | for event in sched.get_time_slot_array().get_events(slots, |
314 | schedule.TimeSlotArray.TASK_LIST, | 314 | schedule.TimeSlotArray.TASK_LIST, |
315 | schedule.EVENT_LIST): | 315 | schedule.EVENT_LIST): |
316 | events_to_render[event.get_layer()][event] = None | 316 | events_to_render[event.get_layer()][event] = None |
317 | 317 | ||
318 | return events_to_render | 318 | return events_to_render |
319 | 319 | ||
320 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 320 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
321 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 321 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
322 | x = self._get_time_xpos(time) | 322 | x = self.get_time_xpos(time) |
323 | y = self._get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 | 323 | y = self.get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 |
324 | self.canvas.draw_suspend_triangle(x, y, height, selected) | 324 | self.canvas.draw_suspend_triangle(x, y, height, selected) |
325 | 325 | ||
326 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): | 326 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): |
327 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 327 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
328 | x = self._get_time_xpos(time) | 328 | x = self.get_time_xpos(time) |
329 | y = self._get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 | 329 | y = self.get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 |
330 | 330 | ||
331 | self.canvas.add_sel_suspend_triangle(x, y, height, event) | 331 | self.canvas.add_sel_suspend_triangle(x, y, height, event) |
332 | 332 | ||
333 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 333 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
334 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 334 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
335 | x = self._get_time_xpos(time) | 335 | x = self.get_time_xpos(time) |
336 | y = self._get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 | 336 | y = self.get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 |
337 | 337 | ||
338 | self.canvas.draw_resume_triangle(x, y, height, selected) | 338 | self.canvas.draw_resume_triangle(x, y, height, selected) |
339 | 339 | ||
340 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): | 340 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): |
341 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 341 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
342 | x = self._get_time_xpos(time) | 342 | x = self.get_time_xpos(time) |
343 | y = self._get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 | 343 | y = self.get_item_ypos(task_no) + self._get_bar_height() / 2.0 - height / 2.0 |
344 | 344 | ||
345 | self.canvas.add_sel_resume_triangle(x, y, height, event) | 345 | self.canvas.add_sel_resume_triangle(x, y, height, event) |
346 | 346 | ||
347 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): | 347 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): |
348 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR | 348 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR |
349 | x = self._get_time_xpos(time) | 349 | x = self.get_time_xpos(time) |
350 | y = self._get_item_ypos(task_no) + self._get_bar_height() - height | 350 | y = self.get_item_ypos(task_no) + self._get_bar_height() - height |
351 | 351 | ||
352 | self.canvas.draw_completion_marker(x, y, height, selected) | 352 | self.canvas.draw_completion_marker(x, y, height, selected) |
353 | 353 | ||
354 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): | 354 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): |
355 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR | 355 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR |
356 | 356 | ||
357 | x = self._get_time_xpos(time) | 357 | x = self.get_time_xpos(time) |
358 | y = self._get_item_ypos(task_no) + self._get_bar_height() - height | 358 | y = self.get_item_ypos(task_no) + self._get_bar_height() - height |
359 | 359 | ||
360 | self.canvas.add_sel_completion_marker(x, y, height, event) | 360 | self.canvas.add_sel_completion_marker(x, y, height, event) |
361 | 361 | ||
362 | def draw_release_arrow_at_time(self, time, task_no, job_no=None, selected=False): | 362 | def draw_release_arrow_at_time(self, time, task_no, job_no=None, selected=False): |
363 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR | 363 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR |
364 | 364 | ||
365 | x = self._get_time_xpos(time) | 365 | x = self.get_time_xpos(time) |
366 | y = self._get_item_ypos(task_no) + self._get_bar_height() - height | 366 | y = self.get_item_ypos(task_no) + self._get_bar_height() - height |
367 | 367 | ||
368 | self.canvas.draw_release_arrow_big(x, y, height, selected) | 368 | self.canvas.draw_release_arrow_big(x, y, height, selected) |
369 | 369 | ||
370 | def add_sel_release_arrow_at_time(self, time, task_no, event): | 370 | def add_sel_release_arrow_at_time(self, time, task_no, event): |
371 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR | 371 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR |
372 | 372 | ||
373 | x = self._get_time_xpos(time) | 373 | x = self.get_time_xpos(time) |
374 | y = self._get_item_ypos(task_no) + self._get_bar_height() - height | 374 | y = self.get_item_ypos(task_no) + self._get_bar_height() - height |
375 | 375 | ||
376 | self.canvas.add_sel_release_arrow_big(x, y, height, event) | 376 | self.canvas.add_sel_release_arrow_big(x, y, height, event) |
377 | 377 | ||
378 | def draw_deadline_arrow_at_time(self, time, task_no, job_no=None, selected=False): | 378 | def draw_deadline_arrow_at_time(self, time, task_no, job_no=None, selected=False): |
379 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR | 379 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR |
380 | 380 | ||
381 | x = self._get_time_xpos(time) | 381 | x = self.get_time_xpos(time) |
382 | y = self._get_item_ypos(task_no) | 382 | y = self.get_item_ypos(task_no) |
383 | 383 | ||
384 | self.canvas.draw_deadline_arrow_big(x, y, height, selected) | 384 | self.canvas.draw_deadline_arrow_big(x, y, height, selected) |
385 | 385 | ||
386 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): | 386 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): |
387 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR | 387 | height = self._get_bar_height() * GraphFormat.BIG_ARROW_FACTOR |
388 | 388 | ||
389 | x = self._get_time_xpos(time) | 389 | x = self.get_time_xpos(time) |
390 | y = self._get_item_ypos(task_no) | 390 | y = self.get_item_ypos(task_no) |
391 | 391 | ||
392 | self.canvas.add_sel_deadline_arrow_big(x, y, height, event) | 392 | self.canvas.add_sel_deadline_arrow_big(x, y, height, event) |
393 | 393 | ||
394 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 394 | 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: | 395 | if start_time > end_time: |
396 | raise ValueError("Litmus is not a time machine") | 396 | raise ValueError("Litmus is not a time machine") |
397 | 397 | ||
398 | x = self._get_time_xpos(start_time) | 398 | x = self.get_time_xpos(start_time) |
399 | y = self._get_item_ypos(task_no) | 399 | y = self.get_item_ypos(task_no) |
400 | width = self._get_bar_width(start_time, end_time) | 400 | width = self._get_bar_width(start_time, end_time) |
401 | height = self._get_bar_height() | 401 | height = self._get_bar_height() |
402 | 402 | ||
403 | self.canvas.draw_bar(x, y, width, height, cpu_no, clip_side, selected) | 403 | self.canvas.draw_bar(x, y, width, height, cpu_no, clip_side, selected) |
404 | 404 | ||
405 | # if a job number is specified, we want to draw a superscript and subscript for the task and job number, respectively | 405 | # if a job number is specified, we want to draw a superscript and subscript for the task and job number, respectively |
406 | if job_no is not None: | 406 | if job_no is not None: |
407 | x += GraphFormat.BAR_LABEL_OFS | 407 | x += GraphFormat.BAR_LABEL_OFS |
408 | y += self.attrs.y_item_size * GraphFormat.BAR_SIZE_FACTOR / 2.0 | 408 | y += self.attrs.y_item_size * GraphFormat.BAR_SIZE_FACTOR / 2.0 |
409 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 409 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
410 | GraphFormat.DEF_FOPTS_BAR, GraphFormat.DEF_FOPTS_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) | 410 | GraphFormat.DEF_FOPTS_BAR, GraphFormat.DEF_FOPTS_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) |
411 | 411 | ||
412 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 412 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
413 | if start_time > end_time: | 413 | if start_time > end_time: |
414 | raise ValueError("Litmus is not a time machine") | 414 | raise ValueError("Litmus is not a time machine") |
415 | 415 | ||
416 | x = self._get_time_xpos(start_time) | 416 | x = self.get_time_xpos(start_time) |
417 | y = self._get_item_ypos(task_no) | 417 | y = self.get_item_ypos(task_no) |
418 | width = self._get_bar_width(start_time, end_time) | 418 | width = self._get_bar_width(start_time, end_time) |
419 | height = self._get_bar_height() | 419 | height = self._get_bar_height() |
420 | 420 | ||
421 | self.canvas.add_sel_bar(x, y, width, height, event) | 421 | self.canvas.add_sel_bar(x, y, width, height, event) |
422 | 422 | ||
423 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 423 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): |
424 | if start_time > end_time: | 424 | if start_time > end_time: |
425 | raise ValueError("Litmus is not a time machine") | 425 | raise ValueError("Litmus is not a time machine") |
426 | 426 | ||
427 | x = self._get_time_xpos(start_time) | 427 | x = self.get_time_xpos(start_time) |
428 | y = self._get_item_ypos(task_no) - self._get_mini_bar_ofs() | 428 | y = self.get_item_ypos(task_no) - self._get_mini_bar_ofs() |
429 | width = self._get_bar_width(start_time, end_time) | 429 | width = self._get_bar_width(start_time, end_time) |
430 | height = self._get_mini_bar_height() | 430 | height = self._get_mini_bar_height() |
431 | 431 | ||
432 | self.canvas.draw_mini_bar(x, y, width, height, Canvas.NULL_PATTERN, clip_side, selected) | 432 | self.canvas.draw_mini_bar(x, y, width, height, Canvas.NULL_PATTERN, clip_side, selected) |
433 | 433 | ||
434 | if job_no is not None: | 434 | if job_no is not None: |
435 | x += GraphFormat.MINI_BAR_LABEL_OFS | 435 | x += GraphFormat.MINI_BAR_LABEL_OFS |
436 | y += self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR / 2.0 | 436 | y += self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR / 2.0 |
437 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 437 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
438 | GraphFormat.DEF_FOPTS_MINI_BAR, GraphFormat.DEF_FOPTS_MINI_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) | 438 | GraphFormat.DEF_FOPTS_MINI_BAR, GraphFormat.DEF_FOPTS_MINI_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) |
439 | 439 | ||
440 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 440 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
441 | x = self._get_time_xpos(start_time) | 441 | x = self.get_time_xpos(start_time) |
442 | y = self._get_item_ypos(task_no) - self._get_mini_bar_ofs() | 442 | y = self.get_item_ypos(task_no) - self._get_mini_bar_ofs() |
443 | width = self._get_bar_width(start_time, end_time) | 443 | width = self._get_bar_width(start_time, end_time) |
444 | height = self._get_mini_bar_height() | 444 | height = self._get_mini_bar_height() |
445 | 445 | ||
446 | self.canvas.add_sel_mini_bar(x, y, width, height, event) | 446 | self.canvas.add_sel_mini_bar(x, y, width, height, event) |
447 | 447 | ||
448 | class CpuGraph(Graph): | 448 | class CpuGraph(Graph): |
449 | def get_events_to_render(self, sched, regions, selectable=False): | 449 | def get_events_to_render(self, sched, regions, selectable=False): |
450 | BOTTOM_EVENTS = [schedule.ReleaseEvent, schedule.DeadlineEvent, schedule.InversionStartEvent, | 450 | BOTTOM_EVENTS = [schedule.ReleaseEvent, schedule.DeadlineEvent, schedule.InversionStartEvent, |
451 | schedule.InversionEndEvent, schedule.InversionDummy] | 451 | schedule.InversionEndEvent, schedule.InversionDummy] |
452 | TOP_EVENTS = [schedule.SuspendEvent, schedule.ResumeEvent, schedule.CompleteEvent, | 452 | TOP_EVENTS = [schedule.SuspendEvent, schedule.ResumeEvent, schedule.CompleteEvent, |
453 | schedule.SwitchAwayEvent, schedule.SwitchToEvent, schedule.IsRunningDummy] | 453 | schedule.SwitchAwayEvent, schedule.SwitchToEvent, schedule.IsRunningDummy] |
454 | 454 | ||
455 | if not regions: | 455 | if not regions: |
456 | return {} | 456 | return {} |
457 | 457 | ||
458 | top_slots = {} | 458 | top_slots = {} |
459 | bottom_slots = {} | 459 | bottom_slots = {} |
460 | 460 | ||
461 | self.min_time, self.max_time, self.min_item, self.max_item = None, None, None, None | 461 | self.min_time, self.max_time, self.min_item, self.max_item = None, None, None, None |
462 | for region in regions: | 462 | for region in regions: |
463 | x, y, width, height = region | 463 | x, y, width, height = region |
464 | start_time, end_time, start_item, end_item = self.get_offset_params(x, y, width, height) | 464 | start_time, end_time, start_item, end_item = self.get_offset_params(x, y, width, height) |
465 | self._recomp_min_max(start_time, end_time, start_item, end_item) | 465 | self._recomp_min_max(start_time, end_time, start_item, end_item) |
466 | 466 | ||
467 | sched.get_time_slot_array().get_slots(top_slots, | 467 | sched.get_time_slot_array().get_slots(top_slots, |
468 | start_time, end_time, start_item, end_item, | 468 | start_time, end_time, start_item, end_item, |
469 | schedule.TimeSlotArray.CPU_LIST) | 469 | schedule.TimeSlotArray.CPU_LIST) |
470 | 470 | ||
471 | if end_item >= len(self.y_item_list): | 471 | if end_item >= len(self.y_item_list): |
472 | # we are far down enough that we should render the releases and deadlines and inversions, | 472 | # we are far down enough that we should render the releases and deadlines and inversions, |
473 | # which appear near the x-axis | 473 | # which appear near the x-axis |
474 | sched.get_time_slot_array().get_slots(bottom_slots, | 474 | sched.get_time_slot_array().get_slots(bottom_slots, |
475 | start_time, end_time, 0, sched.get_num_cpus(), | 475 | start_time, end_time, 0, sched.get_num_cpus(), |
476 | schedule.TimeSlotArray.CPU_LIST) | 476 | schedule.TimeSlotArray.CPU_LIST) |
477 | 477 | ||
478 | if not selectable: | 478 | if not selectable: |
479 | self.draw_skeleton(self.min_time, self.max_time, | 479 | self.draw_skeleton(self.min_time, self.max_time, |
480 | self.min_item, self.max_item) | 480 | self.min_item, self.max_item) |
481 | 481 | ||
482 | events_to_render = {} | 482 | events_to_render = {} |
483 | for layer in Canvas.LAYERS: | 483 | for layer in Canvas.LAYERS: |
484 | events_to_render[layer] = {} | 484 | events_to_render[layer] = {} |
485 | 485 | ||
486 | for event in sched.get_time_slot_array().get_events(top_slots, | 486 | for event in sched.get_time_slot_array().get_events(top_slots, |
487 | schedule.TimeSlotArray.CPU_LIST, | 487 | schedule.TimeSlotArray.CPU_LIST, |
488 | TOP_EVENTS): | 488 | TOP_EVENTS): |
489 | events_to_render[event.get_layer()][event] = None | 489 | events_to_render[event.get_layer()][event] = None |
490 | for event in sched.get_time_slot_array().get_events(bottom_slots, | 490 | for event in sched.get_time_slot_array().get_events(bottom_slots, |
491 | schedule.TimeSlotArray.CPU_LIST, | 491 | schedule.TimeSlotArray.CPU_LIST, |
492 | BOTTOM_EVENTS): | 492 | BOTTOM_EVENTS): |
493 | events_to_render[event.get_layer()][event] = None | 493 | events_to_render[event.get_layer()][event] = None |
494 | 494 | ||
495 | return events_to_render | 495 | return events_to_render |
496 | 496 | ||
497 | def render(self, schedule, start_time=None, end_time=None): | 497 | def render(self, schedule, start_time=None, end_time=None): |
498 | if end_time < start_time: | 498 | if end_time < start_time: |
499 | raise ValueError('start must be less than end') | 499 | raise ValueError('start must be less than end') |
500 | 500 | ||
501 | if start_time is None: | 501 | if start_time is None: |
502 | start_time = self.start | 502 | start_time = self.start |
503 | if end_time is None: | 503 | if end_time is None: |
504 | end_time = self.end | 504 | end_time = self.end |
505 | start_slot = self.get_time_slot(start_time) | 505 | start_slot = self.get_time_slot(start_time) |
506 | end_slot = min(len(self.time_slots), self.get_time_slot(end_time) + 1) | 506 | end_slot = min(len(self.time_slots), self.get_time_slot(end_time) + 1) |
507 | 507 | ||
508 | for layer in Canvas.LAYERS: | 508 | for layer in Canvas.LAYERS: |
509 | prev_events = {} | 509 | prev_events = {} |
510 | for i in range(start_slot, end_slot): | 510 | for i in range(start_slot, end_slot): |
511 | for event in self.time_slots[i]: | 511 | for event in self.time_slots[i]: |
512 | event.render(graph, layer, prev_events) | 512 | event.render(graph, layer, prev_events) |
513 | 513 | ||
514 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 514 | def draw_suspend_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
515 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 515 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
516 | x = self._get_time_xpos(time) | 516 | x = self.get_time_xpos(time) |
517 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 | 517 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 |
518 | self.canvas.draw_suspend_triangle(x, y, height, selected) | 518 | self.canvas.draw_suspend_triangle(x, y, height, selected) |
519 | 519 | ||
520 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): | 520 | def add_sel_suspend_triangle_at_time(self, time, task_no, cpu_no, event): |
521 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 521 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
522 | x = self._get_time_xpos(time) | 522 | x = self.get_time_xpos(time) |
523 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 | 523 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 |
524 | 524 | ||
525 | self.canvas.add_sel_suspend_triangle(x, y, height, event) | 525 | self.canvas.add_sel_suspend_triangle(x, y, height, event) |
526 | 526 | ||
527 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): | 527 | def draw_resume_triangle_at_time(self, time, task_no, cpu_no, selected=False): |
528 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 528 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
529 | x = self._get_time_xpos(time) | 529 | x = self.get_time_xpos(time) |
530 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 | 530 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 |
531 | 531 | ||
532 | self.canvas.draw_resume_triangle(x, y, height, selected) | 532 | self.canvas.draw_resume_triangle(x, y, height, selected) |
533 | 533 | ||
534 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): | 534 | def add_sel_resume_triangle_at_time(self, time, task_no, cpu_no, event): |
535 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR | 535 | height = self._get_bar_height() * GraphFormat.BLOCK_TRIANGLE_FACTOR |
536 | x = self._get_time_xpos(time) | 536 | x = self.get_time_xpos(time) |
537 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 | 537 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() / 2.0 - height / 2.0 |
538 | 538 | ||
539 | self.canvas.add_sel_resume_triangle(x, y, height, event) | 539 | self.canvas.add_sel_resume_triangle(x, y, height, event) |
540 | 540 | ||
541 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): | 541 | def draw_completion_marker_at_time(self, time, task_no, cpu_no, selected=False): |
542 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR | 542 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR |
543 | x = self._get_time_xpos(time) | 543 | x = self.get_time_xpos(time) |
544 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() - height | 544 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() - height |
545 | 545 | ||
546 | self.canvas.draw_completion_marker(x, y, height, selected) | 546 | self.canvas.draw_completion_marker(x, y, height, selected) |
547 | 547 | ||
548 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): | 548 | def add_sel_completion_marker_at_time(self, time, task_no, cpu_no, event): |
549 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR | 549 | height = self._get_bar_height() * GraphFormat.COMPLETION_MARKER_FACTOR |
550 | 550 | ||
551 | x = self._get_time_xpos(time) | 551 | x = self.get_time_xpos(time) |
552 | y = self._get_item_ypos(cpu_no) + self._get_bar_height() - height | 552 | y = self.get_item_ypos(cpu_no) + self._get_bar_height() - height |
553 | 553 | ||
554 | self.canvas.add_sel_completion_marker(x, y, height, event) | 554 | self.canvas.add_sel_completion_marker(x, y, height, event) |
555 | 555 | ||
556 | def draw_release_arrow_at_time(self, time, task_no, job_no=None, selected=False): | 556 | def draw_release_arrow_at_time(self, time, task_no, job_no=None, selected=False): |
557 | if job_no is None and task_no is not None: | 557 | if job_no is None and task_no is not None: |
558 | raise ValueError("Must specify a job number along with the task number") | 558 | raise ValueError("Must specify a job number along with the task number") |
559 | 559 | ||
560 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR | 560 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR |
561 | 561 | ||
562 | x = self._get_time_xpos(time) | 562 | x = self.get_time_xpos(time) |
563 | y = self.origin[1] - height | 563 | y = self.origin[1] - height |
564 | 564 | ||
565 | self.canvas.draw_release_arrow_small(x, y, height, selected) | 565 | self.canvas.draw_release_arrow_small(x, y, height, selected) |
566 | 566 | ||
567 | if task_no is not None: | 567 | if task_no is not None: |
568 | y -= GraphFormat.ARROW_LABEL_OFS | 568 | y -= GraphFormat.ARROW_LABEL_OFS |
569 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 569 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
570 | GraphFormat.DEF_FOPTS_ARROW, GraphFormat.DEF_FOPTS_ARROW_SSCRIPT, \ | 570 | GraphFormat.DEF_FOPTS_ARROW, GraphFormat.DEF_FOPTS_ARROW_SSCRIPT, \ |
571 | AlignMode.CENTER, AlignMode.BOTTOM) | 571 | AlignMode.CENTER, AlignMode.BOTTOM) |
572 | 572 | ||
573 | def add_sel_release_arrow_at_time(self, time, task_no, event): | 573 | def add_sel_release_arrow_at_time(self, time, task_no, event): |
574 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR | 574 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR |
575 | 575 | ||
576 | x = self._get_time_xpos(time) | 576 | x = self.get_time_xpos(time) |
577 | y = self.origin[1] - height | 577 | y = self.origin[1] - height |
578 | 578 | ||
579 | self.canvas.add_sel_release_arrow_small(x, y, height, event) | 579 | self.canvas.add_sel_release_arrow_small(x, y, height, event) |
580 | 580 | ||
581 | def draw_deadline_arrow_at_time(self, time, task_no, job_no=None, selected=False): | 581 | def draw_deadline_arrow_at_time(self, time, task_no, job_no=None, selected=False): |
582 | if job_no is None and task_no is not None: | 582 | if job_no is None and task_no is not None: |
583 | raise ValueError("Must specify a job number along with the task number") | 583 | raise ValueError("Must specify a job number along with the task number") |
584 | 584 | ||
585 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR | 585 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR |
586 | 586 | ||
587 | x = self._get_time_xpos(time) | 587 | x = self.get_time_xpos(time) |
588 | y = self.origin[1] - height | 588 | y = self.origin[1] - height |
589 | 589 | ||
590 | self.canvas.draw_deadline_arrow_small(x, y, height, selected) | 590 | self.canvas.draw_deadline_arrow_small(x, y, height, selected) |
591 | 591 | ||
592 | if task_no is not None: | 592 | if task_no is not None: |
593 | y -= GraphFormat.ARROW_LABEL_OFS | 593 | y -= GraphFormat.ARROW_LABEL_OFS |
594 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 594 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
595 | GraphFormat.DEF_FOPTS_ARROW, GraphFormat.DEF_FOPTS_ARROW_SSCRIPT, \ | 595 | GraphFormat.DEF_FOPTS_ARROW, GraphFormat.DEF_FOPTS_ARROW_SSCRIPT, \ |
596 | AlignMode.CENTER, AlignMode.BOTTOM) | 596 | AlignMode.CENTER, AlignMode.BOTTOM) |
597 | 597 | ||
598 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): | 598 | def add_sel_deadline_arrow_at_time(self, time, task_no, event): |
599 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR | 599 | height = self._get_bar_height() * GraphFormat.SMALL_ARROW_FACTOR |
600 | 600 | ||
601 | x = self._get_time_xpos(time) | 601 | x = self.get_time_xpos(time) |
602 | y = self.origin[1] - height | 602 | y = self.origin[1] - height |
603 | 603 | ||
604 | self.canvas.add_sel_deadline_arrow_small(x, y, height, event) | 604 | self.canvas.add_sel_deadline_arrow_small(x, y, height, event) |
605 | 605 | ||
606 | def draw_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 606 | 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: | 607 | if start_time > end_time: |
608 | raise ValueError("Litmus is not a time machine") | 608 | raise ValueError("Litmus is not a time machine") |
609 | 609 | ||
610 | x = self._get_time_xpos(start_time) | 610 | x = self.get_time_xpos(start_time) |
611 | y = self._get_item_ypos(cpu_no) | 611 | y = self.get_item_ypos(cpu_no) |
612 | width = self._get_bar_width(start_time, end_time) | 612 | width = self._get_bar_width(start_time, end_time) |
613 | height = self._get_bar_height() | 613 | height = self._get_bar_height() |
614 | 614 | ||
615 | self.canvas.draw_bar(x, y, width, height, task_no, clip_side, selected) | 615 | self.canvas.draw_bar(x, y, width, height, task_no, clip_side, selected) |
616 | 616 | ||
617 | # if a job number is specified, we want to draw a superscript and subscript for the task and job number, respectively | 617 | # if a job number is specified, we want to draw a superscript and subscript for the task and job number, respectively |
618 | if job_no is not None: | 618 | if job_no is not None: |
619 | x += GraphFormat.BAR_LABEL_OFS | 619 | x += GraphFormat.BAR_LABEL_OFS |
@@ -621,37 +621,37 @@ class CpuGraph(Graph): | |||
621 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 621 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
622 | GraphFormat.DEF_FOPTS_BAR, GraphFormat.DEF_FOPTS_BAR_SSCRIPT, \ | 622 | GraphFormat.DEF_FOPTS_BAR, GraphFormat.DEF_FOPTS_BAR_SSCRIPT, \ |
623 | AlignMode.LEFT, AlignMode.CENTER) | 623 | AlignMode.LEFT, AlignMode.CENTER) |
624 | 624 | ||
625 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 625 | def add_sel_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
626 | x = self._get_time_xpos(start_time) | 626 | x = self.get_time_xpos(start_time) |
627 | y = self._get_item_ypos(cpu_no) | 627 | y = self.get_item_ypos(cpu_no) |
628 | width = self._get_bar_width(start_time, end_time) | 628 | width = self._get_bar_width(start_time, end_time) |
629 | height = self._get_bar_height() | 629 | height = self._get_bar_height() |
630 | 630 | ||
631 | self.canvas.add_sel_bar(x, y, width, height, event) | 631 | self.canvas.add_sel_bar(x, y, width, height, event) |
632 | 632 | ||
633 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): | 633 | def draw_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, job_no=None, clip_side=None, selected=False): |
634 | if start_time > end_time: | 634 | if start_time > end_time: |
635 | raise ValueError("Litmus is not a time machine") | 635 | raise ValueError("Litmus is not a time machine") |
636 | 636 | ||
637 | x = self._get_time_xpos(start_time) | 637 | x = self.get_time_xpos(start_time) |
638 | y = self._get_item_ypos(len(self.y_item_list)) | 638 | y = self.get_item_ypos(len(self.y_item_list)) |
639 | width = self._get_bar_width(start_time, end_time) | 639 | width = self._get_bar_width(start_time, end_time) |
640 | height = self._get_mini_bar_height() | 640 | height = self._get_mini_bar_height() |
641 | 641 | ||
642 | self.canvas.draw_mini_bar(x, y, width, height, task_no, clip_side, selected) | 642 | self.canvas.draw_mini_bar(x, y, width, height, task_no, clip_side, selected) |
643 | 643 | ||
644 | if job_no is not None: | 644 | if job_no is not None: |
645 | x += GraphFormat.MINI_BAR_LABEL_OFS | 645 | x += GraphFormat.MINI_BAR_LABEL_OFS |
646 | y += self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR / 2.0 | 646 | y += self.attrs.y_item_size * GraphFormat.MINI_BAR_SIZE_FACTOR / 2.0 |
647 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ | 647 | self.canvas.draw_label_with_sscripts('T', str(task_no), str(job_no), x, y, \ |
648 | GraphFormat.DEF_FOPTS_MINI_BAR, GraphFormat.DEF_FOPTS_MINI_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) | 648 | GraphFormat.DEF_FOPTS_MINI_BAR, GraphFormat.DEF_FOPTS_MINI_BAR_SSCRIPT, AlignMode.LEFT, AlignMode.CENTER) |
649 | 649 | ||
650 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): | 650 | def add_sel_mini_bar_at_time(self, start_time, end_time, task_no, cpu_no, event): |
651 | x = self._get_time_xpos(start_time) | 651 | x = self.get_time_xpos(start_time) |
652 | y = self._get_item_ypos(len(self.y_item_list)) | 652 | y = self.get_item_ypos(len(self.y_item_list)) |
653 | width = self._get_bar_width(start_time, end_time) | 653 | width = self._get_bar_width(start_time, end_time) |
654 | height = self._get_mini_bar_height() | 654 | height = self._get_mini_bar_height() |
655 | 655 | ||
656 | self.canvas.add_sel_mini_bar(x, y, width, height, event) | 656 | self.canvas.add_sel_mini_bar(x, y, width, height, event) |
657 | 657 | ||