Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / timeline / process.py
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.
4
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
8
9 class Process(event_container.TimelineEventContainer):
10   ''' The Process represents a single userland process in the trace.
11   '''
12   def __init__(self, parent, pid):
13     super(Process, self).__init__('process %s' % pid, parent)
14     self.pid = pid
15     self._threads = {}
16     self._counters = {}
17
18   @property
19   def threads(self):
20     return self._threads
21
22   @property
23   def counters(self):
24     return self._counters
25
26   def IterChildContainers(self):
27     for thread in self._threads.itervalues():
28       yield thread
29     for counter in self._counters.itervalues():
30       yield counter
31
32   def IterAllSlicesOfName(self, name):
33     for thread in self._threads.itervalues():
34       for s in thread.IterAllSlicesOfName(name):
35         yield s
36
37   def IterAllAsyncSlicesOfName(self, name):
38     for thread in self._threads.itervalues():
39       for s in thread.IterAllAsyncSlicesOfName(name):
40         yield s
41
42   def IterEventsInThisContainer(self):
43     return
44     yield # pylint: disable=W0101
45
46   def GetOrCreateThread(self, tid):
47     thread = self.threads.get(tid, None)
48     if thread:
49       return thread
50     thread = tracing_thread.Thread(self, tid)
51     self._threads[tid] = thread
52     return thread
53
54   def GetCounter(self, category, name):
55     counter_id = category + '.' + name
56     if counter_id in self.counters:
57       return self.counters[counter_id]
58     raise ValueError(
59         'Counter %s not found in process with id %s.' % (counter_id,
60                                                          self.pid))
61   def GetOrCreateCounter(self, category, name):
62     try:
63       return self.GetCounter(category, name)
64     except ValueError:
65       ctr = tracing_counter.Counter(self, category, name)
66       self._counters[ctr.full_name] = ctr
67       return ctr
68
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)
72
73   def FinalizeImport(self):
74     for thread in self._threads.itervalues():
75       thread.FinalizeImport()
76     for counter in self._counters.itervalues():
77       counter.FinalizeImport()