1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 nheap = new (function() {
9 this.COL_STACKTRACE = 3;
12 this.nheapData_ = null;
13 this.nheapTable_ = null;
14 this.nheapFilter_ = null;
16 this.onDomReady_ = function() {
17 // Create the mmaps table.
18 this.nheapTable_ = new google.visualization.Table($('#nheap-table')[0]);
19 google.visualization.events.addListener(
20 this.nheapTable_, 'select', this.onNheapTableRowSelect_.bind(this));
21 $('#nheap-filter').on('change', this.applyTableFilters_.bind(this));
24 this.dumpNheapFromStorage = function(archiveName, snapshot) {
25 webservice.ajaxRequest('/storage/' + archiveName + '/' + snapshot + '/nheap',
26 this.onDumpAjaxResponse_.bind(this));
27 rootUi.showDialog('Loading native heap allocs from archive ...');
28 this.resetTableFilters_();
31 this.onDumpAjaxResponse_ = function(data) {
32 this.nheapData_ = new google.visualization.DataTable(data); // TODO remove .table form mmap
33 this.nheapFilter_ = new google.visualization.DataView(this.nheapData_);
34 this.applyTableFilters_();
38 this.resetTableFilters_ = function() {
39 $('#nheap-filter').val('');
42 this.applyTableFilters_ = function() {
43 // Filters the rows according to the user-provided file and prot regexps.
44 if (!this.nheapFilter_)
47 var rx = $('#nheap-filter').val();
49 var total_allocated = 0;
50 var total_resident = 0;
52 for (var row = 0; row < this.nheapData_.getNumberOfRows(); ++row) {
53 stackTrace = this.nheapData_.getValue(row, this.COL_STACKTRACE);
54 if (!stackTrace.match(rx))
57 total_allocated += this.nheapData_.getValue(row, this.COL_TOTAL);
58 total_resident += this.nheapData_.getValue(row, this.COL_RESIDENT);
61 $('#nheap-total-allocated').val(Math.floor(total_allocated / 1024) + ' KB');
62 $('#nheap-total-resident').val(Math.floor(total_resident / 1024) + ' KB');
63 this.nheapFilter_.setRows(rows);
67 this.onNheapTableRowSelect_ = function() {
68 if (!this.nheapFilter_)
71 var total_allocated = 0;
72 var total_resident = 0;
74 this.nheapTable_.getSelection().forEach(function(sel) {
76 total_allocated += this.nheapFilter_.getValue(row, this.COL_TOTAL);
77 total_resident += this.nheapFilter_.getValue(row, this.COL_RESIDENT);
80 $('#nheap-selected-allocated').val(Math.floor(total_allocated / 1024) +
82 $('#nheap-selected-resident').val(Math.floor(total_resident / 1024) + ' KB');
85 this.redraw = function() {
86 if (!this.nheapFilter_)
88 this.nheapTable_.draw(this.nheapFilter_, {allowHtml: true,
93 $(document).ready(this.onDomReady_.bind(this));