OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/metrics/sample_vector.h" | 5 #include "base/metrics/sample_vector.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "base/metrics/persistent_memory_allocator.h" | 10 #include "base/metrics/persistent_memory_allocator.h" |
11 #include "base/numerics/safe_conversions.h" | 11 #include "base/numerics/safe_conversions.h" |
12 #include "base/synchronization/lock.h" | 12 #include "base/synchronization/lock.h" |
13 #include "base/threading/platform_thread.h" | 13 #include "base/threading/platform_thread.h" |
14 | 14 |
15 // This SampleVector makes use of the single-sample embedded in the base | 15 // This SampleVector makes use of the single-sample embedded in the base |
16 // HistogramSamples class. If the count is non-zero then there is guaranteed | 16 // HistogramSamples class. If the count is non-zero then there is guaranteed |
17 // (within the bounds of "eventual consistency") to be no allocated external | 17 // (within the bounds of "eventual consistency") to be no allocated external |
18 // storage. Once the full counts storage is allocated, the single-sample must | 18 // storage. Once the full counts storage is allocated, the single-sample must |
19 // be extracted and disabled. | 19 // be extracted and disabled. |
20 | 20 |
21 namespace base { | 21 namespace base { |
22 | 22 |
23 typedef HistogramBase::Count Count; | 23 typedef HistogramBase::Count Count; |
24 typedef HistogramBase::Sample Sample; | 24 typedef HistogramBase::Sample Sample; |
25 | 25 |
26 SampleVectorBase::SampleVectorBase(uint64_t id, | 26 SampleVectorBase::SampleVectorBase(uint64_t id, |
27 const BucketRanges* bucket_ranges) | |
28 : HistogramSamples(id), bucket_ranges_(bucket_ranges) { | |
29 CHECK_GE(bucket_ranges_->bucket_count(), 1u); | |
30 } | |
31 | |
32 SampleVectorBase::SampleVectorBase(uint64_t id, | |
33 Metadata* meta, | 27 Metadata* meta, |
34 const BucketRanges* bucket_ranges) | 28 const BucketRanges* bucket_ranges) |
35 : HistogramSamples(id, meta), bucket_ranges_(bucket_ranges) { | 29 : HistogramSamples(id, meta), bucket_ranges_(bucket_ranges) { |
36 CHECK_GE(bucket_ranges_->bucket_count(), 1u); | 30 CHECK_GE(bucket_ranges_->bucket_count(), 1u); |
37 } | 31 } |
38 | 32 |
39 SampleVectorBase::~SampleVectorBase() {} | 33 SampleVectorBase::~SampleVectorBase() {} |
40 | 34 |
41 void SampleVectorBase::Accumulate(Sample value, Count count) { | 35 void SampleVectorBase::Accumulate(Sample value, Count count) { |
42 const size_t bucket_index = GetBucketIndex(value); | 36 const size_t bucket_index = GetBucketIndex(value); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 273 } |
280 | 274 |
281 // Move any single-sample into the newly mounted storage. | 275 // Move any single-sample into the newly mounted storage. |
282 MoveSingleSampleToCounts(); | 276 MoveSingleSampleToCounts(); |
283 } | 277 } |
284 | 278 |
285 SampleVector::SampleVector(const BucketRanges* bucket_ranges) | 279 SampleVector::SampleVector(const BucketRanges* bucket_ranges) |
286 : SampleVector(0, bucket_ranges) {} | 280 : SampleVector(0, bucket_ranges) {} |
287 | 281 |
288 SampleVector::SampleVector(uint64_t id, const BucketRanges* bucket_ranges) | 282 SampleVector::SampleVector(uint64_t id, const BucketRanges* bucket_ranges) |
289 : SampleVectorBase(id, bucket_ranges) {} | 283 : SampleVectorBase(id, new LocalMetadata(), bucket_ranges) {} |
290 | 284 |
291 SampleVector::~SampleVector() {} | 285 SampleVector::~SampleVector() { |
| 286 delete static_cast<LocalMetadata*>(meta()); |
| 287 } |
292 | 288 |
293 bool SampleVector::MountExistingCountsStorage() const { | 289 bool SampleVector::MountExistingCountsStorage() const { |
294 // There is never any existing storage other than what is already in use. | 290 // There is never any existing storage other than what is already in use. |
295 return counts() != nullptr; | 291 return counts() != nullptr; |
296 } | 292 } |
297 | 293 |
298 HistogramBase::AtomicCount* SampleVector::CreateCountsStorageWhileLocked() { | 294 HistogramBase::AtomicCount* SampleVector::CreateCountsStorageWhileLocked() { |
299 local_counts_.resize(counts_size()); | 295 local_counts_.resize(counts_size()); |
300 return &local_counts_[0]; | 296 return &local_counts_[0]; |
301 } | 297 } |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 return; | 412 return; |
417 | 413 |
418 while (index_ < counts_size_) { | 414 while (index_ < counts_size_) { |
419 if (subtle::NoBarrier_Load(&counts_[index_]) != 0) | 415 if (subtle::NoBarrier_Load(&counts_[index_]) != 0) |
420 return; | 416 return; |
421 index_++; | 417 index_++; |
422 } | 418 } |
423 } | 419 } |
424 | 420 |
425 } // namespace base | 421 } // namespace base |
OLD | NEW |