summaryrefslogtreecommitdiffstats
path: root/unit_trace/viz/renderer.py
blob: 056e1a54d1a35d1b2d04dee30c3c6ae9fa7bf431 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/python
from schedule import *
from graph import *

"""The renderer, a glue object which converts a schedule to its representation
on a graph."""

class Renderer(object):
    def __init__(self, schedule):
        self.schedule = schedule

    def prepare_task_graph(self, SurfaceType=ImageSurface, attrs=GraphFormat()):
        """Outputs the fully-rendered graph (y-axis = tasks) to a Cairo ImageSurface"""
        item_list = self.get_task_item_list()
        start, end = self.schedule.get_time_bounds()
        self.graph = TaskGraph(CairoCanvas, SurfaceType(), start, end, item_list, attrs)

    def prepare_cpu_graph(self, SurfaceType=ImageSurface, attrs=GraphFormat()):
        item_list = ['CPU %d' % i for i in range(0, self.schedule.get_num_cpus())]
        start, end = self.schedule.get_time_bounds()
        self.graph = CpuGraph(CairoCanvas, SurfaceType(), start, end, item_list, attrs)

    def render_graph_full(self):
        """Does the heavy lifting for rendering a task or CPU graph, by scanning the schedule
        and drawing it piece by piece"""
        #graph.draw_axes('Time', '')
        self.schedule.render(self.graph)

    def write_out(self, fname):
        self.graph.surface.write_out(fname)

    def get_graph(self):
        return self.graph

    def get_schedule(self):
        return self.schedule

    def get_task_item_list(self):
        return [task.get_name() for task in self.schedule.get_task_list()]