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

Unified Diff: chrome/browser/ui/startup/startup_browser_creator.cc

Issue 61983003: Add a switch to emit browser histograms. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comments Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/startup/startup_browser_creator.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator.cc b/chrome/browser/ui/startup/startup_browser_creator.cc
index 202f9f8f2c473aeddd0aa22a1a0214921d1e298b..b252220eab91fc6b53887d7f9a61bc8da97621c6 100644
--- a/chrome/browser/ui/startup/startup_browser_creator.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator.cc
@@ -14,11 +14,13 @@
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/environment.h"
+#include "base/file_util.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/statistics_recorder.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
@@ -227,6 +229,17 @@ class ProfileLaunchObserver : public content::NotificationObserver {
base::LazyInstance<ProfileLaunchObserver> profile_launch_observer =
LAZY_INSTANCE_INITIALIZER;
+// Dumps the current set of the browser process's histograms to |output_file|.
+// The file is overwritten if it exists. This function should only be called in
+// the blocking pool.
+void DumpBrowserHistograms(const base::FilePath& output_file) {
+ base::ThreadRestrictions::AssertIOAllowed();
+
+ std::string output_string(base::StatisticsRecorder::ToJSON(std::string()));
+ file_util::WriteFile(output_file, output_string.data(),
+ static_cast<int>(output_string.size()));
+}
+
} // namespace
StartupBrowserCreator::StartupBrowserCreator()
@@ -602,6 +615,20 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
ui::TouchFactory::SetTouchDeviceListFromCommandLine();
#endif
+ if (!process_startup &&
+ command_line.HasSwitch(switches::kDumpBrowserHistograms)) {
+ // Only handle --dump-browser-histograms from a rendezvous. In this case, do
+ // not open a new browser window even if no output file was given.
+ base::FilePath output_file(
+ command_line.GetSwitchValuePath(switches::kDumpBrowserHistograms));
+ if (!output_file.empty()) {
+ BrowserThread::PostBlockingPoolTask(
+ FROM_HERE,
+ base::Bind(&DumpBrowserHistograms, output_file));
+ }
+ silent_launch = true;
+ }
+
// If we don't want to launch a new browser window or tab (in the case
// of an automation request), we are done here.
if (silent_launch)
« no previous file with comments | « base/metrics/statistics_recorder_unittest.cc ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698