storage.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
5storage = new (function() {
6
7this.table_ = null;
8this.tableData_ = null;
9
10this.onDomReady_ = function() {
11  // Initialize the toolbar.
12  $('#storage-profile-mmaps').button({icons:{primary: 'ui-icon-image'}})
13      .click(this.profileMmapForSelectedSnapshots.bind(this));
14  $('#storage-dump-mmaps').button({icons:{primary: 'ui-icon-calculator'}})
15      .click(this.dumpMmapForSelectedSnapshot_.bind(this));
16  $('#storage-profile-native').button({icons:{primary: 'ui-icon-image'}})
17      .click(this.profileNativeForSelectedSnapshots.bind(this));
18  $('#storage-dump-nheap').button({icons:{primary: 'ui-icon-calculator'}})
19      .click(this.dumpNheapForSelectedSnapshot_.bind(this));
20
21  // Create the table.
22  this.table_ = new google.visualization.Table($('#storage-table')[0]);
23};
24
25this.reload = function() {
26  webservice.ajaxRequest('/storage/list', this.onListAjaxResponse_.bind(this));
27}
28
29this.onListAjaxResponse_ = function(data) {
30  this.tableData_ = new google.visualization.DataTable(data);
31  this.redraw();
32};
33
34this.profileMmapForSelectedSnapshots = function() {
35  // Generates a mmap profile for the selected snapshots.
36  var sel = this.table_.getSelection();
37  if (!sel.length || !this.tableData_)
38    return;
39  var archiveName = null;
40  var snapshots = [];
41
42  for (var i = 0; i < sel.length; ++i) {
43    var row = sel[i].row;
44    var curArchive = this.tableData_.getValue(row, 0);
45    if (archiveName && curArchive != archiveName){
46      alert('All the selected snapshots must belong to the same archive!');
47      return;
48    }
49    archiveName = curArchive;
50    snapshots.push(this.tableData_.getValue(row, 1));
51  }
52  profiler.profileArchivedMmaps(archiveName, snapshots);
53  rootUi.showTab('prof');
54};
55
56this.dumpMmapForSelectedSnapshot_ = function() {
57  var sel = this.table_.getSelection();
58  if (sel.length != 1) {
59    alert('Please select only one snapshot.')
60    return;
61  }
62
63  var row = sel[0].row;
64  mmap.dumpMmapsFromStorage(this.tableData_.getValue(row, 0),
65                            this.tableData_.getValue(row, 1))
66  rootUi.showTab('mm');
67};
68
69this.dumpNheapForSelectedSnapshot_ = function() {
70  var sel = this.table_.getSelection();
71  if (sel.length != 1) {
72    alert('Please select only one snapshot.')
73    return;
74  }
75
76  var row = sel[0].row;
77  if (!this.checkHasNativeHapDump_(row))
78    return;
79  nheap.dumpNheapFromStorage(this.tableData_.getValue(row, 0),
80                             this.tableData_.getValue(row, 1))
81  rootUi.showTab('nheap');
82};
83
84this.profileNativeForSelectedSnapshots = function() {
85  // Generates a native heap profile for the selected snapshots.
86  var sel = this.table_.getSelection();
87  if (!sel.length || !this.tableData_)
88    return;
89  var archiveName = null;
90  var snapshots = [];
91
92  for (var i = 0; i < sel.length; ++i) {
93    var row = sel[i].row;
94    var curArchive = this.tableData_.getValue(row, 0);
95    if (archiveName && curArchive != archiveName) {
96      alert('All the selected snapshots must belong to the same archive!');
97      return;
98    }
99    if (!this.checkHasNativeHapDump_(row))
100      return;
101    archiveName = curArchive;
102    snapshots.push(this.tableData_.getValue(row, 1));
103  }
104  profiler.profileArchivedNHeaps(archiveName, snapshots);
105  rootUi.showTab('prof');
106};
107
108this.checkHasNativeHapDump_ = function(row) {
109  if (!this.tableData_.getValue(row, 3)) {
110    alert('The selected snapshot doesn\'t have a heap dump!');
111    return false;
112  }
113  return true;
114}
115
116this.redraw = function() {
117  if (!this.tableData_)
118    return;
119  this.table_.draw(this.tableData_);
120};
121
122$(document).ready(this.onDomReady_.bind(this));
123
124})();