| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Identifies key events related to user satisfaction. | 5 """Identifies key events related to user satisfaction. |
| 6 | 6 |
| 7 Several lenses are defined, for example FirstTextPaintLens and | 7 Several lenses are defined, for example FirstTextPaintLens and |
| 8 FirstSignificantPaintLens. | 8 FirstSignificantPaintLens. |
| 9 | 9 |
| 10 When run from the command line, takes a lens name and a trace, and prints the | 10 When run from the command line, takes a lens name and a trace, and prints the |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 207 |
| 208 Our satisfaction time is that of the layout change, as all resources must have | 208 Our satisfaction time is that of the layout change, as all resources must have |
| 209 been loaded to compute the layout. Our event time is that of the next paint as | 209 been loaded to compute the layout. Our event time is that of the next paint as |
| 210 that is the observable event. | 210 that is the observable event. |
| 211 """ | 211 """ |
| 212 _FIRST_LAYOUT_COUNTER = 'LayoutObjectsThatHadNeverHadLayout' | 212 _FIRST_LAYOUT_COUNTER = 'LayoutObjectsThatHadNeverHadLayout' |
| 213 _EVENT_CATEGORIES = ['blink', 'disabled-by-default-blink.debug.layout'] | 213 _EVENT_CATEGORIES = ['blink', 'disabled-by-default-blink.debug.layout'] |
| 214 def _CalculateTimes(self, trace): | 214 def _CalculateTimes(self, trace): |
| 215 for cat in self._EVENT_CATEGORIES: | 215 for cat in self._EVENT_CATEGORIES: |
| 216 self._CheckCategory(trace.tracing_track, cat) | 216 self._CheckCategory(trace.tracing_track, cat) |
| 217 sync_paint_times = [] | 217 paint_tree_times = [] |
| 218 layouts = [] # (layout item count, msec). | 218 layouts = [] # (layout item count, msec). |
| 219 for e in trace.tracing_track.GetEvents(): | 219 for e in trace.tracing_track.GetEvents(): |
| 220 if ('frame' in e.args and | 220 if ('frame' in e.args and |
| 221 e.args['frame'] != trace.tracing_track.GetMainFrameID()): | 221 e.args['frame'] != trace.tracing_track.GetMainFrameID()): |
| 222 continue | 222 continue |
| 223 # If we don't know have a frame id, we assume it applies to all events. | 223 # If we don't know have a frame id, we assume it applies to all events. |
| 224 | 224 |
| 225 # TODO(mattcary): is this the right paint event? Check if synchronized | 225 if e.Matches('blink', 'FrameView::paintTree'): |
| 226 # paints appear at the same time as the first*Paint events, above. | 226 paint_tree_times.append(e.start_msec) |
| 227 if e.Matches('blink', 'FrameView::synchronizedPaint'): | |
| 228 sync_paint_times.append(e.start_msec) | |
| 229 if ('counters' in e.args and | 227 if ('counters' in e.args and |
| 230 self._FIRST_LAYOUT_COUNTER in e.args['counters']): | 228 self._FIRST_LAYOUT_COUNTER in e.args['counters']): |
| 231 layouts.append((e.args['counters'][self._FIRST_LAYOUT_COUNTER], | 229 layouts.append((e.args['counters'][self._FIRST_LAYOUT_COUNTER], |
| 232 e.start_msec)) | 230 e.start_msec)) |
| 233 assert layouts, 'No layout events' | 231 assert layouts, 'No layout events' |
| 234 assert sync_paint_times,'No sync paint times' | 232 assert paint_tree_times,'No paintTree times' |
| 235 layouts.sort(key=operator.itemgetter(0), reverse=True) | 233 layouts.sort(key=operator.itemgetter(0), reverse=True) |
| 236 self._satisfied_msec = layouts[0][1] | 234 self._satisfied_msec = layouts[0][1] |
| 237 self._event_msec = min(t for t in sync_paint_times | 235 self._event_msec = min(t for t in paint_tree_times |
| 238 if t > self._satisfied_msec) | 236 if t > self._satisfied_msec) |
| 239 | 237 |
| 240 | 238 |
| 241 def main(lens_name, trace_file): | 239 def main(lens_name, trace_file): |
| 242 assert (lens_name in globals() and | 240 assert (lens_name in globals() and |
| 243 not lens_name.startswith('_') and | 241 not lens_name.startswith('_') and |
| 244 lens_name.endswith('Lens')), 'Bad lens %s' % lens_name | 242 lens_name.endswith('Lens')), 'Bad lens %s' % lens_name |
| 245 lens_cls = globals()[lens_name] | 243 lens_cls = globals()[lens_name] |
| 246 trace = loading_trace.LoadingTrace.FromJsonFile(trace_file) | 244 trace = loading_trace.LoadingTrace.FromJsonFile(trace_file) |
| 247 lens = lens_cls(trace) | 245 lens = lens_cls(trace) |
| 248 for fp in sorted(lens.CriticalFingerprints()): | 246 for fp in sorted(lens.CriticalFingerprints()): |
| 249 print fp | 247 print fp |
| 250 | 248 |
| 251 | 249 |
| 252 if __name__ == '__main__': | 250 if __name__ == '__main__': |
| 253 import sys | 251 import sys |
| 254 import loading_trace | 252 import loading_trace |
| 255 main(sys.argv[1], sys.argv[2]) | 253 main(sys.argv[1], sys.argv[2]) |
| OLD | NEW |