Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: base/metrics/histogram_samples.cc

Issue 2973603002: Remove typically unused local_metadata_ field. (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/metrics/histogram_samples.h ('k') | base/metrics/sample_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <limits> 7 #include <limits>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/numerics/safe_conversions.h" 10 #include "base/numerics/safe_conversions.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool HistogramSamples::AtomicSingleSample::IsDisabled() const { 157 bool HistogramSamples::AtomicSingleSample::IsDisabled() const {
158 return subtle::Acquire_Load(&as_atomic) == kDisabledSingleSample; 158 return subtle::Acquire_Load(&as_atomic) == kDisabledSingleSample;
159 } 159 }
160 160
161 HistogramSamples::LocalMetadata::LocalMetadata() { 161 HistogramSamples::LocalMetadata::LocalMetadata() {
162 // This is the same way it's done for persistent metadata since no ctor 162 // This is the same way it's done for persistent metadata since no ctor
163 // is called for the data members in that case. 163 // is called for the data members in that case.
164 memset(this, 0, sizeof(*this)); 164 memset(this, 0, sizeof(*this));
165 } 165 }
166 166
167 // Don't try to delegate behavior to the constructor below that accepts a
168 // Matadata pointer by passing &local_meta_. Such cannot be reliably passed
169 // because it has not yet been constructed -- no member variables have; the
170 // class itself is in the middle of being constructed. Using it to
171 // initialize meta_ is okay because the object now exists and local_meta_
172 // is before meta_ in the construction order.
173 HistogramSamples::HistogramSamples(uint64_t id)
174 : meta_(&local_meta_) {
175 meta_->id = id;
176 }
177
178 HistogramSamples::HistogramSamples(uint64_t id, Metadata* meta) 167 HistogramSamples::HistogramSamples(uint64_t id, Metadata* meta)
179 : meta_(meta) { 168 : meta_(meta) {
180 DCHECK(meta_->id == 0 || meta_->id == id); 169 DCHECK(meta_->id == 0 || meta_->id == id);
181 170
182 // It's possible that |meta| is contained in initialized, read-only memory 171 // It's possible that |meta| is contained in initialized, read-only memory
183 // so it's essential that no write be done in that case. 172 // so it's essential that no write be done in that case.
184 if (!meta_->id) 173 if (!meta_->id)
185 meta_->id = id; 174 meta_->id = id;
186 } 175 }
187 176
177 // This mustn't do anything with |meta_|. It was passed to the ctor and may
178 // be invalid by the time this dtor gets called.
188 HistogramSamples::~HistogramSamples() {} 179 HistogramSamples::~HistogramSamples() {}
189 180
190 void HistogramSamples::Add(const HistogramSamples& other) { 181 void HistogramSamples::Add(const HistogramSamples& other) {
191 IncreaseSumAndCount(other.sum(), other.redundant_count()); 182 IncreaseSumAndCount(other.sum(), other.redundant_count());
192 std::unique_ptr<SampleCountIterator> it = other.Iterator(); 183 std::unique_ptr<SampleCountIterator> it = other.Iterator();
193 bool success = AddSubtractImpl(it.get(), ADD); 184 bool success = AddSubtractImpl(it.get(), ADD);
194 DCHECK(success); 185 DCHECK(success);
195 } 186 }
196 187
197 bool HistogramSamples::AddFromPickle(PickleIterator* iter) { 188 bool HistogramSamples::AddFromPickle(PickleIterator* iter) {
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 289
299 bool SingleSampleIterator::GetBucketIndex(size_t* index) const { 290 bool SingleSampleIterator::GetBucketIndex(size_t* index) const {
300 DCHECK(!Done()); 291 DCHECK(!Done());
301 if (bucket_index_ == kSizeMax) 292 if (bucket_index_ == kSizeMax)
302 return false; 293 return false;
303 *index = bucket_index_; 294 *index = bucket_index_;
304 return true; 295 return true;
305 } 296 }
306 297
307 } // namespace base 298 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_samples.h ('k') | base/metrics/sample_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698