summaryrefslogtreecommitdiffstats
path: root/chrome_frame/chrome_frame_histograms.cc
diff options
context:
space:
mode:
authorslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
committerslightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-24 05:11:58 +0000
commitf781782dd67077478e117c61dca4ea5eefce3544 (patch)
tree4801f724123cfdcbb69c4e7fe40a565b331723ae /chrome_frame/chrome_frame_histograms.cc
parent63cf4759efa2373e33436fb5df6849f930081226 (diff)
downloadchromium_src-f781782dd67077478e117c61dca4ea5eefce3544.zip
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.gz
chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.bz2
Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming in a separate CL.
BUG=None TEST=None Review URL: http://codereview.chromium.org/218019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/chrome_frame_histograms.cc')
-rw-r--r--chrome_frame/chrome_frame_histograms.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome_frame/chrome_frame_histograms.cc b/chrome_frame/chrome_frame_histograms.cc
new file mode 100644
index 0000000..e1ea548
--- /dev/null
+++ b/chrome_frame/chrome_frame_histograms.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome_frame/chrome_frame_histograms.h"
+
+#include "base/histogram.h"
+#include "base/lazy_instance.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/pickle.h"
+
+ // Initialize histogram statistics gathering system.
+base::LazyInstance<StatisticsRecorder>
+ g_statistics_recorder_(base::LINKER_INITIALIZED);
+
+ChromeFrameHistogramSnapshots::ChromeFrameHistogramSnapshots() {
+ // Ensure that an instance of the StatisticsRecorder object is created.
+ g_statistics_recorder_.Get();
+}
+
+ChromeFrameHistogramSnapshots::HistogramPickledList
+ ChromeFrameHistogramSnapshots::GatherAllHistograms() {
+
+ StatisticsRecorder::Histograms histograms;
+ StatisticsRecorder::GetHistograms(&histograms);
+
+ HistogramPickledList pickled_histograms;
+
+ for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
+ histograms.end() != it;
+ it++) {
+ GatherHistogram(**it, &pickled_histograms);
+ }
+
+ return pickled_histograms;
+}
+
+void ChromeFrameHistogramSnapshots::GatherHistogram(
+ const Histogram& histogram,
+ HistogramPickledList* pickled_histograms) {
+
+ // Get up-to-date snapshot of sample stats.
+ Histogram::SampleSet snapshot;
+ histogram.SnapshotSample(&snapshot);
+ const std::string& histogram_name = histogram.histogram_name();
+
+ // Check if we already have a log of this histogram and if not create an
+ // empty set.
+ LoggedSampleMap::iterator it = logged_samples_.find(histogram_name);
+ Histogram::SampleSet* already_logged;
+ if (logged_samples_.end() == it) {
+ // Add new entry.
+ already_logged = &logged_samples_[histogram.histogram_name()];
+ already_logged->Resize(histogram); // Complete initialization.
+ } else {
+ already_logged = &(it->second);
+ // Deduct any stats we've already logged from our snapshot.
+ snapshot.Subtract(*already_logged);
+ }
+
+ // Snapshot now contains only a delta to what we've already_logged.
+ if (snapshot.TotalCount() > 0) {
+ GatherHistogramDelta(histogram, snapshot, pickled_histograms);
+ // Add new data into our running total.
+ already_logged->Add(snapshot);
+ }
+}
+
+void ChromeFrameHistogramSnapshots::GatherHistogramDelta(
+ const Histogram& histogram,
+ const Histogram::SampleSet& snapshot,
+ HistogramPickledList* pickled_histograms) {
+
+ DCHECK(0 != snapshot.TotalCount());
+ snapshot.CheckSize(histogram);
+
+ std::string histogram_info =
+ Histogram::SerializeHistogramInfo(histogram, snapshot);
+ pickled_histograms->push_back(histogram_info);
+}