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

Side by Side Diff: tracing/tracing/metrics/blink/leak_detection_metric.html

Issue 3012153002: Add leakDetectionMetric for tracing (Closed)
Patch Set: Use ES6 Created 3 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
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <!--
3 Copyright 2017 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/tracing/base/unit.html">
9 <link rel="import" href="/tracing/metrics/metric_registry.html">
10 <link rel="import" href="/tracing/metrics/system_health/utils.html">
11 <link rel="import" href="/tracing/value/histogram.html">
12
13 <script>
14 'use strict';
15
16 tr.exportTo('tr.metrics.blink', function() {
17 function leakDetectionMetric(histograms, model) {
18 // Extract renderer pids.
19 const modelHelper = model.getOrCreateHelper(
20 tr.model.helpers.ChromeModelHelper);
21 if (Object.keys(modelHelper).length === 0) {
benjhayden 2017/09/15 17:30:46 getOrCreateHelper returns undefined if Chrome is n
yuzuchan 2017/09/19 07:56:26 Done.
22 throw new Error('Chrome is not present.');
23 }
24 const rendererHelpers = modelHelper.rendererHelpers;
25 if (Object.keys(rendererHelpers).length === 0) {
26 throw new Error('Renderer process is not present.');
27 }
28 const pids = Object.keys(rendererHelpers);
29
30 // Get the dumps.
31 const chromeDumps = tr.metrics.sh
32 .splitGlobalDumpsByBrowserName(model, undefined).get('chrome');
33
34 const sumCounter = new Map();
35 // Add up counters for all the renderer processes.
36
37 for (const pid of pids) {
38 for (const [key, count] of countLeakedBlinkObjects(chromeDumps, pid)) {
39 sumCounter.set(key, (sumCounter.get(key) || 0) + count);
40 }
41 }
42
43 for (const [key, count] of sumCounter) {
44 const histogram = histograms.createHistogram('Leaked ' + key,
benjhayden 2017/09/15 17:30:46 No need to define the unused variable 'histogram'.
yuzuchan 2017/09/19 07:56:26 Done.
45 tr.b.Unit.byName.count_smallerIsBetter, sumCounter.get(key), {
benjhayden 2017/09/15 17:30:46 s/sumCounter.get(key)/count/
yuzuchan 2017/09/19 07:56:26 Done.
46 summaryOptions: {
47 avg: false,
48 count: true,
benjhayden 2017/09/15 17:30:46 This is the default value of count so it doesn't n
yuzuchan 2017/09/19 07:56:26 Done.
49 max: false,
50 min: false,
51 std: false,
52 sum: true,
benjhayden 2017/09/15 17:30:45 This is the default value of sum.
yuzuchan 2017/09/19 07:56:26 Done.
53 },
54 });
55 }
56 }
57
58 tr.metrics.MetricRegistry.register(leakDetectionMetric);
59
60 function countLeakedBlinkObjects(dumps, pid) {
61 if (dumps === undefined || dumps.length < 2) {
62 throw new Error('Expected at least two memory dumps.');
63 }
64 const firstCounter = countBlinkObjects(dumps[0], pid);
65 const lastCounter = countBlinkObjects(dumps[dumps.length - 1], pid);
66 const diffCounter = new Map();
67 for (const key of lastCounter.keys()) {
benjhayden 2017/09/15 17:30:46 for (const [key, lastCount] of lastCounter) { di
yuzuchan 2017/09/19 07:56:26 Done.
68 diffCounter.set(key, lastCounter.get(key) - firstCounter.get(key));
69 }
70 return diffCounter;
71 }
72
73 function countBlinkObjects(dump, pid) {
74 const counter = new Map();
75 const processesMemoryDumps = dump.processMemoryDumps;
76 if (pid in processesMemoryDumps) {
benjhayden 2017/09/15 17:30:45 We generally recommend using early-returns to redu
yuzuchan 2017/09/19 07:56:26 Done.
77 const blinkObjectsDump = processesMemoryDumps[pid].memoryAllocatorDumps
78 .find(dump => dump.fullName === 'blink_objects');
79 blinkObjectsDump.children.forEach(function(v) {
benjhayden 2017/09/15 17:30:46 Please use for (const v of blinkObjectsDump.childr
yuzuchan 2017/09/19 07:56:26 Done.
80 counter.set(v.name, v.numerics.object_count.value);
81 });
82 }
83 return counter;
84 }
85
86 return {
87 leakDetectionMetric,
88 };
89 });
90 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698