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.
6 tvcm.require('tvcm.iteration_helpers');
7 tvcm.require('tvcm.sorted_array_utils');
8 tvcm.require('tracing.trace_model.event');
10 tvcm.exportTo('tracing.trace_model', function() {
11 function CounterSample(series, timestamp, value) {
12 tracing.trace_model.Event.call(this);
13 this.series_ = series;
14 this.timestamp_ = timestamp;
18 CounterSample.groupByTimestamp = function(samples) {
19 var samplesByTimestamp = {};
20 for (var i = 0; i < samples.length; i++) {
21 var sample = samples[i];
22 var ts = sample.timestamp;
23 if (!samplesByTimestamp[ts])
24 samplesByTimestamp[ts] = [];
25 samplesByTimestamp[ts].push(sample);
27 var timestamps = tvcm.dictionaryKeys(samplesByTimestamp);
30 for (var i = 0; i < timestamps.length; i++) {
31 var ts = timestamps[i];
32 var group = samplesByTimestamp[ts];
33 group.sort(function(x, y) {
34 return x.series.seriesIndex - y.series.seriesIndex;
41 CounterSample.prototype = {
42 __proto__: tracing.trace_model.Event.prototype,
49 return this.timestamp_;
56 set timestamp(timestamp) {
57 this.timestamp_ = timestamp;
60 addBoundsToRange: function(range) {
61 range.addValue(this.timestamp);
65 var obj = new Object();
66 var keys = Object.keys(this);
67 for (var i = 0; i < keys.length; i++) {
69 if (typeof this[key] == 'function')
71 if (key == 'series_') {
72 obj[key] = this[key].guid;
80 getSampleIndex: function() {
81 return tvcm.findLowIndexInSortedArray(
82 this.series.timestamps,
83 function(x) { return x; },
89 CounterSample: CounterSample