 Chromium Code Reviews
 Chromium Code Reviews Issue 19772005:
  [telemetry] Timeline model cleanups  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 19772005:
  [telemetry] Timeline model cleanups  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be | 
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. | 
| 4 | 4 | 
| 5 import telemetry.core.timeline.event as timeline_event | 5 import telemetry.core.timeline.event_container as event_container | 
| 6 import telemetry.core.timeline.tracing.counter as tracing_counter | 6 import telemetry.core.timeline.counter as tracing_counter | 
| 7 import telemetry.core.timeline.tracing.thread as tracing_thread | 7 import telemetry.core.timeline.thread as tracing_thread | 
| 8 | 8 | 
| 9 class Process(timeline_event.TimelineEvent): | 9 class Process(event_container.TimelineEventContainer): | 
| 10 ''' The Process represents a single userland process in the trace. | 10 ''' The Process represents a single userland process in the trace. | 
| 11 ''' | 11 ''' | 
| 12 def __init__(self, pid): | 12 def __init__(self, parent, pid): | 
| 13 super(Process, self).__init__('process %s' % pid, 0, 0) | 13 super(Process, self).__init__('process %s' % pid, parent) | 
| 14 self.pid = pid | 14 self.pid = pid | 
| 15 self._threads = [] | 15 self._threads = {} | 
| 16 self._counters = {} | 16 self._counters = {} | 
| 17 | 17 | 
| 18 @property | 18 @property | 
| 19 def threads(self): | 19 def threads(self): | 
| 20 return self._threads | 20 return self._threads | 
| 21 | 21 | 
| 22 @property | 22 @property | 
| 23 def counters(self): | 23 def counters(self): | 
| 24 return self._counters | 24 return self._counters | 
| 25 | 25 | 
| 26 def GetThreadWithId(self, tid): | 26 def IterChildContainers(self): | 
| 27 for t in self.threads: | 27 for thread in self._threads.itervalues(): | 
| 28 if t.tid == tid: | 28 yield thread | 
| 29 return t | 29 for counter in self._counters.itervalues(): | 
| 30 raise ValueError( | 30 yield counter | 
| 31 'Thread with id %s not found in process with id %s.' % (tid, self.pid)) | 31 | 
| 32 def IterEventsInThisContainer(self): | |
| 33 return | |
| 
Tim Song
2013/07/18 22:56:36
This seems a bit too clever. We can just return it
 | |
| 34 yield # pylint: disable=W0101 | |
| 32 | 35 | 
| 33 def GetOrCreateThread(self, tid): | 36 def GetOrCreateThread(self, tid): | 
| 34 try: | 37 thread = self.threads.get(tid, None) | 
| 35 return self.GetThreadWithId(tid) | 38 if thread: | 
| 36 except ValueError: | |
| 37 thread = tracing_thread.Thread(self, tid) | |
| 38 self.children.append(thread) | |
| 39 self._threads.append(thread) | |
| 40 return thread | 39 return thread | 
| 40 thread = tracing_thread.Thread(self, tid) | |
| 41 self._threads[tid] = thread | |
| 42 return thread | |
| 41 | 43 | 
| 42 def GetCounter(self, category, name): | 44 def GetCounter(self, category, name): | 
| 43 counter_id = category + '.' + name | 45 counter_id = category + '.' + name | 
| 44 if counter_id in self.counters: | 46 if counter_id in self.counters: | 
| 45 return self.counters[counter_id] | 47 return self.counters[counter_id] | 
| 46 raise ValueError( | 48 raise ValueError( | 
| 47 'Counter %s not found in process with id %s.' % (counter_id, | 49 'Counter %s not found in process with id %s.' % (counter_id, | 
| 48 self.pid)) | 50 self.pid)) | 
| 49 def GetOrCreateCounter(self, category, name): | 51 def GetOrCreateCounter(self, category, name): | 
| 50 try: | 52 try: | 
| 51 return self.GetCounter(category, name) | 53 return self.GetCounter(category, name) | 
| 52 except ValueError: | 54 except ValueError: | 
| 53 ctr = tracing_counter.Counter(self, category, name) | 55 ctr = tracing_counter.Counter(self, category, name) | 
| 54 self._counters[ctr.full_name] = ctr | 56 self._counters[ctr.full_name] = ctr | 
| 55 return ctr | 57 return ctr | 
| 56 | 58 | 
| 57 def UpdateBounds(self): | 59 def AutoCloseOpenSlices(self, max_timestamp): | 
| 58 super(Process, self).UpdateBounds() | 60 for thread in self._threads.itervalues(): | 
| 59 for ctr in self.counters.itervalues(): | 61 thread.AutoCloseOpenSlices(max_timestamp) | 
| 60 ctr.UpdateBounds() | |
| 61 | 62 | 
| 62 def FinalizeImport(self): | 63 def FinalizeImport(self): | 
| 63 for thread in self._threads: | 64 for thread in self._threads.itervalues(): | 
| 64 thread.FinalizeImport() | 65 thread.FinalizeImport() | 
| 66 for counter in self._counters.itervalues(): | |
| 67 counter.FinalizeImport() | |
| OLD | NEW |