Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: tools/telemetry/telemetry/core/timeline/slice.py

Issue 19772005: [telemetry] Timeline model cleanups (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix parenting Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 as timeline_event
6
7 class Slice(timeline_event.TimelineEvent):
8 """A Slice represents an interval of time plus parameters associated
9 with that interval.
10
11 NOTE: The Sample class implements the same interface as
12 Slice. These must be kept in sync.
13
14 All time units are stored in milliseconds.
15 """
16 def __init__(self, parent_thread, category, name, timestamp,
17 args=None, duration=0):
18 super(Slice, self).__init__(
19 category, name, timestamp, duration, args=args)
20 self.parent_thread = parent_thread
21 self.parent_slice = None
22 self.sub_slices = []
23 self.did_not_finish = False
24
25 def AddSubSlice(self, sub_slice):
26 assert sub_slice.parent_slice == self
Tim Song 2013/07/18 22:56:36 We should just assign the parent_slice here instea
27 self.sub_slices.append(sub_slice)
28
29 def IterEventsInThisContainerRecrusively(self):
30 for sub_slice in self.sub_slices:
31 yield sub_slice
32 for sub_sub in sub_slice.IterEventsInThisContainerRecrusively():
33 yield sub_sub
34
35 @property
36 def self_time(self):
37 """Time spent in this function less any time spent in child events."""
38 child_total = sum(
39 [e.duration for e in self.sub_slices])
40 return self.duration - child_total
41
42 def _GetSubSlicesRecursive(self):
43 for sub_slice in self.sub_slices:
44 for s in sub_slice.GetAllSubSlices():
45 yield s
46 yield sub_slice
47
48 def GetAllSubSlices(self):
49 return list(self._GetSubSlicesRecursive())
50
51 def GetAllSubSlicesOfName(self, name):
52 return [e for e in self.GetAllSubSlices() if e.name == name]
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698