1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="stylesheet"
9    href="/tracing/ui/extras/system_stats/system_stats_snapshot_view.css">
10
11<link rel="import" href="/tracing/ui/analysis/object_snapshot_view.html">
12
13<script>
14'use strict';
15
16tr.exportTo('tr.ui.e.system_stats', function() {
17  /*
18   * Displays a system stats snapshot in a human readable form. @constructor
19   */
20  var SystemStatsSnapshotView = tr.ui.b.define(
21      'tr-ui-e-system-stats-snapshot-view', tr.ui.analysis.ObjectSnapshotView);
22
23  SystemStatsSnapshotView.prototype = {
24    __proto__: tr.ui.analysis.ObjectSnapshotView.prototype,
25
26    decorate: function() {
27      this.classList.add('tr-ui-e-system-stats-snapshot-view');
28    },
29
30    updateContents: function() {
31      var snapshot = this.objectSnapshot_;
32      if (!snapshot || !snapshot.getStats()) {
33        this.textContent = 'No system stats snapshot found.';
34        return;
35      }
36      // Clear old snapshot view.
37      this.textContent = '';
38
39      var stats = snapshot.getStats();
40      this.appendChild(this.buildList_(stats));
41    },
42
43    isFloat: function(n) {
44      return typeof n === 'number' && n % 1 !== 0;
45    },
46
47    /**
48     * Creates nested lists.
49     *
50     * @param {Object} stats The current trace system stats entry.
51     * @return {Element} A ul list element.
52     */
53    buildList_: function(stats) {
54      var statList = document.createElement('ul');
55
56      for (var statName in stats) {
57        var statText = document.createElement('li');
58        statText.textContent = '' + statName + ': ';
59        statList.appendChild(statText);
60
61        if (stats[statName] instanceof Object) {
62          statList.appendChild(this.buildList_(stats[statName]));
63        } else {
64          if (this.isFloat(stats[statName]))
65            statText.textContent += stats[statName].toFixed(2);
66          else
67            statText.textContent += stats[statName];
68        }
69      }
70
71      return statList;
72    }
73  };
74
75  tr.ui.analysis.ObjectSnapshotView.register(
76      SystemStatsSnapshotView,
77      {typeName: 'base::TraceEventSystemStatsMonitor::SystemStats'});
78
79  return {
80    SystemStatsSnapshotView: SystemStatsSnapshotView
81  };
82
83});
84</script>
85