OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
| 8 <link rel="import" |
| 9 href="/tracing/extras/chrome/chrome_user_friendly_category_driver.html"> |
8 <link rel="import" href="/tracing/metrics/metric_registry.html"> | 10 <link rel="import" href="/tracing/metrics/metric_registry.html"> |
9 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html"> | 11 <link rel="import" href="/tracing/model/helpers/chrome_model_helper.html"> |
10 <link rel="import" href="/tracing/value/numeric.html"> | 12 <link rel="import" href="/tracing/value/numeric.html"> |
11 <link rel="import" href="/tracing/value/value.html"> | 13 <link rel="import" href="/tracing/value/value.html"> |
12 | 14 |
13 <script> | 15 <script> |
14 'use strict'; | 16 'use strict'; |
15 | 17 |
16 tr.exportTo('tr.metrics.sh', function() { | 18 tr.exportTo('tr.metrics.sh', function() { |
17 var LONG_TASK_MS = 50; | 19 var LONG_TASK_MS = 50; |
(...skipping 11 matching lines...) Expand all Loading... |
29 * | 31 * |
30 * @param {tr.model.Thread} thread | 32 * @param {tr.model.Thread} thread |
31 * @param {tr.b.Range=} opt_range | 33 * @param {tr.b.Range=} opt_range |
32 * @param {function()} cb | 34 * @param {function()} cb |
33 * @param {Object=} opt_this | 35 * @param {Object=} opt_this |
34 */ | 36 */ |
35 function iterateLongTopLevelTasksOnThreadInRange( | 37 function iterateLongTopLevelTasksOnThreadInRange( |
36 thread, opt_range, cb, opt_this) { | 38 thread, opt_range, cb, opt_this) { |
37 thread.sliceGroup.topLevelSlices.forEach(function(slice) { | 39 thread.sliceGroup.topLevelSlices.forEach(function(slice) { |
38 if (opt_range && | 40 if (opt_range && |
39 !opt_range.intersectsExplicitRangeExclusive(slice.start, slice.end)) | 41 !opt_range.intersectsExplicitRangeInclusive(slice.start, slice.end)) |
40 return; | 42 return; |
41 | 43 |
42 if (slice.duration < LONG_TASK_MS) | 44 if (slice.duration < LONG_TASK_MS) |
43 return; | 45 return; |
44 | 46 |
45 cb.call(opt_this, slice); | 47 cb.call(opt_this, slice); |
46 }); | 48 }); |
47 } | 49 } |
48 | 50 |
49 /** | 51 /** |
(...skipping 12 matching lines...) Expand all Loading... |
62 if (!rendererHelper.mainThread) | 64 if (!rendererHelper.mainThread) |
63 return; | 65 return; |
64 cb.call(opt_this, rendererHelper.mainThread); | 66 cb.call(opt_this, rendererHelper.mainThread); |
65 }); | 67 }); |
66 } | 68 } |
67 | 69 |
68 var LONG_TASK_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear( | 70 var LONG_TASK_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear( |
69 tr.v.Unit.byName.timeDurationInMs_smallerIsBetter, | 71 tr.v.Unit.byName.timeDurationInMs_smallerIsBetter, |
70 tr.b.Range.fromExplicitRange(LONG_TASK_MS, LONGEST_TASK_MS), 50); | 72 tr.b.Range.fromExplicitRange(LONG_TASK_MS, LONGEST_TASK_MS), 50); |
71 | 73 |
| 74 // This range spans several orders of magnitude, and the data is likely to |
| 75 // form an exponential distribution, so use exponential bins in order to |
| 76 // prevent the lowest bin from containing almost all of the samples. |
| 77 // See also most UMA histograms that are exponential for similar reasons. |
| 78 var SLICE_NUMERIC_BUILDER = tr.v.NumericBuilder.createExponential( |
| 79 tr.v.Unit.byName.timeDurationInMs_smallerIsBetter, |
| 80 tr.b.Range.fromExplicitRange(0.1, LONGEST_TASK_MS), 50); |
| 81 |
72 /** | 82 /** |
73 * This metric directly measures long tasks on renderer main threads. | 83 * This metric directly measures long tasks on renderer main threads. |
74 * This metric requires only the 'toplevel' tracing category. | 84 * This metric requires only the 'toplevel' tracing category. |
75 * | 85 * |
76 * @param {!tr.v.ValueSet} values | 86 * @param {!tr.v.ValueSet} values |
77 * @param {!tr.model.Model} model | 87 * @param {!tr.model.Model} model |
78 * @param {!Object=} opt_options | 88 * @param {!Object=} opt_options |
79 */ | 89 */ |
80 function longTasksMetric(values, model, opt_options) { | 90 function longTasksMetric(values, model, opt_options) { |
81 var rangeOfInterest = opt_options ? opt_options.rangeOfInterest : undefined; | 91 var rangeOfInterest = opt_options ? opt_options.rangeOfInterest : undefined; |
82 var longTaskNumeric = LONG_TASK_NUMERIC_BUILDER.build(); | 92 var longTaskNumeric = LONG_TASK_NUMERIC_BUILDER.build(); |
| 93 var slices = new tr.model.EventSet(); |
83 iterateRendererMainThreads(model, function(thread) { | 94 iterateRendererMainThreads(model, function(thread) { |
84 iterateLongTopLevelTasksOnThreadInRange( | 95 iterateLongTopLevelTasksOnThreadInRange( |
85 thread, rangeOfInterest, function(task) { | 96 thread, rangeOfInterest, function(task) { |
86 longTaskNumeric.add(task.duration, task.stableId); | 97 longTaskNumeric.add(task.duration, |
| 98 new tr.v.d.RelatedEventSet([task])); |
| 99 slices.push(task); |
| 100 slices.addEventSet(task.descendentSlices); |
87 }); | 101 }); |
88 }); | 102 }); |
89 values.addValue(new tr.v.NumericValue( | 103 var options = {description: 'durations of long tasks'}; |
90 'long tasks', longTaskNumeric)); | 104 var longTaskValue = new tr.v.NumericValue( |
| 105 'long tasks', longTaskNumeric, options); |
| 106 values.addValue(longTaskValue); |
| 107 var composition = tr.v.d.Composition.buildFromEvents( |
| 108 values, 'long tasks ', slices, SLICE_NUMERIC_BUILDER, |
| 109 e => (model.getUserFriendlyCategoryFromEvent(e) || 'unknown')); |
| 110 longTaskValue.diagnostics.add('category', composition); |
91 } | 111 } |
92 | 112 |
93 tr.metrics.MetricRegistry.register(longTasksMetric, { | 113 tr.metrics.MetricRegistry.register(longTasksMetric, { |
94 supportsRangeOfInterest: true | 114 supportsRangeOfInterest: true |
95 }); | 115 }); |
96 | 116 |
97 return { | 117 return { |
98 longTasksMetric: longTasksMetric, | 118 longTasksMetric: longTasksMetric, |
99 iterateLongTopLevelTasksOnThreadInRange: | 119 iterateLongTopLevelTasksOnThreadInRange: |
100 iterateLongTopLevelTasksOnThreadInRange, | 120 iterateLongTopLevelTasksOnThreadInRange, |
101 iterateRendererMainThreads: iterateRendererMainThreads, | 121 iterateRendererMainThreads: iterateRendererMainThreads, |
102 LONG_TASK_MS: LONG_TASK_MS, | 122 LONG_TASK_MS: LONG_TASK_MS, |
103 LONGEST_TASK_MS: LONGEST_TASK_MS | 123 LONGEST_TASK_MS: LONGEST_TASK_MS |
104 }; | 124 }; |
105 }); | 125 }); |
106 </script> | 126 </script> |
OLD | NEW |