| 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/histogram_samples.h" | 5 #include "base/metrics/histogram_samples.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
| 9 | 9 |
| 10 namespace base { | 10 namespace base { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // initialize meta_ is okay because the object now exists and local_meta_ | 66 // initialize meta_ is okay because the object now exists and local_meta_ |
| 67 // is before meta_ in the construction order. | 67 // is before meta_ in the construction order. |
| 68 HistogramSamples::HistogramSamples(uint64_t id) | 68 HistogramSamples::HistogramSamples(uint64_t id) |
| 69 : meta_(&local_meta_) { | 69 : meta_(&local_meta_) { |
| 70 meta_->id = id; | 70 meta_->id = id; |
| 71 } | 71 } |
| 72 | 72 |
| 73 HistogramSamples::HistogramSamples(uint64_t id, Metadata* meta) | 73 HistogramSamples::HistogramSamples(uint64_t id, Metadata* meta) |
| 74 : meta_(meta) { | 74 : meta_(meta) { |
| 75 DCHECK(meta_->id == 0 || meta_->id == id); | 75 DCHECK(meta_->id == 0 || meta_->id == id); |
| 76 meta_->id = id; | 76 |
| 77 // It's possible that |meta| is contained in initialized, read-only memory |
| 78 // so it's essential that no write be done in that case. |
| 79 if (!meta_->id) |
| 80 meta_->id = id; |
| 77 } | 81 } |
| 78 | 82 |
| 79 HistogramSamples::~HistogramSamples() {} | 83 HistogramSamples::~HistogramSamples() {} |
| 80 | 84 |
| 81 // Despite using atomic operations, the increment/add actions below are *not* | 85 // Despite using atomic operations, the increment/add actions below are *not* |
| 82 // atomic! Race conditions may cause loss of samples or even completely corrupt | 86 // atomic! Race conditions may cause loss of samples or even completely corrupt |
| 83 // the 64-bit sum on 32-bit machines. This is done intentionally to reduce the | 87 // the 64-bit sum on 32-bit machines. This is done intentionally to reduce the |
| 84 // cost of these operations that could be executed in performance-significant | 88 // cost of these operations that could be executed in performance-significant |
| 85 // points of the code. | 89 // points of the code. |
| 86 // | 90 // |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 163 } |
| 160 | 164 |
| 161 SampleCountIterator::~SampleCountIterator() {} | 165 SampleCountIterator::~SampleCountIterator() {} |
| 162 | 166 |
| 163 bool SampleCountIterator::GetBucketIndex(size_t* index) const { | 167 bool SampleCountIterator::GetBucketIndex(size_t* index) const { |
| 164 DCHECK(!Done()); | 168 DCHECK(!Done()); |
| 165 return false; | 169 return false; |
| 166 } | 170 } |
| 167 | 171 |
| 168 } // namespace base | 172 } // namespace base |
| OLD | NEW |