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
3 # found in the LICENSE file.
5 import telemetry.core.timeline.event_container as event_container
6 import telemetry.core.timeline.counter as tracing_counter
7 import telemetry.core.timeline.thread as tracing_thread
9 class Process(event_container.TimelineEventContainer):
10 ''' The Process represents a single userland process in the trace.
12 def __init__(self, parent, pid):
13 super(Process, self).__init__('process %s' % pid, parent)
26 def IterChildContainers(self):
27 for thread in self._threads.itervalues():
29 for counter in self._counters.itervalues():
32 def IterAllSlicesOfName(self, name):
33 for thread in self._threads.itervalues():
34 for s in thread.IterAllSlicesOfName(name):
37 def IterAllAsyncSlicesOfName(self, name):
38 for thread in self._threads.itervalues():
39 for s in thread.IterAllAsyncSlicesOfName(name):
42 def IterEventsInThisContainer(self):
44 yield # pylint: disable=W0101
46 def GetOrCreateThread(self, tid):
47 thread = self.threads.get(tid, None)
50 thread = tracing_thread.Thread(self, tid)
51 self._threads[tid] = thread
54 def GetCounter(self, category, name):
55 counter_id = category + '.' + name
56 if counter_id in self.counters:
57 return self.counters[counter_id]
59 'Counter %s not found in process with id %s.' % (counter_id,
61 def GetOrCreateCounter(self, category, name):
63 return self.GetCounter(category, name)
65 ctr = tracing_counter.Counter(self, category, name)
66 self._counters[ctr.full_name] = ctr
69 def AutoCloseOpenSlices(self, max_timestamp, thread_time_bounds):
70 for thread in self._threads.itervalues():
71 thread.AutoCloseOpenSlices(max_timestamp, thread_time_bounds[thread].max)
73 def FinalizeImport(self):
74 for thread in self._threads.itervalues():
75 thread.FinalizeImport()
76 for counter in self._counters.itervalues():
77 counter.FinalizeImport()