1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 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/iteration_helpers.html"> 9<link rel="import" href="/tracing/base/sorted_array_utils.html"> 10<link rel="import" href="/tracing/model/event.html"> 11<link rel="import" href="/tracing/model/event_registry.html"> 12<link rel="import" href="/tracing/value/unit.html"> 13 14<script> 15'use strict'; 16 17tr.exportTo('tr.model', function() { 18 19 /** 20 * The value of a given measurement at a given time. 21 * 22 * As an example, if we're measuring the throughput of data sent over a USB 23 * connection, each counter sample might represent the instantaneous 24 * throughput of the connection at a given time. 25 * 26 * @constructor 27 * @extends {Event} 28 */ 29 function CounterSample(series, timestamp, value) { 30 tr.model.Event.call(this); 31 this.series_ = series; 32 this.timestamp_ = timestamp; 33 this.value_ = value; 34 } 35 36 CounterSample.groupByTimestamp = function(samples) { 37 var samplesByTimestamp = tr.b.group(samples, function(sample) { 38 return sample.timestamp; 39 }); 40 41 var timestamps = tr.b.dictionaryKeys(samplesByTimestamp); 42 timestamps.sort(); 43 var groups = []; 44 for (var i = 0; i < timestamps.length; i++) { 45 var ts = timestamps[i]; 46 var group = samplesByTimestamp[ts]; 47 group.sort(function(x, y) { 48 return x.series.seriesIndex - y.series.seriesIndex; 49 }); 50 groups.push(group); 51 } 52 return groups; 53 }; 54 55 CounterSample.prototype = { 56 __proto__: tr.model.Event.prototype, 57 58 get series() { 59 return this.series_; 60 }, 61 62 get timestamp() { 63 return this.timestamp_; 64 }, 65 66 get value() { 67 return this.value_; 68 }, 69 70 set timestamp(timestamp) { 71 this.timestamp_ = timestamp; 72 }, 73 74 addBoundsToRange: function(range) { 75 range.addValue(this.timestamp); 76 }, 77 78 getSampleIndex: function() { 79 return tr.b.findLowIndexInSortedArray( 80 this.series.timestamps, 81 function(x) { return x; }, 82 this.timestamp_); 83 }, 84 85 get userFriendlyName() { 86 return 'Counter sample from ' + this.series_.title + ' at ' + 87 tr.v.Unit.byName.timeStampInMs.format(this.timestamp); 88 } 89 }; 90 91 92 tr.model.EventRegistry.register( 93 CounterSample, 94 { 95 name: 'counterSample', 96 pluralName: 'counterSamples', 97 singleViewElementName: 'tr-ui-a-counter-sample-sub-view', 98 multiViewElementName: 'tr-ui-a-counter-sample-sub-view' 99 }); 100 101 return { 102 CounterSample: CounterSample 103 }; 104}); 105</script> 106