summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 06:10:17 +0000
committerjar@chromium.org <jar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-25 06:10:17 +0000
commit55e57d4d2326bd98d6e14c92ba055754ef77b0e6 (patch)
tree29f456dcb43fd5754104fe4e302df13532262c83 /chrome/renderer
parentf78d965fa1ef193595740604508d7d94fde0ef84 (diff)
downloadchromium_src-55e57d4d2326bd98d6e14c92ba055754ef77b0e6.zip
chromium_src-55e57d4d2326bd98d6e14c92ba055754ef77b0e6.tar.gz
chromium_src-55e57d4d2326bd98d6e14c92ba055754ef77b0e6.tar.bz2
Initial support for Renderer Side Histograms
Patch contributed by Raman Tenneti see also patch number 21038 Review URL: http://codereview.chromium.org/27034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10330 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/render_thread.cc14
-rw-r--r--chrome/renderer/render_thread.h10
-rw-r--r--chrome/renderer/renderer.scons2
-rw-r--r--chrome/renderer/renderer.vcproj8
-rw-r--r--chrome/renderer/renderer_histogram_snapshots.cc94
-rw-r--r--chrome/renderer/renderer_histogram_snapshots.h54
-rw-r--r--chrome/renderer/renderer_main.cc8
7 files changed, 189 insertions, 1 deletions
diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc
index 58de4ef..6e8e7b0 100644
--- a/chrome/renderer/render_thread.cc
+++ b/chrome/renderer/render_thread.cc
@@ -59,7 +59,8 @@ RenderThread::RenderThread(const std::wstring& channel_name)
MessageLoop::TYPE_UI : MessageLoop::TYPE_DEFAULT, kStackSize)),
visited_link_slave_(NULL),
user_script_slave_(NULL),
- render_dns_master_(NULL) {
+ render_dns_master_(NULL),
+ renderer_histogram_snapshots_(NULL) {
SetChannelName(channel_name);
}
@@ -83,6 +84,10 @@ void RenderThread::Resolve(const char* name, size_t length) {
return render_dns_master_->Resolve(name, length);
}
+void RenderThread::SendHistograms() {
+ return renderer_histogram_snapshots_->SendHistograms();
+}
+
void RenderThread::Init() {
ChildThread::Init();
notification_service_.reset(new NotificationService);
@@ -97,6 +102,7 @@ void RenderThread::Init() {
visited_link_slave_ = new VisitedLinkSlave();
user_script_slave_ = new UserScriptSlave();
render_dns_master_.reset(new RenderDnsMaster());
+ renderer_histogram_snapshots_.reset(new RendererHistogramSnapshots());
}
void RenderThread::CleanUp() {
@@ -140,6 +146,8 @@ void RenderThread::OnControlMessageReceived(const IPC::Message& msg) {
// is there a new non-windows message I should add here?
IPC_MESSAGE_HANDLER(ViewMsg_New, OnCreateNewView)
IPC_MESSAGE_HANDLER(ViewMsg_SetCacheCapacities, OnSetCacheCapacities)
+ IPC_MESSAGE_HANDLER(ViewMsg_GetRendererHistograms,
+ OnGetRendererHistograms)
IPC_MESSAGE_HANDLER(ViewMsg_GetCacheResourceStats,
OnGetCacheResourceStats)
IPC_MESSAGE_HANDLER(ViewMsg_PluginMessage, OnPluginMessage)
@@ -212,6 +220,10 @@ void RenderThread::OnGetCacheResourceStats() {
#endif
}
+void RenderThread::OnGetRendererHistograms() {
+ SendHistograms();
+}
+
void RenderThread::InformHostOfCacheStats() {
#if defined(OS_WIN) || defined(OS_LINUX)
CacheManager::UsageStats stats;
diff --git a/chrome/renderer/render_thread.h b/chrome/renderer/render_thread.h
index 54043ca..a23776e 100644
--- a/chrome/renderer/render_thread.h
+++ b/chrome/renderer/render_thread.h
@@ -12,10 +12,12 @@
#include "base/task.h"
#include "build/build_config.h"
#include "chrome/common/child_thread.h"
+#include "chrome/renderer/renderer_histogram_snapshots.h"
class FilePath;
class NotificationService;
class RenderDnsMaster;
+class RendererHistogram;
class SkBitmap;
class UserScriptSlave;
class VisitedLinkSlave;
@@ -86,6 +88,9 @@ class RenderThread : public RenderThreadBase,
// Do DNS prefetch resolution of a hostname.
void Resolve(const char* name, size_t length);
+ // Send all the Histogram data to browser.
+ void SendHistograms();
+
// Invokes InformHostOfCacheStats after a short delay. Used to move this
// bookkeeping operation off the critical latency path.
void InformHostOfCacheStatsLater();
@@ -113,6 +118,9 @@ class RenderThread : public RenderThreadBase,
size_t capacity);
void OnGetCacheResourceStats();
+ // Send all histograms to browser.
+ void OnGetRendererHistograms();
+
// Gather usage statistics from the in-memory cache and inform our host.
// These functions should be call periodically so that the host can make
// decisions about how to allocation resources using current information.
@@ -124,6 +132,8 @@ class RenderThread : public RenderThreadBase,
scoped_ptr<RenderDnsMaster> render_dns_master_;
+ scoped_ptr<RendererHistogramSnapshots> renderer_histogram_snapshots_;
+
scoped_ptr<ScopedRunnableMethodFactory<RenderThread> > cache_stats_factory_;
scoped_ptr<NotificationService> notification_service_;
diff --git a/chrome/renderer/renderer.scons b/chrome/renderer/renderer.scons
index c03848b..3bb0d17 100644
--- a/chrome/renderer/renderer.scons
+++ b/chrome/renderer/renderer.scons
@@ -83,6 +83,8 @@ input_files = ChromeFileList([
'render_widget.cc',
'render_widget.h',
'renderer_glue.cc',
+ 'renderer_histogram_snapshots.cc',
+ 'renderer_histogram_snapshots.h',
'renderer_main.cc',
'renderer_resources.h',
'user_script_slave.cc',
diff --git a/chrome/renderer/renderer.vcproj b/chrome/renderer/renderer.vcproj
index 7e50f8f..684ec52 100644
--- a/chrome/renderer/renderer.vcproj
+++ b/chrome/renderer/renderer.vcproj
@@ -298,6 +298,14 @@
>
</File>
<File
+ RelativePath=".\renderer_histogram_snapshots.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\renderer_histogram_snapshots.h"
+ >
+ </File>
+ <File
RelativePath=".\renderer_main.cc"
>
</File>
diff --git a/chrome/renderer/renderer_histogram_snapshots.cc b/chrome/renderer/renderer_histogram_snapshots.cc
new file mode 100644
index 0000000..a4488ca
--- /dev/null
+++ b/chrome/renderer/renderer_histogram_snapshots.cc
@@ -0,0 +1,94 @@
+// Copyright (c) 2006-2008 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/renderer/renderer_histogram_snapshots.h"
+
+#include <ctype.h>
+
+#include "base/histogram.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "base/pickle.h"
+#include "chrome/common/render_messages.h"
+#include "chrome/renderer/render_process.h"
+#include "chrome/renderer/render_thread.h"
+
+// TODO(raman): Before renderer shuts down send final snapshot lists.
+
+RendererHistogramSnapshots::RendererHistogramSnapshots()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(
+ renderer_histogram_snapshots_factory_(this)) {
+}
+
+// Send data quickly!
+void RendererHistogramSnapshots::SendHistograms() {
+ RenderThread::current()->message_loop()->PostTask(FROM_HERE,
+ renderer_histogram_snapshots_factory_.NewRunnableMethod(
+ &RendererHistogramSnapshots::UploadAllHistrograms));
+}
+
+void RendererHistogramSnapshots::UploadAllHistrograms() {
+ StatisticsRecorder::Histograms histograms;
+ StatisticsRecorder::GetHistograms(&histograms);
+
+ HistogramPickledList pickled_histograms;
+
+ for (StatisticsRecorder::Histograms::iterator it = histograms.begin();
+ histograms.end() != it;
+ it++) {
+ UploadHistrogram(**it, &pickled_histograms);
+ }
+ // Send the handle over synchronous IPC.
+ if (pickled_histograms.size() > 0) {
+ RenderThread::current()->Send(
+ new ViewHostMsg_RendererHistograms(pickled_histograms));
+ }
+}
+
+// Extract snapshot data and then send it off the the Browser process
+// to save it.
+void RendererHistogramSnapshots::UploadHistrogram(
+ 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();
+
+ // Find the already sent stats, or 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) {
+ UploadHistogramDelta(histogram, snapshot, pickled_histograms);
+ // Add new data into our running total.
+ already_logged->Add(snapshot);
+ }
+}
+
+void RendererHistogramSnapshots::UploadHistogramDelta(
+ 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);
+}
+
diff --git a/chrome/renderer/renderer_histogram_snapshots.h b/chrome/renderer/renderer_histogram_snapshots.h
new file mode 100644
index 0000000..b3d7fb1
--- /dev/null
+++ b/chrome/renderer/renderer_histogram_snapshots.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef CHROME_RENDERER_HISTOGRAM_SNAPSHOTS_H_
+#define CHROME_RENDERER_HISTOGRAM_SNAPSHOTS_H_
+
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/histogram.h"
+#include "base/process.h"
+#include "base/scoped_ptr.h"
+#include "base/task.h"
+
+class RendererHistogramSnapshots {
+ public:
+ RendererHistogramSnapshots();
+
+ ~RendererHistogramSnapshots() {}
+
+ // Send the histogram data.
+ void SendHistograms();
+
+ // Maintain a map of histogram names to the sample stats we've sent.
+ typedef std::map<std::string, Histogram::SampleSet> LoggedSampleMap;
+ typedef std::vector<std::string> HistogramPickledList;
+
+ private:
+ // Extract snapshot data and then send it off the the Browser process.
+ // Send only a delta to what we have already sent.
+ void UploadAllHistrograms();
+ void UploadHistrogram(const Histogram& histogram,
+ HistogramPickledList* histograms);
+ void UploadHistogramDelta(const Histogram& histogram,
+ const Histogram::SampleSet& snapshot,
+ HistogramPickledList* histograms);
+
+ ScopedRunnableMethodFactory<RendererHistogramSnapshots>
+ renderer_histogram_snapshots_factory_;
+
+ // For histograms, record what we've already logged (as a sample for each
+ // histogram) so that we can send only the delta with the next log.
+ LoggedSampleMap logged_samples_;
+
+ DISALLOW_COPY_AND_ASSIGN(RendererHistogramSnapshots);
+};
+
+#endif // CHROME_RENDERER_HISTOGRAM_SNAPSHOTS_H_
+
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index b79e9e5..8e70dee 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/command_line.h"
+#include "base/histogram.h"
#include "base/message_loop.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
@@ -89,6 +90,13 @@ int RendererMain(const MainFunctionParams& parameters) {
HandleRendererErrorTestParameters(parsed_command_line);
+ // Initialize histogram statistics gathering system.
+ // Don't create StatisticsRecorde in the single process mode.
+ scoped_ptr<StatisticsRecorder> statistics;
+ if (!StatisticsRecorder::WasStarted()) {
+ statistics.reset(new StatisticsRecorder());
+ }
+
{
RenderProcess render_process;
bool run_loop = true;