Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / memory_inspector / memory_inspector / frontends / www_content / js / nheap.js
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
5 nheap = new (function() {
6
7 this.COL_STACKTRACE = 3;
8 this.COL_TOTAL = 0;
9
10 this.nheapData_ = null;
11 this.nheapTable_ = null;
12 this.nheapFilter_ = null;
13
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));
20 };
21
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_();
27 };
28
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_();
33   rootUi.hideDialog();
34 };
35
36 this.resetTableFilters_ = function() {
37   $('#nheap-filter').val('');
38 }
39
40 this.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
62 this.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
76 this.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 })();