[email protected] | c521289 | 2010-09-08 06:30:33 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 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 | |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 9 | #include "base/logging.h" |
| 10 | #include "base/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 11 | #include "base/metrics/histogram.h" |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 12 | #include "chrome/common/render_messages.h" |
[email protected] | 10e6ab57 | 2011-04-14 23:42:00 | [diff] [blame] | 13 | #include "content/renderer/render_thread.h" |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 14 | |
| 15 | // TODO(raman): Before renderer shuts down send final snapshot lists. |
| 16 | |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 17 | using base::Histogram; |
| 18 | using base::StatisticsRecorder; |
| 19 | |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 20 | RendererHistogramSnapshots::RendererHistogramSnapshots() |
| 21 | : ALLOW_THIS_IN_INITIALIZER_LIST( |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 22 | renderer_histogram_snapshots_factory_(this)) { |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 23 | } |
| 24 | |
[email protected] | 46f36a49 | 2010-07-28 19:36:41 | [diff] [blame] | 25 | RendererHistogramSnapshots::~RendererHistogramSnapshots() { |
| 26 | } |
| 27 | |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 28 | // Send data quickly! |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 29 | void RendererHistogramSnapshots::SendHistograms(int sequence_number) { |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 30 | RenderThread::current()->message_loop()->PostTask(FROM_HERE, |
| 31 | renderer_histogram_snapshots_factory_.NewRunnableMethod( |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 32 | &RendererHistogramSnapshots::UploadAllHistrograms, sequence_number)); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | 6cf19311f | 2011-04-14 23:06:02 | [diff] [blame] | 35 | bool RendererHistogramSnapshots::OnControlMessageReceived( |
| 36 | const IPC::Message& message) { |
| 37 | bool handled = true; |
| 38 | IPC_BEGIN_MESSAGE_MAP(RendererHistogramSnapshots, message) |
| 39 | IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms, OnGetRendererHistograms) |
| 40 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 41 | IPC_END_MESSAGE_MAP() |
| 42 | return handled; |
| 43 | } |
| 44 | |
| 45 | void RendererHistogramSnapshots::OnGetRendererHistograms(int sequence_number) { |
| 46 | SendHistograms(sequence_number); |
| 47 | } |
| 48 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 49 | void RendererHistogramSnapshots::UploadAllHistrograms(int sequence_number) { |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 50 | DCHECK_EQ(0u, pickled_histograms_.size()); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 51 | |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 52 | // Push snapshots into our pickled_histograms_ vector. |
| 53 | TransmitAllHistograms(Histogram::kIPCSerializationSourceFlag, false); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 54 | |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 55 | // Send the sequence number and list of pickled histograms over synchronous |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 56 | // IPC, so we can clear pickled_histograms_ afterwards. |
[email protected] | c9a3ef8 | 2009-05-28 22:02:46 | [diff] [blame] | 57 | RenderThread::current()->Send( |
| 58 | new ViewHostMsg_RendererHistograms( |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 59 | sequence_number, pickled_histograms_)); |
| 60 | |
| 61 | pickled_histograms_.clear(); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 62 | } |
| 63 | |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 64 | void RendererHistogramSnapshots::TransmitHistogramDelta( |
| 65 | const base::Histogram& histogram, |
| 66 | const base::Histogram::SampleSet& snapshot) { |
| 67 | DCHECK_NE(0, snapshot.TotalCount()); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 68 | snapshot.CheckSize(histogram); |
| 69 | |
| 70 | std::string histogram_info = |
| 71 | Histogram::SerializeHistogramInfo(histogram, snapshot); |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 72 | pickled_histograms_.push_back(histogram_info); |
[email protected] | 55e57d4 | 2009-02-25 06:10:17 | [diff] [blame] | 73 | } |
[email protected] | bb007d4 | 2010-11-10 17:03:55 | [diff] [blame] | 74 | |
| 75 | void RendererHistogramSnapshots::InconsistencyDetected(int problem) { |
| 76 | UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRenderer", |
| 77 | problem, Histogram::NEVER_EXCEEDED_VALUE); |
| 78 | } |
| 79 | |
| 80 | void RendererHistogramSnapshots::UniqueInconsistencyDetected(int problem) { |
| 81 | UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRendererUnique", |
| 82 | problem, Histogram::NEVER_EXCEEDED_VALUE); |
| 83 | } |
| 84 | |
| 85 | void RendererHistogramSnapshots::SnapshotProblemResolved(int amount) { |
| 86 | UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotRenderer", |
| 87 | std::abs(amount)); |
| 88 | } |
| 89 | |