Home | History | Annotate | Download | only in profile_chrome
      1 # Copyright 2016 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import optparse
      6 import tempfile
      7 
      8 from systrace import trace_result
      9 from systrace import tracing_agents
     10 
     11 
     12 class FakeAgent(object):
     13   def __init__(self, contents='fake-contents'):
     14     self.contents = contents
     15     self.stopped = False
     16     self.filename = None
     17     self.config = None
     18     self.timeout = None
     19 
     20   def StartAgentTracing(self, config, timeout=None):
     21     self.config = config
     22     self.timeout = timeout
     23     return True
     24 
     25   # pylint: disable=unused-argument
     26   def StopAgentTracing(self, timeout=None):
     27     self.stopped = True
     28     return True
     29 
     30   # pylint: disable=unused-argument
     31   def GetResults(self, timeout=None):
     32     trace_data = open(self._PullTrace()).read()
     33     return trace_result.TraceResult('fakeData', trace_data)
     34 
     35   def _PullTrace(self):
     36     with tempfile.NamedTemporaryFile(delete=False) as f:
     37       self.filename = f.name
     38       f.write(self.contents)
     39       return f.name
     40 
     41   # pylint: disable=no-self-use
     42   def SupportsExplicitClockSync(self):
     43     return False
     44 
     45   # pylint: disable=unused-argument, no-self-use
     46   def RecordClockSyncMarker(self, sync_id, did_record_sync_marker_callback):
     47     print ('Clock sync marker cannot be recorded since explicit clock sync '
     48            'is not supported.')
     49 
     50   def __repr__(self):
     51     return 'faketrace'
     52 
     53 
     54 class FakeConfig(tracing_agents.TracingConfig):
     55   def __init__(self):
     56     tracing_agents.TracingConfig.__init__(self)
     57 
     58 
     59 # pylint: disable=unused-argument
     60 def try_create_agent(config):
     61   return FakeAgent()
     62 
     63 def add_options(parser):
     64   options = optparse.OptionGroup(parser, 'Fake options.')
     65   return options
     66 
     67 # pylint: disable=unused-argument
     68 def get_config(options):
     69   return FakeConfig()
     70