Home | History | Annotate | Download | only in timeline
      1 # Copyright (c) 2013 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 class TimelineEvent(object):
      6   """Represents a timeline event.
      7 
      8      thread_start, thread_duration and thread_end are the start time, duration
      9      and end time of this event as measured by the thread-specific CPU clock
     10      (ticking when the thread is actually scheduled). Thread time is optional
     11      on trace events and the corresponding attributes in TimelineEvent will be
     12      set to None (not 0) if not present. Users of this class need to properly
     13      handle this case.
     14   """
     15   def __init__(self, category, name, start, duration, thread_start=None,
     16                thread_duration=None, args=None):
     17     self.category = category
     18     self.name = name
     19     self.start = start
     20     self.duration = duration
     21     self.thread_start = thread_start
     22     self.thread_duration = thread_duration
     23     self.args = args
     24 
     25   @property
     26   def end(self):
     27     return self.start + self.duration
     28 
     29   @property
     30   def thread_end(self):
     31     """Thread-specific CPU time when this event ended.
     32 
     33        May be None if the trace event didn't have thread time data.
     34     """
     35     if self.thread_start == None or self.thread_duration == None:
     36       return None
     37     return self.thread_start + self.thread_duration
     38 
     39   def __repr__(self):
     40     if self.args:
     41       args_str = ', ' + repr(self.args)
     42     else:
     43       args_str = ''
     44 
     45     return ("TimelineEvent(name='%s', start=%f, duration=%s, " +
     46             "thread_start=%s, thread_duration=%s%s)") % (
     47                 self.name,
     48                 self.start,
     49                 self.duration,
     50                 self.thread_start,
     51                 self.thread_duration,
     52                 args_str)
     53