Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / trace_model / counter_series.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
8 <link rel="import" href="/tracing/trace_model/counter_sample.html">
9
10 <script>
11 'use strict';
12
13 /**
14  * @fileoverview Provides the CounterSeries class.
15  */
16 tvcm.exportTo('tracing.trace_model', function() {
17   var CounterSample = tracing.trace_model.CounterSample;
18
19   function CounterSeries(name, color) {
20     this.guid_ = tvcm.GUID.allocate();
21
22     this.name_ = name;
23     this.color_ = color;
24
25     this.timestamps_ = [];
26     this.samples_ = [];
27
28     // Set by counter.addSeries
29     this.counter = undefined;
30     this.seriesIndex = undefined;
31   }
32
33   CounterSeries.prototype = {
34     __proto__: Object.prototype,
35
36     toJSON: function() {
37       var obj = new Object();
38       var keys = Object.keys(this);
39       for (var i = 0; i < keys.length; i++) {
40         var key = keys[i];
41         if (typeof this[key] == 'function')
42           continue;
43         if (key == 'counter') {
44           obj[key] = this[key].guid;
45           continue;
46         }
47         obj[key] = this[key];
48       }
49       return obj;
50     },
51
52     get length() {
53       return this.timestamps_.length;
54     },
55
56     get name() {
57       return this.name_;
58     },
59
60     get color() {
61       return this.color_;
62     },
63
64     get samples() {
65       return this.samples_;
66     },
67
68     get timestamps() {
69       return this.timestamps_;
70     },
71
72     getSample: function(idx) {
73       return this.samples_[idx];
74     },
75
76     getTimestamp: function(idx) {
77       return this.timestamps_[idx];
78     },
79
80     addCounterSample: function(ts, val) {
81       this.timestamps_.push(ts);
82       var sample = new CounterSample(this, ts, val);
83       this.samples_.push(sample);
84       return sample;
85     },
86
87     getStatistics: function(sampleIndices) {
88       var sum = 0;
89       var min = Number.MAX_VALUE;
90       var max = -Number.MAX_VALUE;
91
92       for (var i = 0; i < sampleIndices.length; ++i) {
93         var sample = this.getSample(sampleIndices[i]).value;
94
95         sum += sample;
96         min = Math.min(sample, min);
97         max = Math.max(sample, max);
98       }
99
100       return {
101         min: min,
102         max: max,
103         avg: (sum / sampleIndices.length),
104         start: this.getSample(sampleIndices[0]).value,
105         end: this.getSample(sampleIndices.length - 1).value
106       };
107     },
108
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];
113       }
114     },
115
116     iterateAllEvents: function(callback, opt_this) {
117       this.samples_.forEach(callback, opt_this);
118     }
119   };
120
121   return {
122     CounterSeries: CounterSeries
123   };
124 });
125 </script>
126