blob: feb9d64fd6506d01c71cf8fa91c15117c3c81422 [file] [log] [blame]
[email protected]c5212892010-09-08 06:30:331// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]55e57d42009-02-25 06:10:172// 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]55e57d42009-02-25 06:10:179#include "base/logging.h"
10#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3811#include "base/metrics/histogram.h"
[email protected]55e57d42009-02-25 06:10:1712#include "chrome/common/render_messages.h"
[email protected]10e6ab572011-04-14 23:42:0013#include "content/renderer/render_thread.h"
[email protected]55e57d42009-02-25 06:10:1714
15// TODO(raman): Before renderer shuts down send final snapshot lists.
16
[email protected]835d7c82010-10-14 04:38:3817using base::Histogram;
18using base::StatisticsRecorder;
19
[email protected]55e57d42009-02-25 06:10:1720RendererHistogramSnapshots::RendererHistogramSnapshots()
21 : ALLOW_THIS_IN_INITIALIZER_LIST(
[email protected]bb007d42010-11-10 17:03:5522 renderer_histogram_snapshots_factory_(this)) {
[email protected]55e57d42009-02-25 06:10:1723}
24
[email protected]46f36a492010-07-28 19:36:4125RendererHistogramSnapshots::~RendererHistogramSnapshots() {
26}
27
[email protected]55e57d42009-02-25 06:10:1728// Send data quickly!
[email protected]c9a3ef82009-05-28 22:02:4629void RendererHistogramSnapshots::SendHistograms(int sequence_number) {
[email protected]55e57d42009-02-25 06:10:1730 RenderThread::current()->message_loop()->PostTask(FROM_HERE,
31 renderer_histogram_snapshots_factory_.NewRunnableMethod(
[email protected]c9a3ef82009-05-28 22:02:4632 &RendererHistogramSnapshots::UploadAllHistrograms, sequence_number));
[email protected]55e57d42009-02-25 06:10:1733}
34
[email protected]6cf19311f2011-04-14 23:06:0235bool 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
45void RendererHistogramSnapshots::OnGetRendererHistograms(int sequence_number) {
46 SendHistograms(sequence_number);
47}
48
[email protected]c9a3ef82009-05-28 22:02:4649void RendererHistogramSnapshots::UploadAllHistrograms(int sequence_number) {
[email protected]bb007d42010-11-10 17:03:5550 DCHECK_EQ(0u, pickled_histograms_.size());
[email protected]55e57d42009-02-25 06:10:1751
[email protected]bb007d42010-11-10 17:03:5552 // Push snapshots into our pickled_histograms_ vector.
53 TransmitAllHistograms(Histogram::kIPCSerializationSourceFlag, false);
[email protected]55e57d42009-02-25 06:10:1754
[email protected]c9a3ef82009-05-28 22:02:4655 // Send the sequence number and list of pickled histograms over synchronous
[email protected]bb007d42010-11-10 17:03:5556 // IPC, so we can clear pickled_histograms_ afterwards.
[email protected]c9a3ef82009-05-28 22:02:4657 RenderThread::current()->Send(
58 new ViewHostMsg_RendererHistograms(
[email protected]bb007d42010-11-10 17:03:5559 sequence_number, pickled_histograms_));
60
61 pickled_histograms_.clear();
[email protected]55e57d42009-02-25 06:10:1762}
63
[email protected]bb007d42010-11-10 17:03:5564void RendererHistogramSnapshots::TransmitHistogramDelta(
65 const base::Histogram& histogram,
66 const base::Histogram::SampleSet& snapshot) {
67 DCHECK_NE(0, snapshot.TotalCount());
[email protected]55e57d42009-02-25 06:10:1768 snapshot.CheckSize(histogram);
69
70 std::string histogram_info =
71 Histogram::SerializeHistogramInfo(histogram, snapshot);
[email protected]bb007d42010-11-10 17:03:5572 pickled_histograms_.push_back(histogram_info);
[email protected]55e57d42009-02-25 06:10:1773}
[email protected]bb007d42010-11-10 17:03:5574
75void RendererHistogramSnapshots::InconsistencyDetected(int problem) {
76 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRenderer",
77 problem, Histogram::NEVER_EXCEEDED_VALUE);
78}
79
80void RendererHistogramSnapshots::UniqueInconsistencyDetected(int problem) {
81 UMA_HISTOGRAM_ENUMERATION("Histogram.InconsistenciesRendererUnique",
82 problem, Histogram::NEVER_EXCEEDED_VALUE);
83}
84
85void RendererHistogramSnapshots::SnapshotProblemResolved(int amount) {
86 UMA_HISTOGRAM_COUNTS("Histogram.InconsistentSnapshotRenderer",
87 std::abs(amount));
88}
89