OLD | NEW |
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 #include "counter.h" | 5 #include "counter.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 | 8 |
9 #include <base/eintr_wrapper.h> | 9 #include <base/eintr_wrapper.h> |
10 #include <base/logging.h> | 10 #include <base/logging.h> |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 case kRecordNull: | 176 case kRecordNull: |
177 case kRecordValid: | 177 case kRecordValid: |
178 // Nothing to do. | 178 // Nothing to do. |
179 break; | 179 break; |
180 | 180 |
181 default: | 181 default: |
182 NOTREACHED(); | 182 NOTREACHED(); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
| 186 FrequencyCounter::FrequencyCounter() : cycle_duration_(1) { |
| 187 } |
| 188 |
| 189 FrequencyCounter::~FrequencyCounter() { |
| 190 } |
| 191 |
| 192 void FrequencyCounter::Init(const char* filename, |
| 193 TaggedCounterInterface::Reporter reporter, |
| 194 void* reporter_handle, |
| 195 time_t cycle_duration) { |
| 196 // Allow tests to inject tagged_counter_ dependency. |
| 197 if (tagged_counter_.get() == NULL) { |
| 198 tagged_counter_.reset(new TaggedCounter()); |
| 199 } |
| 200 tagged_counter_->Init(filename, reporter, reporter_handle); |
| 201 DCHECK(cycle_duration > 0); |
| 202 cycle_duration_ = cycle_duration; |
| 203 } |
| 204 |
| 205 void FrequencyCounter::UpdateInternal(int32 count, time_t now) { |
| 206 DCHECK(tagged_counter_.get() != NULL); |
| 207 tagged_counter_->Update(GetCycleNumber(now), count); |
| 208 } |
| 209 |
| 210 int32 FrequencyCounter::GetCycleNumber(time_t now) { |
| 211 return now / cycle_duration_; |
| 212 } |
| 213 |
186 } // namespace chromeos_metrics | 214 } // namespace chromeos_metrics |
OLD | NEW |