aboutsummaryrefslogtreecommitdiff
path: root/devlib/instrument/frames.py
blob: d5a2147814a838fbef0592f993fec0cb4c6a3d9f (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from devlib.instrument import (Instrument, CONTINUOUS,
                               MeasurementsCsv, MeasurementType)
from devlib.utils.rendering import (GfxinfoFrameCollector,
                                    SurfaceFlingerFrameCollector,
                                    SurfaceFlingerFrame,
                                    read_gfxinfo_columns)


class FramesInstrument(Instrument):

    mode = CONTINUOUS
    collector_cls = None

    def __init__(self, target, collector_target, period=2, keep_raw=True):
        super(FramesInstrument, self).__init__(target)
        self.collector_target = collector_target
        self.period = period
        self.keep_raw = keep_raw
        self.collector = None
        self.header = None
        self._need_reset = True
        self._init_channels()

    def reset(self, sites=None, kinds=None, channels=None):
        super(FramesInstrument, self).reset(sites, kinds, channels)
        self.collector = self.collector_cls(self.target, self.period,
                                            self.collector_target, self.header)
        self._need_reset = False

    def start(self):
        if self._need_reset:
            self.reset()
        self.collector.start()

    def stop(self):
        self.collector.stop()
        self._need_reset = True

    def get_data(self, outfile):
        raw_outfile = None
        if self.keep_raw:
            raw_outfile = outfile + '.raw'
        self.collector.process_frames(raw_outfile)
        active_sites = [chan.label for chan in self.active_channels]
        self.collector.write_frames(outfile, columns=active_sites)
        return MeasurementsCsv(outfile, self.active_channels)

    def _init_channels(self):
        raise NotImplementedError()


class GfxInfoFramesInstrument(FramesInstrument):

    mode = CONTINUOUS
    collector_cls = GfxinfoFrameCollector

    def _init_channels(self):
        columns = read_gfxinfo_columns(self.target)
        for entry in columns:
            if entry == 'Flags':
                self.add_channel('Flags', MeasurementType('flags', 'flags'))
            else:
                self.add_channel(entry, 'time_us')
        self.header = [chan.label for chan in self.channels.values()]


class SurfaceFlingerFramesInstrument(FramesInstrument):

    mode = CONTINUOUS
    collector_cls = SurfaceFlingerFrameCollector

    def _init_channels(self):
        for field in SurfaceFlingerFrame._fields:
            # remove the "_time" from filed names to avoid duplication
            self.add_channel(field[:-5], 'time_us')
        self.header = [chan.label for chan in self.channels.values()]