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

Unified Diff: tools/telemetry/telemetry/core/timeline/event.py

Issue 273103003: Add responsiveness_metric for timeline_based_measurement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Chris' comments Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698