OLD | NEW |
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 Loading... |
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, remember what we've seen so far, and then send off the | 55 // Extract snapshot data and then send it off the the Browser process |
56 // delta to the browser. | 56 // to save it. |
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 |
60 // Get up-to-date snapshot of sample stats. | 61 // Get up-to-date snapshot of sample stats. |
61 Histogram::SampleSet snapshot; | 62 Histogram::SampleSet snapshot; |
62 histogram.SnapshotSample(&snapshot); | 63 histogram.SnapshotSample(&snapshot); |
63 const std::string& histogram_name = histogram.histogram_name(); | 64 const std::string& histogram_name = histogram.histogram_name(); |
64 | 65 |
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 | |
82 // Find the already sent stats, or create an empty set. | 66 // Find the already sent stats, or create an empty set. |
83 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); | 67 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name); |
84 Histogram::SampleSet* already_logged; | 68 Histogram::SampleSet* already_logged; |
85 if (logged_samples_.end() == it) { | 69 if (logged_samples_.end() == it) { |
86 // Add new entry. | 70 // Add new entry. |
87 already_logged = &logged_samples_[histogram.histogram_name()]; | 71 already_logged = &logged_samples_[histogram.histogram_name()]; |
88 already_logged->Resize(histogram); // Complete initialization. | 72 already_logged->Resize(histogram); // Complete initialization. |
89 } else { | 73 } else { |
90 already_logged = &(it->second); | 74 already_logged = &(it->second); |
91 // Deduct any stats we've already logged from our snapshot. | 75 // Deduct any stats we've already logged from our snapshot. |
92 snapshot.Subtract(*already_logged); | 76 snapshot.Subtract(*already_logged); |
93 } | 77 } |
94 | 78 |
95 // Snapshot now contains only a delta to what we've already_logged. | 79 // Snapshot now contains only a delta to what we've already_logged. |
96 | 80 |
97 if (snapshot.TotalCount() > 0) { | 81 if (snapshot.TotalCount() > 0) { |
98 UploadHistogramDelta(histogram, snapshot, pickled_histograms); | 82 UploadHistogramDelta(histogram, snapshot, pickled_histograms); |
99 // Add new data into our running total. | 83 // Add new data into our running total. |
100 already_logged->Add(snapshot); | 84 already_logged->Add(snapshot); |
101 } | 85 } |
102 } | 86 } |
103 | 87 |
104 void RendererHistogramSnapshots::UploadHistogramDelta( | 88 void RendererHistogramSnapshots::UploadHistogramDelta( |
105 const Histogram& histogram, | 89 const Histogram& histogram, |
106 const Histogram::SampleSet& snapshot, | 90 const Histogram::SampleSet& snapshot, |
107 HistogramPickledList* pickled_histograms) { | 91 HistogramPickledList* pickled_histograms) { |
| 92 |
108 DCHECK(0 != snapshot.TotalCount()); | 93 DCHECK(0 != snapshot.TotalCount()); |
109 snapshot.CheckSize(histogram); | 94 snapshot.CheckSize(histogram); |
110 | 95 |
111 std::string histogram_info = | 96 std::string histogram_info = |
112 Histogram::SerializeHistogramInfo(histogram, snapshot); | 97 Histogram::SerializeHistogramInfo(histogram, snapshot); |
113 pickled_histograms->push_back(histogram_info); | 98 pickled_histograms->push_back(histogram_info); |
114 } | 99 } |
OLD | NEW |