def AddImplThreadRenderingStats(mock_timer, thread, first_frame, ref_stats=None): """ Adds a random impl thread rendering stats event. thread: The timeline model thread to which the event will be added. first_frame: Is this the first frame within the bounds of an action? ref_stats: A ReferenceRenderingStats object to record expected values. """ # Create randonm data and timestap for impl thread rendering stats. data = { 'frame_count': 1, 'rasterize_time': mock_timer.Advance(5, 10) / 1000.0, 'rasterized_pixel_count': 1280 * 720, 'visible_content_area': random.uniform(0, 100), 'approximated_visible_content_area': random.uniform(0, 5) } timestamp = mock_timer.Get() # Add a slice with the event data to the given thread. thread.PushCompleteSlice( 'benchmark', 'BenchmarkInstrumentation::ImplThreadRenderingStats', timestamp, duration=0.0, thread_timestamp=None, thread_duration=None, args={'data': data}) if not ref_stats: return # Add timestamp only if a frame was output if data['frame_count'] == 1: if not first_frame: # Add frame_time if this is not the first frame in within the bounds of an # action. prev_timestamp = ref_stats.frame_timestamps[-1][-1] ref_stats.frame_times[-1].append( round(timestamp - prev_timestamp, 2)) ref_stats.frame_timestamps[-1].append(timestamp) ref_stats.rasterize_times[-1].append(data['rasterize_time'] * 1000.0) ref_stats.rasterized_pixel_counts[-1].append( data['rasterized_pixel_count']) ref_stats.approximated_pixel_percentages[-1].append( round( DivideIfPossibleOrZero(data['approximated_visible_content_area'], data['visible_content_area']) * 100.0, 3))
def Rate(numerator, denominator): return DivideIfPossibleOrZero(numerator, denominator)