1 // Copyright (c) 2013 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.
7 tvcm.requireStylesheet('system_stats.system_stats_snapshot_view');
9 tvcm.require('tracing.analysis.object_snapshot_view');
10 tvcm.require('tracing.analysis.util');
12 tvcm.exportTo('system_stats', function() {
14 * Displays a system stats snapshot in a human readable form. @constructor
16 var SystemStatsSnapshotView = tvcm.ui.define('system-stats-snapshot-view',
17 tracing.analysis.ObjectSnapshotView);
19 SystemStatsSnapshotView.prototype = {
20 __proto__: tracing.analysis.ObjectSnapshotView.prototype,
22 decorate: function() {
23 this.classList.add('system-stats-snapshot-view');
26 updateContents: function() {
27 var snapshot = this.objectSnapshot_;
28 if (!snapshot || !snapshot.getStats()) {
29 this.textContent = 'No system stats snapshot found.';
32 // Clear old snapshot view.
33 this.textContent = '';
35 var stats = snapshot.getStats();
36 this.appendChild(this.buildList_(stats));
39 isFloat: function(n) {
40 return typeof n === 'number' && n % 1 !== 0;
44 * Creates nested lists.
46 * @param {Object} stats The current trace system stats entry.
51 buildList_: function(stats) {
52 var statList = document.createElement('ul');
54 for (var statName in stats) {
55 var statText = document.createElement('li');
56 statText.textContent = '' + statName + ': ';
57 statList.appendChild(statText);
59 if (stats[statName] instanceof Object) {
60 statList.appendChild(this.buildList_(stats[statName]));
62 if (this.isFloat(stats[statName]))
63 statText.textContent += stats[statName].toFixed(2);
65 statText.textContent += stats[statName];
73 tracing.analysis.ObjectSnapshotView.register(
74 'base::TraceEventSystemStatsMonitor::SystemStats',
75 SystemStatsSnapshotView);
78 SystemStatsSnapshotView: SystemStatsSnapshotView