Index: tools/telemetry/telemetry/core/timeline/event.py |
diff --git a/tools/telemetry/telemetry/core/timeline/event.py b/tools/telemetry/telemetry/core/timeline/event.py |
index 916d540eabe8d2bdab06a28ef2d762c0ae71e980..a789730b01e53db4ac814af93b88adf40e7fe802 100644 |
--- a/tools/telemetry/telemetry/core/timeline/event.py |
+++ b/tools/telemetry/telemetry/core/timeline/event.py |
@@ -8,9 +8,9 @@ class TimelineEvent(object): |
thread_start, thread_duration and thread_end are the start time, duration |
and end time of this event as measured by the thread-specific CPU clock |
(ticking when the thread is actually scheduled). Thread time is optional |
- on trace events and the corresponding attributes in TimelineEvent will be |
- set to None (not 0) if not present. Users of this class need to properly |
- handle this case. |
+ on trace events and the corresponding attributes (thread_start, |
+ thread_duration, thread_end) in TimelineEvent will be set to None (not 0) |
+ if not present. Users of this class need to properly handle this case. |
""" |
def __init__(self, category, name, start, duration, thread_start=None, |
thread_duration=None, args=None): |
@@ -22,6 +22,7 @@ class TimelineEvent(object): |
self.thread_duration = thread_duration |
self.args = args |
+ |
@property |
def end(self): |
return self.start + self.duration |
@@ -36,6 +37,22 @@ class TimelineEvent(object): |
return None |
return self.thread_start + self.thread_duration |
+ def HasThreadTimeData(self): |
+ """Whether this event has thread-specific CPU time data.""" |
+ return self.thread_start is not None and self.thread_duration is not None |
+ |
+ def GetOverlappedTimeDurationWithRange(self, start, end): |
+ overlapped_interval_start = max(self.start, start) |
+ overlapped_interval_end = min(self.end, end) |
+ return max(overlapped_interval_end - overlapped_interval_start, 0) |
+ |
+ def GetOverlappedThreadTimeDurationWithRange(self, thread_start, thread_end): |
+ assert self.HasThreadTimeData(), 'this event does not have thread time data' |
+ overlapped_interval_thread_start = max(self.thread_start, thread_start) |
+ overlapped_interval_thread_end = min(self.thread_end, thread_end) |
+ return max( |
+ overlapped_interval_thread_end - overlapped_interval_thread_start, 0) |
+ |
def __repr__(self): |
if self.args: |
args_str = ', ' + repr(self.args) |