// Copyright (c) 2013 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. 'use strict'; base.requireStylesheet('tcmalloc.tcmalloc_snapshot_view'); base.require('tracing.analysis.object_snapshot_view'); base.require('tracing.analysis.util'); base.exportTo('tcmalloc', function() { var tsRound = tracing.analysis.tsRound; /* * Displays a heap memory snapshot in a human readable form. * @constructor */ var TcmallocSnapshotView = ui.define( 'heap-snapshot-view', tracing.analysis.ObjectSnapshotView); TcmallocSnapshotView.prototype = { __proto__: tracing.analysis.ObjectSnapshotView.prototype, decorate: function() { this.classList.add('tcmalloc-snapshot-view'); }, updateContents: function() { var snapshot = this.objectSnapshot_; if (!snapshot || !snapshot.heap_) { this.textContent = 'No heap found.'; return; } // Clear old snapshot view. this.textContent = ''; // Note: "total" may actually be less than the largest allocation bin. // This might happen if one stack is doing a lot of allocation, then // passing off to another stack for deallocation. That stack will // have a high "current bytes" count and the other one might be // negative or zero. So "total" may be smaller than the largest trace. var subhead = document.createElement('div'); subhead.textContent = 'Retaining ' + this.getByteString_(snapshot.total_.currentBytes) + ' in ' + snapshot.total_.currentAllocs + ' allocations. Showing > 0.1 MB.'; subhead.className = 'subhead'; this.appendChild(subhead); // Build a nested tree-view of allocations var myList = this.buildAllocList_(snapshot.heap_, false); this.appendChild(myList); }, /** * Creates a nested list with clickable entries. * @param {Object} heapEntry The current trace heap entry. * @param {boolean} hide Whether this list is hidden by default. * @return {Element} A