| OLD | NEW |
| (Empty) |
| 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 | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 class Counter(object): | |
| 6 ''' Stores all the samples for a given counter. | |
| 7 ''' | |
| 8 def __init__(self, parent, category, name): | |
| 9 self.parent = parent | |
| 10 self.full_name = category + '.' + name | |
| 11 self.category = category | |
| 12 self.name = name | |
| 13 self.samples = [] | |
| 14 self.timestamps = [] | |
| 15 self.series_names = [] | |
| 16 self.totals = [] | |
| 17 self.max_total = 0 | |
| 18 self._bounds = None | |
| 19 | |
| 20 @property | |
| 21 def min_timestamp(self): | |
| 22 if not self._bounds: | |
| 23 self.UpdateBounds() | |
| 24 return self._bounds[0] | |
| 25 | |
| 26 @property | |
| 27 def max_timestamp(self): | |
| 28 if not self._bounds: | |
| 29 self.UpdateBounds() | |
| 30 return self._bounds[1] | |
| 31 | |
| 32 @property | |
| 33 def num_series(self): | |
| 34 return len(self.series_names) | |
| 35 | |
| 36 @property | |
| 37 def num_samples(self): | |
| 38 return len(self.timestamps) | |
| 39 | |
| 40 def UpdateBounds(self): | |
| 41 if self.num_series * self.num_samples != len(self.samples): | |
| 42 raise ValueError( | |
| 43 'Length of samples must be a multiple of length of timestamps.') | |
| 44 | |
| 45 self.totals = [] | |
| 46 self.max_total = 0 | |
| 47 if not len(self.samples): | |
| 48 return | |
| 49 | |
| 50 self._bounds = (self.timestamps[0], self.timestamps[-1]) | |
| 51 | |
| 52 max_total = None | |
| 53 for i in xrange(self.num_samples): | |
| 54 total = 0 | |
| 55 for j in xrange(self.num_series): | |
| 56 total += self.samples[i * self.num_series + j] | |
| 57 self.totals.append(total) | |
| 58 if max_total is None or total > max_total: | |
| 59 max_total = total | |
| 60 self.max_total = max_total | |
| 61 | |
| OLD | NEW |