nheap.js revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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_TOTAL = 0; 8this.COL_RESIDENT = 1; 9this.COL_STACKTRACE = 3; 10 11 12this.nheapData_ = null; 13this.nheapTable_ = null; 14this.nheapFilter_ = null; 15 16this.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)); 22}; 23 24this.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_(); 29}; 30 31this.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_(); 35 rootUi.hideDialog(); 36}; 37 38this.resetTableFilters_ = function() { 39 $('#nheap-filter').val(''); 40} 41 42this.applyTableFilters_ = function() { 43 // Filters the rows according to the user-provided file and prot regexps. 44 if (!this.nheapFilter_) 45 return; 46 47 var rx = $('#nheap-filter').val(); 48 var rows = []; 49 var total_allocated = 0; 50 var total_resident = 0; 51 52 for (var row = 0; row < this.nheapData_.getNumberOfRows(); ++row) { 53 stackTrace = this.nheapData_.getValue(row, this.COL_STACKTRACE); 54 if (!stackTrace.match(rx)) 55 continue; 56 rows.push(row); 57 total_allocated += this.nheapData_.getValue(row, this.COL_TOTAL); 58 total_resident += this.nheapData_.getValue(row, this.COL_RESIDENT); 59 } 60 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); 64 this.redraw(); 65}; 66 67this.onNheapTableRowSelect_ = function() { 68 if (!this.nheapFilter_) 69 return; 70 71 var total_allocated = 0; 72 var total_resident = 0; 73 74 this.nheapTable_.getSelection().forEach(function(sel) { 75 var row = sel.row; 76 total_allocated += this.nheapFilter_.getValue(row, this.COL_TOTAL); 77 total_resident += this.nheapFilter_.getValue(row, this.COL_RESIDENT); 78 }, this); 79 80 $('#nheap-selected-allocated').val(Math.floor(total_allocated / 1024) + 81 ' KB'); 82 $('#nheap-selected-resident').val(Math.floor(total_resident / 1024) + ' KB'); 83}; 84 85this.redraw = function() { 86 if (!this.nheapFilter_) 87 return; 88 this.nheapTable_.draw(this.nheapFilter_, {allowHtml: true, 89 page: 'enable', 90 pageSize: 25}); 91}; 92 93$(document).ready(this.onDomReady_.bind(this)); 94 95})();