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

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

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: fixed compile problems on non-Windows builds Created 4 years, 11 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/histogram_snapshot_manager.h" 5 #include "base/metrics/histogram_snapshot_manager.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/histogram_flattener.h" 8 #include "base/metrics/histogram_flattener.h"
9 #include "base/metrics/histogram_samples.h" 9 #include "base/metrics/histogram_samples.h"
10 #include "base/metrics/statistics_recorder.h" 10 #include "base/metrics/statistics_recorder.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 12
13 namespace base { 13 namespace base {
14 14
15 HistogramSnapshotManager::HistogramSnapshotManager( 15 HistogramSnapshotManager::HistogramSnapshotManager(
16 HistogramFlattener* histogram_flattener) 16 HistogramFlattener* histogram_flattener)
17 : histogram_flattener_(histogram_flattener) { 17 : histogram_flattener_(histogram_flattener) {
18 DCHECK(histogram_flattener_); 18 DCHECK(histogram_flattener_);
19 } 19 }
20 20
21 HistogramSnapshotManager::~HistogramSnapshotManager() { 21 HistogramSnapshotManager::~HistogramSnapshotManager() {
22 STLDeleteValues(&logged_samples_); 22 STLDeleteValues(&logged_samples_);
23 } 23 }
24 24
25 void HistogramSnapshotManager::PrepareDeltas(
26 HistogramBase::Flags flag_to_set,
27 HistogramBase::Flags required_flags) {
28 StatisticsRecorder::Histograms histograms;
29 StatisticsRecorder::GetHistograms(&histograms);
30 for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin();
31 histograms.end() != it;
32 ++it) {
33 (*it)->SetFlags(flag_to_set);
34 if (((*it)->flags() & required_flags) == required_flags)
35 PrepareDelta(**it);
36 }
37 }
38
39 void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) { 25 void HistogramSnapshotManager::PrepareDelta(const HistogramBase& histogram) {
40 DCHECK(histogram_flattener_); 26 DCHECK(histogram_flattener_);
41 27
42 // Get up-to-date snapshot of sample stats. 28 // Get up-to-date snapshot of sample stats.
43 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples()); 29 scoped_ptr<HistogramSamples> snapshot(histogram.SnapshotSamples());
44 30
45 // Crash if we detect that our histograms have been overwritten. This may be 31 // Crash if we detect that our histograms have been overwritten. This may be
46 // a fair distance from the memory smasher, but we hope to correlate these 32 // a fair distance from the memory smasher, but we hope to correlate these
47 // crashes with other events, such as plugins, or usage patterns, etc. 33 // crashes with other events, such as plugins, or usage patterns, etc.
48 int corruption = histogram.FindCorruption(*snapshot); 34 int corruption = histogram.FindCorruption(*snapshot);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 88
103 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy); 89 histogram_flattener_->InconsistencyDetectedInLoggedCount(discrepancy);
104 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) { 90 if (discrepancy > Histogram::kCommonRaceBasedCountMismatch) {
105 // Fix logged_samples. 91 // Fix logged_samples.
106 logged_samples->Subtract(*logged_samples); 92 logged_samples->Subtract(*logged_samples);
107 logged_samples->Add(new_snapshot); 93 logged_samples->Add(new_snapshot);
108 } 94 }
109 } 95 }
110 96
111 } // namespace base 97 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698