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

Side by Side Diff: chrome/renderer/renderer_histogram_snapshots.cc

Issue 4174002: Try to detect internal corruption of histogram instances.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | « chrome/common/metrics_helpers.cc ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/renderer/renderer_histogram_snapshots.h" 5 #include "chrome/renderer/renderer_histogram_snapshots.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 (*it)->SetFlags(Histogram::kIPCSerializationSourceFlag); 45 (*it)->SetFlags(Histogram::kIPCSerializationSourceFlag);
46 UploadHistrogram(**it, &pickled_histograms); 46 UploadHistrogram(**it, &pickled_histograms);
47 } 47 }
48 // Send the sequence number and list of pickled histograms over synchronous 48 // Send the sequence number and list of pickled histograms over synchronous
49 // IPC. 49 // IPC.
50 RenderThread::current()->Send( 50 RenderThread::current()->Send(
51 new ViewHostMsg_RendererHistograms( 51 new ViewHostMsg_RendererHistograms(
52 sequence_number, pickled_histograms)); 52 sequence_number, pickled_histograms));
53 } 53 }
54 54
55 // Extract snapshot data and then send it off the the Browser process 55 // Extract snapshot data, remember what we've seen so far, and then send off the
56 // to save it. 56 // delta to the browser.
57 void RendererHistogramSnapshots::UploadHistrogram( 57 void RendererHistogramSnapshots::UploadHistrogram(
58 const Histogram& histogram, 58 const Histogram& histogram,
59 HistogramPickledList* pickled_histograms) { 59 HistogramPickledList* pickled_histograms) {
60
61 // Get up-to-date snapshot of sample stats. 60 // Get up-to-date snapshot of sample stats.
62 Histogram::SampleSet snapshot; 61 Histogram::SampleSet snapshot;
63 histogram.SnapshotSample(&snapshot); 62 histogram.SnapshotSample(&snapshot);
64 const std::string& histogram_name = histogram.histogram_name(); 63 const std::string& histogram_name = histogram.histogram_name();
65 64
65 int corruption = histogram.FindCorruption(snapshot);
66 if (corruption) {
67 NOTREACHED();
68 // Don't send corrupt data to the browser.
69 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRenderer",
70 corruption, Histogram::NEVER_EXCEEDED_VALUE);
71 typedef std::map<std::string, int> ProblemMap;
72 static ProblemMap* inconsistencies = new ProblemMap;
73 int old_corruption = (*inconsistencies)[histogram_name];
74 if (old_corruption == (corruption | old_corruption))
75 return; // We've already seen this corruption for this histogram.
76 (*inconsistencies)[histogram_name] |= corruption;
77 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRendererUnique",
78 corruption, Histogram::NEVER_EXCEEDED_VALUE);
79 return;
80 }
81
66 // Find the already sent stats, or create an empty set. 82 // Find the already sent stats, or create an empty set.
67 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); 83 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
68 Histogram::SampleSet* already_logged; 84 Histogram::SampleSet* already_logged;
69 if (logged_samples_.end() == it) { 85 if (logged_samples_.end() == it) {
70 // Add new entry. 86 // Add new entry.
71 already_logged = &logged_samples_[histogram.histogram_name()]; 87 already_logged = &logged_samples_[histogram.histogram_name()];
72 already_logged->Resize(histogram); // Complete initialization. 88 already_logged->Resize(histogram); // Complete initialization.
73 } else { 89 } else {
74 already_logged = &(it->second); 90 already_logged = &(it->second);
75 // Deduct any stats we've already logged from our snapshot. 91 // Deduct any stats we've already logged from our snapshot.
76 snapshot.Subtract(*already_logged); 92 snapshot.Subtract(*already_logged);
77 } 93 }
78 94
79 // Snapshot now contains only a delta to what we've already_logged. 95 // Snapshot now contains only a delta to what we've already_logged.
80 96
81 if (snapshot.TotalCount() > 0) { 97 if (snapshot.TotalCount() > 0) {
82 UploadHistogramDelta(histogram, snapshot, pickled_histograms); 98 UploadHistogramDelta(histogram, snapshot, pickled_histograms);
83 // Add new data into our running total. 99 // Add new data into our running total.
84 already_logged->Add(snapshot); 100 already_logged->Add(snapshot);
85 } 101 }
86 } 102 }
87 103
88 void RendererHistogramSnapshots::UploadHistogramDelta( 104 void RendererHistogramSnapshots::UploadHistogramDelta(
89 const Histogram& histogram, 105 const Histogram& histogram,
90 const Histogram::SampleSet& snapshot, 106 const Histogram::SampleSet& snapshot,
91 HistogramPickledList* pickled_histograms) { 107 HistogramPickledList* pickled_histograms) {
92
93 DCHECK(0 != snapshot.TotalCount()); 108 DCHECK(0 != snapshot.TotalCount());
94 snapshot.CheckSize(histogram); 109 snapshot.CheckSize(histogram);
95 110
96 std::string histogram_info = 111 std::string histogram_info =
97 Histogram::SerializeHistogramInfo(histogram, snapshot); 112 Histogram::SerializeHistogramInfo(histogram, snapshot);
98 pickled_histograms->push_back(histogram_info); 113 pickled_histograms->push_back(histogram_info);
99 } 114 }
OLDNEW
« no previous file with comments | « chrome/common/metrics_helpers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698