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

Side by Side Diff: chrome_frame/chrome_frame_histograms.cc

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 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_frame/chrome_frame_histograms.h ('k') | chrome_frame/chrome_frame_npapi.h » ('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) 2009 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_frame/chrome_frame_histograms.h"
6
7 #include "base/histogram.h"
8 #include "base/lazy_instance.h"
9 #include "base/logging.h"
10 #include "base/message_loop.h"
11 #include "base/pickle.h"
12
13 // Initialize histogram statistics gathering system.
14 base::LazyInstance<StatisticsRecorder>
15 g_statistics_recorder_(base::LINKER_INITIALIZED);
16
17 ChromeFrameHistogramSnapshots::ChromeFrameHistogramSnapshots() {
18 // Ensure that an instance of the StatisticsRecorder object is created.
19 g_statistics_recorder_.Get();
20 }
21
22 ChromeFrameHistogramSnapshots::HistogramPickledList
23 ChromeFrameHistogramSnapshots::GatherAllHistograms() {
24
25 StatisticsRecorder::Histograms histograms;
26 StatisticsRecorder::GetHistograms(&histograms);
27
28 HistogramPickledList pickled_histograms;
29
30 for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
31 histograms.end() != it;
32 it++) {
33 GatherHistogram(**it, &pickled_histograms);
34 }
35
36 return pickled_histograms;
37 }
38
39 void ChromeFrameHistogramSnapshots::GatherHistogram(
40 const Histogram& histogram,
41 HistogramPickledList* pickled_histograms) {
42
43 // Get up-to-date snapshot of sample stats.
44 Histogram::SampleSet snapshot;
45 histogram.SnapshotSample(&snapshot);
46 const std::string& histogram_name = histogram.histogram_name();
47
48 // Check if we already have a log of this histogram and if not create an
49 // empty set.
50 LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
51 Histogram::SampleSet* already_logged;
52 if (logged_samples_.end() == it) {
53 // Add new entry.
54 already_logged = &logged_samples_[histogram.histogram_name()];
55 already_logged->Resize(histogram); // Complete initialization.
56 } else {
57 already_logged = &(it->second);
58 // Deduct any stats we've already logged from our snapshot.
59 snapshot.Subtract(*already_logged);
60 }
61
62 // Snapshot now contains only a delta to what we've already_logged.
63 if (snapshot.TotalCount() > 0) {
64 GatherHistogramDelta(histogram, snapshot, pickled_histograms);
65 // Add new data into our running total.
66 already_logged->Add(snapshot);
67 }
68 }
69
70 void ChromeFrameHistogramSnapshots::GatherHistogramDelta(
71 const Histogram& histogram,
72 const Histogram::SampleSet& snapshot,
73 HistogramPickledList* pickled_histograms) {
74
75 DCHECK(0 != snapshot.TotalCount());
76 snapshot.CheckSize(histogram);
77
78 std::string histogram_info =
79 Histogram::SerializeHistogramInfo(histogram, snapshot);
80 pickled_histograms->push_back(histogram_info);
81 }
OLDNEW
« no previous file with comments | « chrome_frame/chrome_frame_histograms.h ('k') | chrome_frame/chrome_frame_npapi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698