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

Side by Side Diff: tracing/tracing/metrics/system_health/cpu_time_metric.html

Issue 2334863002: Ignore overhead slices in cpu time computation. (Closed)
Patch Set: Created 4 years, 3 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" href="/tracing/metrics/metric_registry.html"> 8 <link rel="import" href="/tracing/metrics/metric_registry.html">
9 <link rel="import" href="/tracing/value/histogram.html"> 9 <link rel="import" href="/tracing/value/histogram.html">
10 <link rel="import" href="/tracing/value/value.html"> 10 <link rel="import" href="/tracing/value/value.html">
11 11
12 <script> 12 <script>
13 'use strict'; 13 'use strict';
14 14
15 tr.exportTo('tr.metrics.sh', function() { 15 tr.exportTo('tr.metrics.sh', function() {
16 /** 16 /**
17 * This metric measures total CPU time for Chrome processes, per second of 17 * This metric measures total CPU time for Chrome processes, per second of
18 * clock time. 18 * clock time.
19 * This metric requires only the 'toplevel' tracing category. 19 * This metric requires only the 'toplevel' tracing category.
20 * 20 *
21 * @param {!tr.v.ValueSet} values 21 * @param {!tr.v.ValueSet} values
22 * @param {!tr.model.Model} model 22 * @param {!tr.model.Model} model
23 * @param {!Object=} optOptions 23 * @param {!Object=} optOptions
24 */ 24 */
25 function cpuTimeMetric(values, model, optOptions) { 25 function cpuTimeMetric(values, model, optOptions) {
26 var rangeOfInterest = optOptions ? optOptions.rangeOfInterest : undefined; 26 var rangeOfInterest = optOptions ? optOptions.rangeOfInterest : undefined;
27 var allProcessCpuTime = 0; 27 var allProcessCpuTime = 0;
28 var allOverhead = 0;
28 29
29 for (var pid in model.processes) { 30 for (var pid in model.processes) {
30 var process = model.processes[pid]; 31 var process = model.processes[pid];
31 var processCpuTime = 0; 32 var processCpuTime = 0;
33 var processOverhead = 0;
32 for (var tid in process.threads) { 34 for (var tid in process.threads) {
33 var thread = process.threads[tid]; 35 var thread = process.threads[tid];
34 var threadCpuTime = 0; 36 var threadCpuTime = 0;
35 thread.sliceGroup.topLevelSlices.forEach(function(slice) { 37 thread.sliceGroup.topLevelSlices.forEach(function(slice) {
36 if (rangeOfInterest && 38 if (rangeOfInterest &&
37 !rangeOfInterest.intersectsExplicitRangeInclusive( 39 !rangeOfInterest.intersectsExplicitRangeInclusive(
38 slice.start, slice.end)) 40 slice.start, slice.end))
39 return; 41 return;
40 threadCpuTime += slice.cpuDuration; 42 threadCpuTime += slice.cpuDuration;
41 }); 43 });
42 processCpuTime += threadCpuTime; 44 processCpuTime += threadCpuTime;
45
46 var threadOverhead = 0;
47 thread.sliceGroup.slices.forEach(function(slice) {
48 if (rangeOfInterest &&
49 !rangeOfInterest.intersectsExplicitRangeInclusive(
50 slice.start, slice.end))
51 return;
52 if (slice.category != 'trace_event_overhead' ||
53 slice.name != 'overhead')
54 return;
55 threadOverhead += slice.cpuDuration;
56 });
57 processOverhead += threadOverhead;
43 } 58 }
44 allProcessCpuTime += processCpuTime; 59 allProcessCpuTime += processCpuTime;
60 allOverhead += processOverhead;
45 } 61 }
46 62
63 allProcessCpuTime -= allOverhead;
64
47 // Normalize cpu time by clock time. 65 // Normalize cpu time by clock time.
48 var normalizationRange = rangeOfInterest ? 66 var normalizationRange = rangeOfInterest ?
49 rangeOfInterest : model.bounds.range; 67 rangeOfInterest : model.bounds.range;
50 var MILLISECONDS_PER_SECOND = 1000; 68 var MILLISECONDS_PER_SECOND = 1000;
51 var clockTimeInSeconds = normalizationRange / MILLISECONDS_PER_SECOND; 69 var clockTimeInSeconds = normalizationRange / MILLISECONDS_PER_SECOND;
52 70
53 // Use a minimum clock time of 0.0001 to allow 0-sized ranges. 71 // Use a minimum clock time of 0.0001 to allow 0-sized ranges.
54 clockTimeInSeconds = Math.max(clockTimeInSeconds, 0.0001); 72 clockTimeInSeconds = Math.max(clockTimeInSeconds, 0.0001);
55 var normalizedAllProcessCpuTime = allProcessCpuTime / 73 var normalizedAllProcessCpuTime = allProcessCpuTime /
56 clockTimeInSeconds; 74 clockTimeInSeconds;
(...skipping 16 matching lines...) Expand all
73 tr.metrics.MetricRegistry.register(cpuTimeMetric, { 91 tr.metrics.MetricRegistry.register(cpuTimeMetric, {
74 supportsRangeOfInterest: true 92 supportsRangeOfInterest: true
75 }); 93 });
76 94
77 return { 95 return {
78 cpuTimeMetric: cpuTimeMetric, 96 cpuTimeMetric: cpuTimeMetric,
79 }; 97 };
80 }); 98 });
81 </script> 99 </script>
82 100
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698