summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/ui/extras/system_stats/system_stats_snapshot_view.html
blob: 11421e91453c2c6299f82f5a72c961713500ef96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!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="/tracing/ui/extras/system_stats/system_stats_snapshot_view.css">

<link rel="import" href="/tracing/ui/analysis/object_snapshot_view.html">

<script>
'use strict';

tr.exportTo('tr.ui.e.system_stats', function() {
  /*
   * Displays a system stats snapshot in a human readable form. @constructor
   */
  var SystemStatsSnapshotView = tr.ui.b.define(
      'tr-ui-e-system-stats-snapshot-view', tr.ui.analysis.ObjectSnapshotView);

  SystemStatsSnapshotView.prototype = {
    __proto__: tr.ui.analysis.ObjectSnapshotView.prototype,

    decorate: function() {
      this.classList.add('tr-ui-e-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.ui.analysis.ObjectSnapshotView.register(
      SystemStatsSnapshotView,
      {typeName: 'base::TraceEventSystemStatsMonitor::SystemStats'});

  return {
    SystemStatsSnapshotView: SystemStatsSnapshotView
  };

});
</script>