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

Unified Diff: tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.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/web_perf/metrics/timeline_based_metric.py
diff --git a/tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.py b/tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.py
index 0a4f56e7c152035ef981154f682986952c287687..3d38007b863cedd0332676b4ed8d4803d8c5fc85 100644
--- a/tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.py
+++ b/tools/telemetry/telemetry/web_perf/metrics/timeline_based_metric.py
@@ -3,6 +3,29 @@
# found in the LICENSE file.
+class TimelineBasedMetricException(Exception):
+ """Exception that can be thrown from metrics that implements
+ TimelineBasedMetric to indicate a problem arised when computing the metric.
+ """
+
+
+def _TimeRangesHasOverlap(iterable_time_ranges):
+ """ Returns True if there is are overlapped ranges in time ranges.
+ iterable_time_ranges: an iterable of time ranges. Each time range is a
+ tuple (start time, end time).
+ """
+ # Sort the ranges by the start time
+ sorted_time_ranges = sorted(iterable_time_ranges)
+ last_range = sorted_time_ranges[0]
+ for current_range in sorted_time_ranges[1:]:
+ start_current_range = current_range[0]
+ end_last_range = last_range[1]
+ if start_current_range < end_last_range:
+ return True
+ last_range = current_range
+ return False
+
+
class TimelineBasedMetric(object):
def __init__(self):
"""Computes metrics from a telemetry.core.timeline Model and a range
@@ -22,3 +45,14 @@ class TimelineBasedMetric(object):
"""
raise NotImplementedError()
+
+ def VerifyNonOverlappedRecords(self, interaction_records):
+ if _TimeRangesHasOverlap(((r.start, r.end) for r in interaction_records)):
+ raise TimelineBasedMetricException(
+ 'This metric does not support interaction records with overlapped time '
+ 'range.')
+ if _TimeRangesHasOverlap(((r.thread_start, r.thread_end)
+ for r in interaction_records)):
+ raise TimelineBasedMetricException(
+ 'This metric does not support interaction records with overlapped '
+ 'thread time range.')

Powered by Google App Engine
This is Rietveld 408576698