3 Copyright (c) 2013 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.
7 <link rel="import" href="/tracing/trace_model/object_instance.html">
8 <link rel="import" href="/cc/util.html">
12 tvcm.exportTo('tcmalloc', function() {
13 var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
18 function HeapSnapshot() {
19 ObjectSnapshot.apply(this, arguments);
22 HeapSnapshot.prototype = {
23 __proto__: ObjectSnapshot.prototype,
25 preInitialize: function() {
26 cc.preInitializeObject(this);
28 // TODO(jamescook): Any generic field setup can go here.
31 // TODO(jamescook): This seems to be called before the green dot is clicked.
32 // Consider doing it in heap_view.js.
33 initialize: function() {
34 if (this.args.length == 0)
35 throw new Error('No heap snapshot data.');
37 // The first entry is total allocations across all stack traces.
38 this.total_ = this.args[0];
39 // The rest is a list of allocations.
40 var allocs = this.args.slice(1);
42 // Build a nested dictionary of trace event names.
50 for (var i = 0; i < allocs.length; i++) {
51 var alloc = allocs[i];
52 var traceNames = alloc.trace.split(' ');
53 // We don't want to record allocations caused by the heap profiling
54 // system itself, so skip allocations with this special name.
55 if (traceNames.indexOf('trace-memory-ignore') != -1)
57 var heapEntry = this.heap_;
58 // Walk down into the heap of stack traces.
59 for (var j = 0; j < traceNames.length; j++) {
60 // Look for existing children with this trace.
61 var traceName = traceNames[j];
62 // The empty trace name means "(here)", so don't roll those up into
63 // parent traces because they have already been counted.
64 if (traceName.length != 0) {
65 // Add up the total memory for intermediate entries, so the top of
66 // each subtree is the total memory for that tree.
67 heapEntry.currentBytes += alloc.currentBytes;
68 heapEntry.currentAllocs += alloc.currentAllocs;
69 heapEntry.totalBytes += alloc.totalBytes;
70 heapEntry.totalAllocs += alloc.totalAllocs;
72 if (!heapEntry.children[traceName]) {
73 // New trace entry at this depth, so create a child for it.
74 heapEntry.children[traceName] = {
76 currentBytes: alloc.currentBytes,
77 currentAllocs: alloc.currentAllocs,
78 totalBytes: alloc.totalBytes,
79 totalAllocs: alloc.totalAllocs
82 // Descend into the children.
83 heapEntry = heapEntry.children[traceName];
90 ObjectSnapshot.register('memory::Heap', HeapSnapshot);
93 HeapSnapshot: HeapSnapshot