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

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

Issue 27034: Initial support for Renderer Side Histograms... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months 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/renderer/renderer_histogram_snapshots.h ('k') | chrome/renderer/renderer_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2008 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/histogram.h"
10 #include "base/logging.h"
11 #include "base/message_loop.h"
12 #include "base/pickle.h"
13 #include "chrome/common/render_messages.h"
14 #include "chrome/renderer/render_process.h"
15 #include "chrome/renderer/render_thread.h"
16
17 // TODO(raman): Before renderer shuts down send final snapshot lists.
18
19 RendererHistogramSnapshots::RendererHistogramSnapshots()
20 : ALLOW_THIS_IN_INITIALIZER_LIST(
21 renderer_histogram_snapshots_factory_(this)) {
22 }
23
24 // Send data quickly!
25 void RendererHistogramSnapshots::SendHistograms() {
26 RenderThread::current()->message_loop()->PostTask(FROM_HERE,
27 renderer_histogram_snapshots_factory_.NewRunnableMethod(
28 &RendererHistogramSnapshots::UploadAllHistrograms));
29 }
30
31 void RendererHistogramSnapshots::UploadAllHistrograms() {
32 StatisticsRecorder::Histograms histograms;
33 StatisticsRecorder::GetHistograms(&histograms);
34
35 HistogramPickledList pickled_histograms;
36
37 for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
38 histograms.end() != it;
39 it++) {
40 UploadHistrogram(**it, &pickled_histograms);
41 }
42 // Send the handle over synchronous IPC.
43 if (pickled_histograms.size() > 0) {
44 RenderThread::current()->Send(
45 new ViewHostMsg_RendererHistograms(pickled_histograms));
46 }
47 }
48
49 // Extract snapshot data and then send it off the the Browser process
50 // to save it.
51 void RendererHistogramSnapshots::UploadHistrogram(
52 const Histogram& histogram,
53 HistogramPickledList* pickled_histograms) {
54
55 // Get up-to-date snapshot of sample stats.
56 Histogram::SampleSet snapshot;
57 histogram.SnapshotSample(&snapshot);
58 const std::string& histogram_name = histogram.histogram_name();
59
60 // Find the already sent stats, or create an empty set.
61 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
62 Histogram::SampleSet* already_logged;
63 if (logged_samples_.end() == it) {
64 // Add new entry.
65 already_logged = &logged_samples_[histogram.histogram_name()];
66 already_logged->Resize(histogram); // Complete initialization.
67 } else {
68 already_logged = &(it->second);
69 // Deduct any stats we've already logged from our snapshot.
70 snapshot.Subtract(*already_logged);
71 }
72
73 // Snapshot now contains only a delta to what we've already_logged.
74
75 if (snapshot.TotalCount() > 0) {
76 UploadHistogramDelta(histogram, snapshot, pickled_histograms);
77 // Add new data into our running total.
78 already_logged->Add(snapshot);
79 }
80 }
81
82 void RendererHistogramSnapshots::UploadHistogramDelta(
83 const Histogram& histogram,
84 const Histogram::SampleSet& snapshot,
85 HistogramPickledList* pickled_histograms) {
86
87 DCHECK(0 != snapshot.TotalCount());
88 snapshot.CheckSize(histogram);
89
90 std::string histogram_info =
91 Histogram::SerializeHistogramInfo(histogram, snapshot);
92 pickled_histograms->push_back(histogram_info);
93 }
94
OLDNEW
« no previous file with comments | « chrome/renderer/renderer_histogram_snapshots.h ('k') | chrome/renderer/renderer_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698