(self, events = None, trace_filename = None)
Utility class for filtering and manipulating trace data.

    events -- An iterable object containing trace events
    trace_filename -- A file object that contains a complete trace.
Utility class for filtering and manipulating trace data.
Utility class for filtering and manipulating trace data .
def __init__(self, events = None, trace_filename = None):
    """
    Utility class for filtering and manipulating trace data.

    events -- An iterable object containing trace events
    trace_filename -- A file object that contains a complete trace.

    """
    if trace_filename and events:
      raise Exception("Provide either a trace file or event list")
    if not trace_filename and events == None:
      raise Exception("Provide either a trace file or event list")

    if trace_filename:
      f = open(trace_filename, 'r')
      t = f.read()
      f.close()

      # If the event data begins with a [, then we know it should end with a ].
      # The reason we check for this is because some tracing implementations
      # cannot guarantee that a ']' gets written to the trace file. So, we are
      # forgiving and if this is obviously the case, we fix it up before
      # throwing the string at JSON.parse.
      if t[0] == '[':
        n = len(t);
        if t[n - 1] != ']' and t[n - 1] != '\n':
          t = t + ']'
        elif t[n - 2] != ']' and t[n - 1] == '\n':
          t = t + ']'
        elif t[n - 3] != ']' and t[n - 2] == '\r' and t[n - 1] == '\n':
          t = t + ']'

      try:
        events = json.loads(t)
      except ValueError:
        raise Exception("Corrupt trace, did not parse. Value: %s" % t)

      if 'traceEvents' in events:
        events = events['traceEvents']

    if not hasattr(events, '__iter__'):
      raise Exception, 'events must be iteraable.'
    self.events = events
    self.pids = None
    self.tids = None
def __init__ ( self , events = None , trace_filename = None ) : if trace_filename and events : raise Exception ( "Provide either a trace file or event list" ) if not trace_filename and events == None : raise Exception ( "Provide either a trace file or event list" ) if trace_filename : f = open ( trace_filename , 'r' ) t = f . read ( ) f . close ( ) # If the event data begins with a [, then we know it should end with a ]. # The reason we check for this is because some tracing implementations # cannot guarantee that a ']' gets written to the trace file. So, we are # forgiving and if this is obviously the case, we fix it up before # throwing the string at JSON.parse. if t [ 0 ] == '[' : n = len ( t ) if t [ n - 1 ] != ']' and t [ n - 1 ] != '\n' : t = t + ']' elif t [ n - 2 ] != ']' and t [ n - 1 ] == '\n' : t = t + ']' elif t [ n - 3 ] != ']' and t [ n - 2 ] == '\r' and t [ n - 1 ] == '\n' : t = t + ']' try : events = json . loads ( t ) except ValueError : raise Exception ( "Corrupt trace, did not parse. Value: %s" % t ) if 'traceEvents' in events : events = events [ 'traceEvents' ] if not hasattr ( events , '__iter__' ) : raise Exception , 'events must be iteraable.' self . events = events self . pids = None self . tids = None