responsiveness_metric.py revision 116680a4aac90f2aa7413d9095a592090648e557
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.
4import logging
5
6from telemetry.web_perf import timeline_interaction_record as tir_module
7from telemetry.web_perf.metrics import mainthread_jank_stats
8from telemetry.web_perf.metrics import timeline_based_metric
9from telemetry.value import scalar
10
11
12class ResponsivenessMetric(timeline_based_metric.TimelineBasedMetric):
13  """Computes metrics that measure respsonsiveness on the record ranges.
14
15      total_big_jank_thread_time is the total thread duration of all top
16      slices whose thread time ranges overlapped with any thread time ranges of
17      the records and the overlapped thread duration is greater than or equal
18      USER_PERCEIVABLE_DELAY_THRESHOLD_MS.
19
20      biggest_jank_thread_time is the biggest thread duration of all
21      top slices whose thread time ranges overlapped with any of records' thread
22      time ranges.
23
24     All *_time values are measured in milliseconds.
25  """
26
27  def __init__(self):
28    super(ResponsivenessMetric, self).__init__()
29
30  def AddResults(self, _, renderer_thread, interaction_records, results):
31    self.VerifyNonOverlappedRecords(interaction_records)
32    try:
33      jank_stats = mainthread_jank_stats.MainthreadJankStats(
34          renderer_thread, interaction_records)
35    # TODO(nednguyen): maybe fall back to use wall-time for computing the
36    # metrics.
37    except tir_module.NoThreadTimeDataException as e:
38      #TODO(nednguyen): Report the warning with page_results system.
39      logging.warning(
40          'Main thread jank metrics cannot be computed for records %s since '
41          'trace does not contain thread time data. %s',
42          repr(interaction_records), repr(e))
43      return
44
45    results.AddValue(scalar.ScalarValue(
46        results.current_page, 'responsive-total_big_jank_thread_time', 'ms',
47        jank_stats.total_big_jank_thread_time))
48    results.AddValue(scalar.ScalarValue(
49        results.current_page, 'responsive-biggest_jank_thread_time', 'ms',
50        jank_stats.biggest_jank_thread_time))
51