From 1d3b4c80627240db9c199688b1511f16bc25e142 Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Tue, 6 Jun 2017 17:34:59 +0100
Subject: [PATCH] instrument/frames: Add surfaceflinger frames instrument

Add an instrument that utilizes the SurfaceFringerFrameCollector.
---
 devlib/instrument/frames.py | 37 ++++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/devlib/instrument/frames.py b/devlib/instrument/frames.py
index be6f39b..d5a2147 100644
--- a/devlib/instrument/frames.py
+++ b/devlib/instrument/frames.py
@@ -1,16 +1,19 @@
 from devlib.instrument import (Instrument, CONTINUOUS,
                                MeasurementsCsv, MeasurementType)
 from devlib.utils.rendering import (GfxinfoFrameCollector,
+                                    SurfaceFlingerFrameCollector,
+                                    SurfaceFlingerFrame,
                                     read_gfxinfo_columns)
 
 
-class GfxInfoFramesInstrument(Instrument):
+class FramesInstrument(Instrument):
 
     mode = CONTINUOUS
+    collector_cls = None
 
-    def __init__(self, target, package, period=2, keep_raw=True):
-        super(GfxInfoFramesInstrument, self).__init__(target)
-        self.package = package
+    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
@@ -19,9 +22,9 @@ class GfxInfoFramesInstrument(Instrument):
         self._init_channels()
 
     def reset(self, sites=None, kinds=None, channels=None):
-        super(GfxInfoFramesInstrument, self).reset(sites, kinds, channels)
-        self.collector = GfxinfoFrameCollector(self.target, self.period,
-                                               self.package, self.header)
+        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):
@@ -42,6 +45,15 @@ class GfxInfoFramesInstrument(Instrument):
         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:
@@ -51,3 +63,14 @@ class GfxInfoFramesInstrument(Instrument):
                 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()]