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 storage = new (function() {
8 this.tableData_ = null;
10 this.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));
22 this.table_ = new google.visualization.Table($('#storage-table')[0]);
25 this.reload = function() {
26 webservice.ajaxRequest('/storage/list', this.onListAjaxResponse_.bind(this));
29 this.onListAjaxResponse_ = function(data) {
30 this.tableData_ = new google.visualization.DataTable(data);
34 this.profileMmapForSelectedSnapshots = function() {
35 // Generates a mmap profile for the selected snapshots.
36 var sel = this.table_.getSelection();
37 if (!sel.length || !this.tableData_)
39 var archiveName = null;
42 for (var i = 0; i < sel.length; ++i) {
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!');
49 archiveName = curArchive;
50 snapshots.push(this.tableData_.getValue(row, 1));
52 profiler.profileArchivedMmaps(archiveName, snapshots);
53 rootUi.showTab('prof');
56 this.dumpMmapForSelectedSnapshot_ = function() {
57 var sel = this.table_.getSelection();
58 if (sel.length != 1) {
59 alert('Please select only one snapshot.')
64 mmap.dumpMmapsFromStorage(this.tableData_.getValue(row, 0),
65 this.tableData_.getValue(row, 1))
69 this.dumpNheapForSelectedSnapshot_ = function() {
70 var sel = this.table_.getSelection();
71 if (sel.length != 1) {
72 alert('Please select only one snapshot.')
77 if (!this.checkHasNativeHapDump_(row))
79 nheap.dumpNheapFromStorage(this.tableData_.getValue(row, 0),
80 this.tableData_.getValue(row, 1))
81 rootUi.showTab('nheap');
84 this.profileNativeForSelectedSnapshots = function() {
85 // Generates a native heap profile for the selected snapshots.
86 var sel = this.table_.getSelection();
87 if (!sel.length || !this.tableData_)
89 var archiveName = null;
92 for (var i = 0; i < sel.length; ++i) {
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!');
99 if (!this.checkHasNativeHapDump_(row))
101 archiveName = curArchive;
102 snapshots.push(this.tableData_.getValue(row, 1));
104 profiler.profileArchivedNHeaps(archiveName, snapshots);
105 rootUi.showTab('prof');
108 this.checkHasNativeHapDump_ = function(row) {
109 if (!this.tableData_.getValue(row, 3)) {
110 alert('The selected snapshot doesn\'t have a heap dump!');
116 this.redraw = function() {
117 if (!this.tableData_)
119 this.table_.draw(this.tableData_);
122 $(document).ready(this.onDomReady_.bind(this));