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() {
7 this.COL_STACKTRACE = 3;
10 this.nheapData_ = null;
11 this.nheapTable_ = null;
12 this.nheapFilter_ = null;
14 this.onDomReady_ = function() {
15 // Create the mmaps table.
16 this.nheapTable_ = new google.visualization.Table($('#nheap-table')[0]);
17 google.visualization.events.addListener(
18 this.nheapTable_, 'select', this.onNheapTableRowSelect_.bind(this));
19 $('#nheap-filter').on('change', this.applyTableFilters_.bind(this));
22 this.dumpNheapFromStorage = function(archiveName, snapshot) {
23 webservice.ajaxRequest('/storage/' + archiveName + '/' + snapshot + '/nheap',
24 this.onDumpAjaxResponse_.bind(this));
25 rootUi.showDialog('Loading native heap allocs from archive ...');
26 this.resetTableFilters_();
29 this.onDumpAjaxResponse_ = function(data) {
30 this.nheapData_ = new google.visualization.DataTable(data); // TODO remove .table form mmap
31 this.nheapFilter_ = new google.visualization.DataView(this.nheapData_);
32 this.applyTableFilters_();
36 this.resetTableFilters_ = function() {
37 $('#nheap-filter').val('');
40 this.applyTableFilters_ = function() {
41 // Filters the rows according to the user-provided file and prot regexps.
42 if (!this.nheapFilter_)
45 var rx = $('#nheap-filter').val();
49 for (var row = 0; row < this.nheapData_.getNumberOfRows(); ++row) {
50 stackTrace = this.nheapData_.getValue(row, this.COL_STACKTRACE);
51 if (!stackTrace.match(rx))
54 total += this.nheapData_.getValue(row, this.COL_TOTAL);
57 $('#nheap-totals').val(Math.floor(total / 1024) + ' KB');
58 this.nheapFilter_.setRows(rows);
62 this.onNheapTableRowSelect_ = function() {
63 if (!this.nheapFilter_)
68 this.nheapTable_.getSelection().forEach(function(sel) {
70 total += this.nheapFilter_.getValue(row, this.COL_TOTAL);
73 $('#nheap-selected').val(Math.floor(total / 1024) + ' KB');
76 this.redraw = function() {
77 if (!this.nheapFilter_)
79 this.nheapTable_.draw(this.nheapFilter_, {allowHtml: true,
84 $(document).ready(this.onDomReady_.bind(this));