Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 class Counter(object): | 5 import telemetry.core.timeline.event_container as event_container |
| 6 ''' Stores all the samples for a given counter. | 6 |
| 7 ''' | 7 # Doesnt' inherit from TimelineEvent because its only a temporary wrapper of a |
|
Tim Song
2013/07/18 22:56:36
typo here for Doesn't
| |
| 8 # counter sample into an event. During stable operation, the samples are stored | |
| 9 # a dense array of values rather than in the long-form done by an Event. | |
| 10 class CounterSample(object): | |
| 11 def __init__(self, counter, sample_index): | |
| 12 self._counter = counter | |
| 13 self._sample_index = sample_index | |
| 14 | |
| 15 @property | |
| 16 def name(self): | |
| 17 return None | |
| 18 | |
| 19 @property | |
| 20 def start(self): | |
| 21 return self._counter.timestamps[self._sample_index] | |
| 22 | |
| 23 @start.setter | |
| 24 def start(self, start): | |
| 25 self._counter.timestamps[self._sample_index] = start | |
| 26 | |
| 27 @property | |
| 28 def duration(self): | |
| 29 return 0 | |
| 30 | |
| 31 @property | |
| 32 def end(self): | |
| 33 return self.start | |
| 34 | |
| 35 | |
| 36 class Counter(event_container.TimelineEventContainer): | |
| 37 """ Stores all the samples for a given counter. | |
| 38 """ | |
| 8 def __init__(self, parent, category, name): | 39 def __init__(self, parent, category, name): |
| 9 self.parent = parent | 40 super(Counter, self).__init__(name, parent) |
| 41 self.category = category | |
| 10 self.full_name = category + '.' + name | 42 self.full_name = category + '.' + name |
| 11 self.category = category | |
| 12 self.name = name | |
| 13 self.samples = [] | 43 self.samples = [] |
| 14 self.timestamps = [] | 44 self.timestamps = [] |
| 15 self.series_names = [] | 45 self.series_names = [] |
| 16 self.totals = [] | 46 self.totals = [] |
| 17 self.max_total = 0 | 47 self.max_total = 0 |
| 18 self._bounds = None | |
| 19 | 48 |
| 20 @property | 49 def IterChildContainers(self): |
| 21 def min_timestamp(self): | 50 return |
| 22 if not self._bounds: | 51 yield # pylint: disable=W0101 |
| 23 self.UpdateBounds() | |
| 24 return self._bounds[0] | |
| 25 | 52 |
| 26 @property | 53 def IterEventsInThisContainer(self): |
| 27 def max_timestamp(self): | 54 for i in range(len(self.timestamps)): |
| 28 if not self._bounds: | 55 yield CounterSample(self, i) |
| 29 self.UpdateBounds() | |
| 30 return self._bounds[1] | |
| 31 | 56 |
| 32 @property | 57 @property |
| 33 def num_series(self): | 58 def num_series(self): |
| 34 return len(self.series_names) | 59 return len(self.series_names) |
| 35 | 60 |
| 36 @property | 61 @property |
| 37 def num_samples(self): | 62 def num_samples(self): |
| 38 return len(self.timestamps) | 63 return len(self.timestamps) |
| 39 | 64 |
| 40 def UpdateBounds(self): | 65 def FinalizeImport(self): |
| 41 if self.num_series * self.num_samples != len(self.samples): | 66 if self.num_series * self.num_samples != len(self.samples): |
| 42 raise ValueError( | 67 raise ValueError( |
| 43 'Length of samples must be a multiple of length of timestamps.') | 68 'Length of samples must be a multiple of length of timestamps.') |
| 44 | 69 |
| 45 self.totals = [] | 70 self.totals = [] |
| 46 self.max_total = 0 | 71 self.max_total = 0 |
| 47 if not len(self.samples): | 72 if not len(self.samples): |
| 48 return | 73 return |
| 49 | 74 |
| 50 self._bounds = (self.timestamps[0], self.timestamps[-1]) | |
| 51 | |
| 52 max_total = None | 75 max_total = None |
| 53 for i in xrange(self.num_samples): | 76 for i in xrange(self.num_samples): |
| 54 total = 0 | 77 total = 0 |
| 55 for j in xrange(self.num_series): | 78 for j in xrange(self.num_series): |
| 56 total += self.samples[i * self.num_series + j] | 79 total += self.samples[i * self.num_series + j] |
| 57 self.totals.append(total) | 80 self.totals.append(total) |
| 58 if max_total is None or total > max_total: | 81 if max_total is None or total > max_total: |
| 59 max_total = total | 82 max_total = total |
| 60 self.max_total = max_total | 83 self.max_total = max_total |
| 61 | |
| OLD | NEW |