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

Side by Side Diff: tools/perf/metrics/gpu_timeline.py

Issue 854833003: Added GPU performance metrics. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix swap name in unit tests Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « tools/perf/benchmarks/gpu_times.py ('k') | tools/perf/metrics/gpu_timeline_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2015 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.
4 import collections
5 import math
6 import sys
7
8 from telemetry.timeline import model as model_module
9 from telemetry.value import scalar
10 from telemetry.value import list_of_scalar_values
11 from telemetry.web_perf.metrics import timeline_based_metric
12
13 TOPLEVEL_GL_CATEGORY = 'gpu_toplevel'
14 TOPLEVEL_SERVICE_CATEGORY = 'disabled-by-default-gpu.service'
15 TOPLEVEL_DEVICE_CATEGORY = 'disabled-by-default-gpu.device'
16
17 SERVICE_FRAME_END_MARKER = (TOPLEVEL_SERVICE_CATEGORY, 'SwapBuffer')
18 DEVICE_FRAME_END_MARKER = (TOPLEVEL_DEVICE_CATEGORY, 'SwapBuffer')
19
20 TRACKED_NAMES = { 'RenderCompositor': 'render_compositor',
epenner 2015/01/27 22:06:38 Optional nit: Could this be something like TRACKED
David Yen 2015/01/27 22:31:27 Done.
21 'BrowserCompositor': 'browser_compositor',
22 'Compositor': 'browser_compositor' }
23
24
25 def CalculateFrameTimes(events_per_frame):
26 """Given a list of events per frame, returns a list of frame times."""
27 times_per_frame = []
28 for event_list in events_per_frame:
29 # Prefer to use thread_duration but use duration as fallback.
30 event_times = [(event.thread_duration or event.duration)
epenner 2015/01/27 22:06:38 I'd be tempted to just not report anything if thre
David Yen 2015/01/27 22:31:27 This was to simplify the calculation of both synch
epenner 2015/01/27 22:59:02 Minimally, any detection of thread_duration not ex
David Yen 2015/01/27 23:20:00 I've split this up into 2 functions now, so CPU ev
31 for event in event_list]
32 times_per_frame.append(sum(event_times))
33 return times_per_frame
34
35
36 def TimelineName(name, source_type, value_type):
37 """Constructs the standard name given in the timeline.
38
39 Args:
40 name: The name of the timeline, for example "total", or "render_compositor".
41 source_type: One of "cpu", "gpu" or None. None is only used for total times.
42 value_type: the type of value. For example "mean", "stddev"...etc.
43 """
44 if source_type:
45 return '%s_%s_%s_time' % (name, value_type, source_type)
46 else:
47 return '%s_%s_time' % (name, value_type)
48
49
50 class GPUTimelineMetric(timeline_based_metric.TimelineBasedMetric):
51 """Computes GPU based metrics."""
52
53 def __init__(self):
54 super(GPUTimelineMetric, self).__init__()
55
56 def AddResults(self, model, _, interaction_records, results):
57 self.VerifyNonOverlappedRecords(interaction_records)
58 service_times = self._CalculateGPUTimelineData(model)
59 for value_item, durations in service_times.iteritems():
60 count = len(durations)
61 avg = 0.0
62 stddev = 0.0
63 maximum = 0.0
64 if count:
65 avg = sum(durations) / count
66 stddev = math.sqrt(sum((d - avg) ** 2 for d in durations) / count)
67 maximum = max(durations)
68
69 name, src = value_item
70
71 if src:
72 frame_times_name = '%s_%s_frame_times' % (name, src)
73 else:
74 frame_times_name = '%s_frame_times' % (name)
75
76 if durations:
epenner 2015/01/27 22:06:38 Nit: Looks like we should either add or not add al
David Yen 2015/01/27 22:31:27 list_of_scalar_values requires a non-empty list, I
77 results.AddValue(list_of_scalar_values.ListOfScalarValues(
78 results.current_page, frame_times_name, 'ms', durations))
79
80 results.AddValue(scalar.ScalarValue(results.current_page,
81 TimelineName(name, src, 'max'),
82 'ms', maximum))
83 results.AddValue(scalar.ScalarValue(results.current_page,
84 TimelineName(name, src, 'mean'),
85 'ms', avg))
86 results.AddValue(scalar.ScalarValue(results.current_page,
87 TimelineName(name, src, 'stddev'),
88 'ms', stddev))
89
90 def _CalculateGPUTimelineData(self, model):
91 """Uses the model and calculates the times for various values for each
92 frame. The return value will be a dictionary of the following format:
93 {
94 EVENT_NAME1: [FRAME0_TIME, FRAME1_TIME...etc.],
95 EVENT_NAME2: [FRAME0_TIME, FRAME1_TIME...etc.],
96 }
97
98 Event Names:
99 mean_frame - Mean time each frame is calculated to be.
epenner 2015/01/27 22:06:38 Nit: I think this name might have changed in the c
David Yen 2015/01/27 22:31:28 Updated description to match the new return values
100 mean_gpu_service-cpu: Mean time the GPU service took per frame.
101 mean_gpu_device-gpu: Mean time the GPU device took per frame.
102 TRACKED_NAMES_service-cpu: Using the TRACKED_NAMES dictionary, we
103 include service traces per frame for the
104 tracked name.
105 TRACKED_NAMES_device-gpu: Using the TRACKED_NAMES dictionary, we
106 include device traces per frame for the
107 tracked name.
108 """
109 all_service_events = []
110 current_service_frame_end = sys.maxint
111 current_service_events = []
112
113 all_device_events = []
114 current_device_frame_end = sys.maxint
115 current_device_events = []
116
117 tracked_events = {}
118 tracked_events.update(dict([((value, 'cpu'), [])
119 for value in TRACKED_NAMES.itervalues()]))
120 tracked_events.update(dict([((value, 'gpu'), [])
121 for value in TRACKED_NAMES.itervalues()]))
122
123 current_tracked_service_events = collections.defaultdict(list)
epenner 2015/01/27 22:06:38 Optional Nit: current_frame_service_events, or cur
David Yen 2015/01/27 22:31:28 Done.
124 current_tracked_device_events = collections.defaultdict(list)
125
126 event_iter = model.IterAllEvents(
127 event_type_predicate=model_module.IsSliceOrAsyncSlice)
128 for event in event_iter:
129 # Look for frame end markers
130 if (event.category, event.name) == SERVICE_FRAME_END_MARKER:
131 current_service_frame_end = event.end
132 elif (event.category, event.name) == DEVICE_FRAME_END_MARKER:
133 current_device_frame_end = event.end
134
135 # Track all other toplevel gl category markers
136 elif event.args.get('gl_category', None) == TOPLEVEL_GL_CATEGORY:
137 base_name = event.name
138 dash_index = base_name.rfind('-')
139 if dash_index != -1:
140 base_name = base_name[:dash_index]
141 tracked_name = TRACKED_NAMES.get(base_name, None)
142
epenner 2015/01/27 22:06:38 Optional nit: The alternating if blocks are almost
David Yen 2015/01/27 22:31:27 Yeah originally I had it trying to share more code
143 if event.category == TOPLEVEL_SERVICE_CATEGORY:
144 # Check if frame has ended.
145 if event.start >= current_service_frame_end:
146 if current_service_events:
147 all_service_events.append(current_service_events)
148 for value in TRACKED_NAMES.itervalues():
149 tracked_events[(value, 'cpu')].append(
150 current_tracked_service_events[value])
151 current_service_events = []
152 current_service_frame_end = sys.maxint
153 current_tracked_service_events.clear()
154
155 current_service_events.append(event)
156 if tracked_name:
157 current_tracked_service_events[tracked_name].append(event)
158
159 elif event.category == TOPLEVEL_DEVICE_CATEGORY:
160 # Check if frame has ended.
161 if event.start >= current_device_frame_end:
162 if current_device_events:
163 all_device_events.append(current_device_events)
164 for value in TRACKED_NAMES.itervalues():
165 tracked_events[(value, 'gpu')].append(
166 current_tracked_device_events[value])
167 current_device_events = []
168 current_device_frame_end = sys.maxint
169 current_tracked_device_events.clear()
170
171 current_device_events.append(event)
172 if tracked_name:
173 current_tracked_device_events[tracked_name].append(event)
174
175 # Append Data for Last Frame.
176 if current_service_events:
177 all_service_events.append(current_service_events)
178 for value in TRACKED_NAMES.itervalues():
179 tracked_events[(value, 'cpu')].append(
180 current_tracked_service_events[value])
181 if current_device_events:
182 all_device_events.append(current_device_events)
183 for value in TRACKED_NAMES.itervalues():
184 tracked_events[(value, 'gpu')].append(
185 current_tracked_device_events[value])
186
187 # Calculate Mean Frame Time for the CPU side.
188 frame_times = []
189 if all_service_events:
190 prev_frame_end = all_service_events[0][0].start
191 for event_list in all_service_events:
192 last_service_event_in_frame = event_list[-1]
193 frame_times.append(last_service_event_in_frame.end - prev_frame_end)
194 prev_frame_end = last_service_event_in_frame.end
195
196 # Create the timeline data dictionary for service side traces.
197 total_frame_value = ('swap', None)
198 cpu_frame_value = ('total', 'cpu')
199 gpu_frame_value = ('total', 'gpu')
200 timeline_data = {}
201 timeline_data[total_frame_value] = frame_times
202 timeline_data[cpu_frame_value] = CalculateFrameTimes(all_service_events)
203 for value in TRACKED_NAMES.itervalues():
204 cpu_value = (value, 'cpu')
205 timeline_data[cpu_value] = CalculateFrameTimes(tracked_events[cpu_value])
206
207 # Add in GPU side traces if it was supported (IE. device traces exist).
208 if all_device_events:
209 timeline_data[gpu_frame_value] = CalculateFrameTimes(all_device_events)
210 for value in TRACKED_NAMES.itervalues():
211 gpu_value = (value, 'gpu')
212 tracked_gpu_event = tracked_events[gpu_value]
213 timeline_data[gpu_value] = CalculateFrameTimes(tracked_gpu_event)
214
215 return timeline_data
OLDNEW
« no previous file with comments | « tools/perf/benchmarks/gpu_times.py ('k') | tools/perf/metrics/gpu_timeline_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698