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