nheap.js revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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. 4 5nheap = new (function() { 6 7this.COL_STACKTRACE = 3; 8this.COL_TOTAL = 0; 9 10this.nheapData_ = null; 11this.nheapTable_ = null; 12this.nheapFilter_ = null; 13 14this.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)); 20}; 21 22this.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_(); 27}; 28 29this.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_(); 33 rootUi.hideDialog(); 34}; 35 36this.resetTableFilters_ = function() { 37 $('#nheap-filter').val(''); 38} 39 40this.applyTableFilters_ = function() { 41 // Filters the rows according to the user-provided file and prot regexps. 42 if (!this.nheapFilter_) 43 return; 44 45 var rx = $('#nheap-filter').val(); 46 var rows = []; 47 var total = 0; 48 49 for (var row = 0; row < this.nheapData_.getNumberOfRows(); ++row) { 50 stackTrace = this.nheapData_.getValue(row, this.COL_STACKTRACE); 51 if (!stackTrace.match(rx)) 52 continue; 53 rows.push(row); 54 total += this.nheapData_.getValue(row, this.COL_TOTAL); 55 } 56 57 $('#nheap-totals').val(Math.floor(total / 1024) + ' KB'); 58 this.nheapFilter_.setRows(rows); 59 this.redraw(); 60}; 61 62this.onNheapTableRowSelect_ = function() { 63 if (!this.nheapFilter_) 64 return; 65 66 var total = 0; 67 68 this.nheapTable_.getSelection().forEach(function(sel) { 69 var row = sel.row; 70 total += this.nheapFilter_.getValue(row, this.COL_TOTAL); 71 }, this); 72 73 $('#nheap-selected').val(Math.floor(total / 1024) + ' KB'); 74}; 75 76this.redraw = function() { 77 if (!this.nheapFilter_) 78 return; 79 this.nheapTable_.draw(this.nheapFilter_, {allowHtml: true, 80 page: 'enable', 81 pageSize: 25}); 82}; 83 84$(document).ready(this.onDomReady_.bind(this)); 85 86})();