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

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

Issue 10454086: Histograms - Support histograms for Plugins, GPU (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « base/metrics/histogram_snapshot_manager.h ('k') | chrome/browser/browser_about_handler.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 "chrome/common/metrics/histogram_sender.h" 5 #include "base/metrics/histogram_snapshot_manager.h"
6 6
7 using base::Histogram; 7 using base::Histogram;
8 using base::StatisticsRecorder; 8 using base::StatisticsRecorder;
9 9
10 HistogramSender::HistogramSender() {} 10 namespace base {
11 11
12 HistogramSender::~HistogramSender() {} 12 HistogramSnapshotManager::HistogramSnapshotManager(
13 HistogramFlattener* histogram_flattener)
14 : histogram_flattener_(histogram_flattener) {
15 DCHECK(histogram_flattener_);
16 }
13 17
14 void HistogramSender::TransmitAllHistograms(Histogram::Flags flag_to_set, 18 HistogramSnapshotManager::~HistogramSnapshotManager() {}
15 bool send_only_uma) { 19
20 void HistogramSnapshotManager::PrepareDeltas(Histogram::Flags flag_to_set,
21 bool record_only_uma) {
16 StatisticsRecorder::Histograms histograms; 22 StatisticsRecorder::Histograms histograms;
17 StatisticsRecorder::GetHistograms(&histograms); 23 StatisticsRecorder::GetHistograms(&histograms);
18 for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin(); 24 for (StatisticsRecorder::Histograms::const_iterator it = histograms.begin();
19 histograms.end() != it; 25 histograms.end() != it;
20 ++it) { 26 ++it) {
21 (*it)->SetFlags(flag_to_set); 27 (*it)->SetFlags(flag_to_set);
22 if (send_only_uma && 28 if (record_only_uma &&
23 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag)) 29 0 == ((*it)->flags() & Histogram::kUmaTargetedHistogramFlag))
24 continue; 30 continue;
25 TransmitHistogram(**it); 31 PrepareDelta(**it);
26 } 32 }
27 } 33 }
28 34
29 void HistogramSender::TransmitHistogram(const Histogram& histogram) { 35 void HistogramSnapshotManager::PrepareDelta(const Histogram& histogram) {
36 DCHECK(histogram_flattener_);
37
30 // Get up-to-date snapshot of sample stats. 38 // Get up-to-date snapshot of sample stats.
31 Histogram::SampleSet snapshot; 39 Histogram::SampleSet snapshot;
32 histogram.SnapshotSample(&snapshot); 40 histogram.SnapshotSample(&snapshot);
33 const std::string& histogram_name = histogram.histogram_name(); 41 const std::string& histogram_name = histogram.histogram_name();
34 42
35 int corruption = histogram.FindCorruption(snapshot); 43 int corruption = histogram.FindCorruption(snapshot);
36 44
37 // Crash if we detect that our histograms have been overwritten. This may be 45 // Crash if we detect that our histograms have been overwritten. This may be
38 // a fair distance from the memory smasher, but we hope to correlate these 46 // a fair distance from the memory smasher, but we hope to correlate these
39 // crashes with other events, such as plugins, or usage patterns, etc. 47 // crashes with other events, such as plugins, or usage patterns, etc.
40 if (Histogram::BUCKET_ORDER_ERROR & corruption) { 48 if (Histogram::BUCKET_ORDER_ERROR & corruption) {
41 // The checksum should have caught this, so crash separately if it didn't. 49 // The checksum should have caught this, so crash separately if it didn't.
42 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); 50 CHECK_NE(0, Histogram::RANGE_CHECKSUM_ERROR & corruption);
43 CHECK(false); // Crash for the bucket order corruption. 51 CHECK(false); // Crash for the bucket order corruption.
44 } 52 }
45 // Checksum corruption might not have caused order corruption. 53 // Checksum corruption might not have caused order corruption.
46 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption); 54 CHECK_EQ(0, Histogram::RANGE_CHECKSUM_ERROR & corruption);
47 55
48 if (corruption) { 56 if (corruption) {
49 NOTREACHED(); 57 NOTREACHED();
50 InconsistencyDetected(corruption); 58 histogram_flattener_->InconsistencyDetected(corruption);
51 // Don't send corrupt data to metrics survices. 59 // Don't record corrupt data to metrics survices.
52 if (NULL == inconsistencies_.get()) 60 if (NULL == inconsistencies_.get())
53 inconsistencies_.reset(new ProblemMap); 61 inconsistencies_.reset(new ProblemMap);
54 int old_corruption = (*inconsistencies_)[histogram_name]; 62 int old_corruption = (*inconsistencies_)[histogram_name];
55 if (old_corruption == (corruption | old_corruption)) 63 if (old_corruption == (corruption | old_corruption))
56 return; // We've already seen this corruption for this histogram. 64 return; // We've already seen this corruption for this histogram.
57 (*inconsistencies_)[histogram_name] |= corruption; 65 (*inconsistencies_)[histogram_name] |= corruption;
58 UniqueInconsistencyDetected(corruption); 66 histogram_flattener_->UniqueInconsistencyDetected(corruption);
59 return; 67 return;
60 } 68 }
61 69
62 // Find the already sent stats, or create an empty set. Remove from our 70 // Find the already recorded stats, or create an empty set. Remove from our
63 // snapshot anything that we've already sent. 71 // snapshot anything that we've already recorded.
64 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); 72 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
65 Histogram::SampleSet* already_logged; 73 Histogram::SampleSet* already_logged;
66 if (logged_samples_.end() == it) { 74 if (logged_samples_.end() == it) {
67 // Add new entry 75 // Add new entry
68 already_logged = &logged_samples_[histogram.histogram_name()]; 76 already_logged = &logged_samples_[histogram.histogram_name()];
69 already_logged->Resize(histogram); // Complete initialization. 77 already_logged->Resize(histogram); // Complete initialization.
70 } else { 78 } else {
71 already_logged = &(it->second); 79 already_logged = &(it->second);
72 int64 discrepancy(already_logged->TotalCount() - 80 int64 discrepancy(already_logged->TotalCount() -
73 already_logged->redundant_count()); 81 already_logged->redundant_count());
74 if (discrepancy) { 82 if (discrepancy) {
75 NOTREACHED(); // Already_logged has become corrupt. 83 NOTREACHED(); // Already_logged has become corrupt.
76 int problem = static_cast<int>(discrepancy); 84 int problem = static_cast<int>(discrepancy);
77 if (problem != discrepancy) 85 if (problem != discrepancy)
78 problem = INT_MAX; 86 problem = INT_MAX;
79 SnapshotProblemResolved(problem); 87 histogram_flattener_->SnapshotProblemResolved(problem);
80 // With no valid baseline, we'll act like we've sent everything in our 88 // With no valid baseline, we'll act like we've recorded everything in our
81 // snapshot. 89 // snapshot.
82 already_logged->Subtract(*already_logged); 90 already_logged->Subtract(*already_logged);
83 already_logged->Add(snapshot); 91 already_logged->Add(snapshot);
84 } 92 }
85 // Deduct any stats we've already logged from our snapshot. 93 // Deduct any stats we've already logged from our snapshot.
86 snapshot.Subtract(*already_logged); 94 snapshot.Subtract(*already_logged);
87 } 95 }
88 96
89 // Snapshot now contains only a delta to what we've already_logged. 97 // Snapshot now contains only a delta to what we've already_logged.
90 if (snapshot.redundant_count() > 0) { 98 if (snapshot.redundant_count() > 0) {
91 TransmitHistogramDelta(histogram, snapshot); 99 histogram_flattener_->RecordDelta(histogram, snapshot);
92 // Add new data into our running total. 100 // Add new data into our running total.
93 already_logged->Add(snapshot); 101 already_logged->Add(snapshot);
94 } 102 }
95 } 103 }
104 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_snapshot_manager.h ('k') | chrome/browser/browser_about_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698