3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
8 <link rel="import" href="/tracing/trace_model/counter_sample.html">
14 * @fileoverview Provides the CounterSeries class.
16 tvcm.exportTo('tracing.trace_model', function() {
17 var CounterSample = tracing.trace_model.CounterSample;
19 function CounterSeries(name, color) {
20 this.guid_ = tvcm.GUID.allocate();
25 this.timestamps_ = [];
28 // Set by counter.addSeries
29 this.counter = undefined;
30 this.seriesIndex = undefined;
33 CounterSeries.prototype = {
34 __proto__: Object.prototype,
37 var obj = new Object();
38 var keys = Object.keys(this);
39 for (var i = 0; i < keys.length; i++) {
41 if (typeof this[key] == 'function')
43 if (key == 'counter') {
44 obj[key] = this[key].guid;
53 return this.timestamps_.length;
69 return this.timestamps_;
72 getSample: function(idx) {
73 return this.samples_[idx];
76 getTimestamp: function(idx) {
77 return this.timestamps_[idx];
80 addCounterSample: function(ts, val) {
81 this.timestamps_.push(ts);
82 var sample = new CounterSample(this, ts, val);
83 this.samples_.push(sample);
87 getStatistics: function(sampleIndices) {
89 var min = Number.MAX_VALUE;
90 var max = -Number.MAX_VALUE;
92 for (var i = 0; i < sampleIndices.length; ++i) {
93 var sample = this.getSample(sampleIndices[i]).value;
96 min = Math.min(sample, min);
97 max = Math.max(sample, max);
103 avg: (sum / sampleIndices.length),
104 start: this.getSample(sampleIndices[0]).value,
105 end: this.getSample(sampleIndices.length - 1).value
109 shiftTimestampsForward: function(amount) {
110 for (var i = 0; i < this.timestamps_.length; ++i) {
111 this.timestamps_[i] += amount;
112 this.samples_[i].timestamp = this.timestamps_[i];
116 iterateAllEvents: function(callback, opt_this) {
117 this.samples_.forEach(callback, opt_this);
122 CounterSeries: CounterSeries