1# Copyright 2014 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
5import telemetry.timeline.event as event
6
7
8class AsyncSlice(event.TimelineEvent):
9  """An AsyncSlice represents an interval of time during which an
10  asynchronous operation is in progress. An AsyncSlice consumes no CPU time
11  itself and so is only associated with Threads at its start and end point.
12  """
13  def __init__(self, category, name, timestamp, args=None,
14               duration=0, start_thread=None, end_thread=None,
15               thread_start=None, thread_duration=None):
16    super(AsyncSlice, self).__init__(
17        category, name, timestamp, duration, thread_start, thread_duration,
18        args)
19    self.parent_slice = None
20    self.start_thread = start_thread
21    self.end_thread = end_thread
22    self.sub_slices = []
23    self.id = None
24
25  def AddSubSlice(self, sub_slice):
26    assert sub_slice.parent_slice == self
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