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

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

Issue 1780993002: Break global impact of PersistentHistogramAllocator into a separate class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-hp
Patch Set: addressed review comments by Alexei Created 4 years, 8 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
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/statistics_recorder.h" 5 #include "base/metrics/statistics_recorder.h"
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/metrics_hashes.h" 13 #include "base/metrics/metrics_hashes.h"
14 #include "base/metrics/persistent_histogram_allocator.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
16 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
17 #include "base/values.h" 18 #include "base/values.h"
18 19
19 namespace { 20 namespace {
20 21
21 // Initialize histogram statistics gathering system. 22 // Initialize histogram statistics gathering system.
22 base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ = 23 base::LazyInstance<base::StatisticsRecorder>::Leaky g_statistics_recorder_ =
23 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 282 }
282 283
283 // static 284 // static
284 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) { 285 HistogramBase* StatisticsRecorder::FindHistogram(base::StringPiece name) {
285 if (lock_ == NULL) 286 if (lock_ == NULL)
286 return NULL; 287 return NULL;
287 base::AutoLock auto_lock(*lock_); 288 base::AutoLock auto_lock(*lock_);
288 if (histograms_ == NULL) 289 if (histograms_ == NULL)
289 return NULL; 290 return NULL;
290 291
292 // Import histograms from known persistent storage. Histograms could have
293 // been added by other processes and they must be fetched and recognized
294 // locally. If the persistent memory segment is not shared between processes,
295 // this call does nothing.
296 GlobalHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
297 if (allocator)
298 allocator->ImportHistogramsToStatisticsRecorder();
299
291 HistogramMap::iterator it = histograms_->find(HashMetricName(name)); 300 HistogramMap::iterator it = histograms_->find(HashMetricName(name));
292 if (histograms_->end() == it) 301 if (histograms_->end() == it)
293 return NULL; 302 return NULL;
294 DCHECK_EQ(name, it->second->histogram_name()) << "hash collision"; 303 DCHECK_EQ(name, it->second->histogram_name()) << "hash collision";
295 return it->second; 304 return it->second;
296 } 305 }
297 306
298 // static 307 // static
299 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin( 308 StatisticsRecorder::HistogramIterator StatisticsRecorder::begin(
300 bool include_persistent) { 309 bool include_persistent) {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 // static 466 // static
458 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL; 467 StatisticsRecorder::HistogramMap* StatisticsRecorder::histograms_ = NULL;
459 // static 468 // static
460 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL; 469 StatisticsRecorder::CallbackMap* StatisticsRecorder::callbacks_ = NULL;
461 // static 470 // static
462 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL; 471 StatisticsRecorder::RangesMap* StatisticsRecorder::ranges_ = NULL;
463 // static 472 // static
464 base::Lock* StatisticsRecorder::lock_ = NULL; 473 base::Lock* StatisticsRecorder::lock_ = NULL;
465 474
466 } // namespace base 475 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698