blob: 66b827f9c605721100441508f5b228b26b4f549e [file] [log] [blame]
<!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="import" href="/core/trace_model/event.html">
<link rel="import" href="/base/iteration_helpers.html">
<link rel="import" href="/core/analysis/util.html">
<link rel="import" href="/base/sorted_array_utils.html">
<script>
'use strict';
tv.exportTo('tv.c.trace_model', function() {
function CounterSample(series, timestamp, value) {
tv.c.trace_model.Event.call(this);
this.series_ = series;
this.timestamp_ = timestamp;
this.value_ = value;
}
CounterSample.groupByTimestamp = function(samples) {
var samplesByTimestamp = {};
for (var i = 0; i < samples.length; i++) {
var sample = samples[i];
var ts = sample.timestamp;
if (!samplesByTimestamp[ts])
samplesByTimestamp[ts] = [];
samplesByTimestamp[ts].push(sample);
}
var timestamps = tv.b.dictionaryKeys(samplesByTimestamp);
timestamps.sort();
var groups = [];
for (var i = 0; i < timestamps.length; i++) {
var ts = timestamps[i];
var group = samplesByTimestamp[ts];
group.sort(function(x, y) {
return x.series.seriesIndex - y.series.seriesIndex;
});
groups.push(group);
}
return groups;
}
CounterSample.prototype = {
__proto__: tv.c.trace_model.Event.prototype,
get series() {
return this.series_;
},
get timestamp() {
return this.timestamp_;
},
get value() {
return this.value_;
},
set timestamp(timestamp) {
this.timestamp_ = timestamp;
},
addBoundsToRange: function(range) {
range.addValue(this.timestamp);
},
getSampleIndex: function() {
return tv.b.findLowIndexInSortedArray(
this.series.timestamps,
function(x) { return x; },
this.timestamp_);
},
get userFriendlyName() {
return 'Counter sample from ' + this.series_.title + ' at ' +
tv.c.analysis.tsString(this.timestamp);
}
};
tv.c.trace_model.EventRegistry.register(
CounterSample,
{
name: 'counterSample',
pluralName: 'counterSamples',
singleViewElementName: 'tv-c-counter-sample-sub-view',
multiViewElementName: 'tv-c-counter-sample-sub-view'
});
return {
CounterSample: CounterSample
};
});
</script>