OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/renderer_histogram_snapshots.h" | |
6 | |
7 #include <ctype.h> | |
8 | |
9 #include "base/bind.h" | |
10 #include "base/logging.h" | |
11 #include "base/message_loop.h" | |
12 #include "base/metrics/histogram.h" | |
13 #include "chrome/common/render_messages.h" | |
14 #include "content/public/renderer/render_thread.h" | |
15 | |
16 // TODO(raman): Before renderer shuts down send final snapshot lists. | |
17 | |
18 using base::Histogram; | |
19 using base::StatisticsRecorder; | |
20 using content::RenderThread; | |
21 | |
22 RendererHistogramSnapshots::RendererHistogramSnapshots() | |
23 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
24 } | |
25 | |
26 RendererHistogramSnapshots::~RendererHistogramSnapshots() { | |
27 } | |
28 | |
29 // Send data quickly! | |
30 void RendererHistogramSnapshots::SendHistograms(int sequence_number) { | |
31 RenderThread::Get()->GetMessageLoop()->PostTask( | |
32 FROM_HERE, base::Bind(&RendererHistogramSnapshots::UploadAllHistrograms, | |
33 weak_factory_.GetWeakPtr(), sequence_number)); | |
34 } | |
35 | |
36 bool RendererHistogramSnapshots::OnControlMessageReceived( | |
37 const IPC::Message& message) { | |
38 bool handled = true; | |
39 IPC_BEGIN_MESSAGE_MAP(RendererHistogramSnapshots, message) | |
40 IPC_MESSAGE_HANDLER(ChromeViewMsg_GetRendererHistograms, | |
41 OnGetRendererHistograms) | |
42 IPC_MESSAGE_UNHANDLED(handled = false) | |
43 IPC_END_MESSAGE_MAP() | |
44 return handled; | |
45 } | |
46 | |
47 void RendererHistogramSnapshots::OnGetRendererHistograms(int sequence_number) { | |
48 SendHistograms(sequence_number); | |
49 } | |
50 | |
51 void RendererHistogramSnapshots::UploadAllHistrograms(int sequence_number) { | |
52 DCHECK_EQ(0u, pickled_histograms_.size()); | |
53 | |
54 StatisticsRecorder::CollectHistogramStats("Renderer"); | |
55 | |
56 // Push snapshots into our pickled_histograms_ vector. | |
57 TransmitAllHistograms(Histogram::kIPCSerializationSourceFlag, false); | |
58 | |
59 // Send the sequence number and list of pickled histograms over synchronous | |
60 // IPC, so we can clear pickled_histograms_ afterwards. | |
61 RenderThread::Get()->Send(new ChromeViewHostMsg_RendererHistograms( | |
62 sequence_number, pickled_histograms_)); | |
63 | |
64 pickled_histograms_.clear(); | |
65 } | |
66 | |
67 void RendererHistogramSnapshots::TransmitHistogramDelta( | |
68 const base::Histogram& histogram, | |
69 const base::Histogram::SampleSet& snapshot) { | |
70 DCHECK_NE(0, snapshot.TotalCount()); | |
71 snapshot.CheckSize(histogram); | |
72 | |
73 std::string histogram_info = | |
74 Histogram::SerializeHistogramInfo(histogram, snapshot); | |
75 pickled_histograms_.push_back(histogram_info); | |
76 } | |
77 | |
78 void RendererHistogramSnapshots::InconsistencyDetected(int problem) { | |
79 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRenderer", | |
80 problem, Histogram::NEVER_EXCEEDED_VALUE); | |
81 } | |
82 | |
83 void RendererHistogramSnapshots::UniqueInconsistencyDetected(int problem) { | |
84 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRendererUnique", | |
85 problem, Histogram::NEVER_EXCEEDED_VALUE); | |
86 } | |
87 | |
88 void RendererHistogramSnapshots::SnapshotProblemResolved(int amount) { | |
89 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotRenderer", | |
90 std::abs(amount)); | |
91 } | |
92 | |
OLD | NEW |