blob: d77f3a2d1597e926ea799c55b84b058684513d05 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="stylesheet" href="/extras/system_stats/system_stats_snapshot_view.css">
<link rel="import" href="/core/analysis/object_snapshot_view.html">
<link rel="import" href="/base/units/util.html">
<script>
'use strict';
tr.exportTo('tr.e.system_stats', function() {
/*
* Displays a system stats snapshot in a human readable form. @constructor
*/
var SystemStatsSnapshotView = tr.b.ui.define('system-stats-snapshot-view',
tr.c.analysis.ObjectSnapshotView);
SystemStatsSnapshotView.prototype = {
__proto__: tr.c.analysis.ObjectSnapshotView.prototype,
decorate: function() {
this.classList.add('system-stats-snapshot-view');
},
updateContents: function() {
var snapshot = this.objectSnapshot_;
if (!snapshot || !snapshot.getStats()) {
this.textContent = 'No system stats snapshot found.';
return;
}
// Clear old snapshot view.
this.textContent = '';
var stats = snapshot.getStats();
this.appendChild(this.buildList_(stats));
},
isFloat: function(n) {
return typeof n === 'number' && n % 1 !== 0;
},
/**
* Creates nested lists.
*
* @param {Object} stats The current trace system stats entry.
* @return {Element} A ul list element.
*/
buildList_: function(stats) {
var statList = document.createElement('ul');
for (var statName in stats) {
var statText = document.createElement('li');
statText.textContent = '' + statName + ': ';
statList.appendChild(statText);
if (stats[statName] instanceof Object) {
statList.appendChild(this.buildList_(stats[statName]));
} else {
if (this.isFloat(stats[statName]))
statText.textContent += stats[statName].toFixed(2);
else
statText.textContent += stats[statName];
}
}
return statList;
}
};
tr.c.analysis.ObjectSnapshotView.register(
SystemStatsSnapshotView,
{typeName: 'base::TraceEventSystemStatsMonitor::SystemStats'});
return {
SystemStatsSnapshotView: SystemStatsSnapshotView
};
});
</script>