• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<!--
3Copyright (c) 2016 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="import" href="/tracing/base/base.html">
9<link rel="import" href="/tracing/value/unit.html">
10
11<script>
12'use strict';
13
14tr.exportTo('tr.model', function() {
15
16  /**
17   * @constructor
18   */
19  function ModelStats() {
20    this.traceEventCountsByKey_ = new Map();
21    this.allTraceEventStats_ = [];
22
23    this.traceEventStatsInTimeIntervals_ = new Map();
24    this.allTraceEventStatsInTimeIntervals_ = [];
25
26    this.hasEventSizesinBytes_ = false;
27  }
28
29  ModelStats.prototype = {
30    TIME_INTERVAL_SIZE_IN_MS: 100,
31
32    willProcessBasicTraceEvent: function(phase, category, title, ts,
33                                         opt_eventSizeinBytes) {
34      var key = phase + '/' + category + '/' + title;
35      var eventStats = this.traceEventCountsByKey_.get(key);
36      if (eventStats === undefined) {
37        eventStats = {
38          phase: phase,
39          category: category,
40          title: title,
41          numEvents: 0,
42          totalEventSizeinBytes: 0
43        };
44        this.traceEventCountsByKey_.set(key, eventStats);
45        this.allTraceEventStats_.push(eventStats);
46      }
47      eventStats.numEvents++;
48
49      var timeIntervalKey = Math.floor(
50          tr.v.Unit.timestampFromUs(ts) / this.TIME_INTERVAL_SIZE_IN_MS);
51      var eventStatsByTimeInverval =
52          this.traceEventStatsInTimeIntervals_.get(timeIntervalKey);
53      if (eventStatsByTimeInverval === undefined) {
54        eventStatsByTimeInverval = {
55          timeInterval: timeIntervalKey,
56          numEvents: 0,
57          totalEventSizeinBytes: 0
58        };
59        this.traceEventStatsInTimeIntervals_.set(timeIntervalKey,
60                                                eventStatsByTimeInverval);
61        this.allTraceEventStatsInTimeIntervals_.push(eventStatsByTimeInverval);
62      }
63      eventStatsByTimeInverval.numEvents++;
64
65      if (opt_eventSizeinBytes !== undefined) {
66        this.hasEventSizesinBytes_ = true;
67        eventStats.totalEventSizeinBytes += opt_eventSizeinBytes;
68        eventStatsByTimeInverval.totalEventSizeinBytes += opt_eventSizeinBytes;
69      }
70    },
71
72    get allTraceEventStats() {
73      return this.allTraceEventStats_;
74    },
75
76    get allTraceEventStatsInTimeIntervals() {
77      return this.allTraceEventStatsInTimeIntervals_;
78    },
79
80    get hasEventSizesinBytes() {
81      return this.hasEventSizesinBytes_;
82    }
83  };
84
85  return {
86    ModelStats: ModelStats
87  };
88});
89</script>
90