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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: tracing/tracing/metrics/blink/leak_detection_metric.html
diff --git a/tracing/tracing/metrics/blink/leak_detection_metric.html b/tracing/tracing/metrics/blink/leak_detection_metric.html
new file mode 100644
index 0000000000000000000000000000000000000000..c01c1eeae321bcd88c954553688613cb49520511
--- /dev/null
+++ b/tracing/tracing/metrics/blink/leak_detection_metric.html
@@ -0,0 +1,90 @@
+<!DOCTYPE html>
+<!--
+Copyright 2017 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/tracing/base/unit.html">
+<link rel="import" href="/tracing/metrics/metric_registry.html">
+<link rel="import" href="/tracing/metrics/system_health/utils.html">
+<link rel="import" href="/tracing/value/histogram.html">
+
+<script>
+'use strict';
+
+tr.exportTo('tr.metrics.blink', function() {
+ function leakDetectionMetric(histograms, model) {
+ // Extract renderer pids.
+ const modelHelper = model.getOrCreateHelper(
+ tr.model.helpers.ChromeModelHelper);
+ 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.
+ throw new Error('Chrome is not present.');
+ }
+ const rendererHelpers = modelHelper.rendererHelpers;
+ if (Object.keys(rendererHelpers).length === 0) {
+ throw new Error('Renderer process is not present.');
+ }
+ const pids = Object.keys(rendererHelpers);
+
+ // Get the dumps.
+ const chromeDumps = tr.metrics.sh
+ .splitGlobalDumpsByBrowserName(model, undefined).get('chrome');
+
+ const sumCounter = new Map();
+ // Add up counters for all the renderer processes.
+
+ for (const pid of pids) {
+ for (const [key, count] of countLeakedBlinkObjects(chromeDumps, pid)) {
+ sumCounter.set(key, (sumCounter.get(key) || 0) + count);
+ }
+ }
+
+ for (const [key, count] of sumCounter) {
+ 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.
+ 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.
+ summaryOptions: {
+ avg: false,
+ 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.
+ max: false,
+ min: false,
+ std: false,
+ sum: true,
benjhayden 2017/09/15 17:30:45 This is the default value of sum.
yuzuchan 2017/09/19 07:56:26 Done.
+ },
+ });
+ }
+ }
+
+ tr.metrics.MetricRegistry.register(leakDetectionMetric);
+
+ function countLeakedBlinkObjects(dumps, pid) {
+ if (dumps === undefined || dumps.length < 2) {
+ throw new Error('Expected at least two memory dumps.');
+ }
+ const firstCounter = countBlinkObjects(dumps[0], pid);
+ const lastCounter = countBlinkObjects(dumps[dumps.length - 1], pid);
+ const diffCounter = new Map();
+ 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.
+ diffCounter.set(key, lastCounter.get(key) - firstCounter.get(key));
+ }
+ return diffCounter;
+ }
+
+ function countBlinkObjects(dump, pid) {
+ const counter = new Map();
+ const processesMemoryDumps = dump.processMemoryDumps;
+ 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.
+ const blinkObjectsDump = processesMemoryDumps[pid].memoryAllocatorDumps
+ .find(dump => dump.fullName === 'blink_objects');
+ 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.
+ counter.set(v.name, v.numerics.object_count.value);
+ });
+ }
+ return counter;
+ }
+
+ return {
+ leakDetectionMetric,
+ };
+});
+</script>

Powered by Google App Engine
This is Rietveld 408576698