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

Unified Diff: content/browser/browser_main_loop.cc

Issue 1317333002: Reland [Startup Tracing] Add --trace-config-file flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test Created 5 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/browser_main_loop.cc
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index b5159df02a3e91b640f71dc37d0e5e82f77e634a..df19ee86f070e4da101a1a94f7167b9a1cd9390f 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -26,6 +26,7 @@
#include "base/timer/hi_res_timer_manager.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"
+#include "components/tracing/trace_config_file.h"
#include "components/tracing/tracing_switches.h"
#include "content/browser/browser_thread_impl.h"
#include "content/browser/device_sensors/device_inertial_sensor_service.h"
@@ -390,9 +391,11 @@ BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters)
result_code_(RESULT_CODE_NORMAL_EXIT),
created_threads_(false),
// ContentMainRunner should have enabled tracing of the browser process
- // when kTraceStartup is in the command line.
- is_tracing_startup_(
- parameters.command_line.HasSwitch(switches::kTraceStartup)) {
+ // when kTraceStartup or kTraceConfigFile is in the command line.
+ is_tracing_startup_for_duration_(
+ parameters.command_line.HasSwitch(switches::kTraceStartup) ||
+ (tracing::TraceConfigFile::GetInstance()->IsEnabled() &&
+ tracing::TraceConfigFile::GetInstance()->GetStartupDuration() > 0)) {
DCHECK(!g_current_browser_main_loop);
g_current_browser_main_loop = this;
}
@@ -578,9 +581,9 @@ void BrowserMainLoop::PostMainMessageLoopStart() {
// Start tracing to a file if needed. Only do this after starting the main
// message loop to avoid calling MessagePumpForUI::ScheduleWork() before
// MessagePumpForUI::Start() as it will crash the browser.
- if (is_tracing_startup_) {
- TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing");
- InitStartupTracing(parsed_command_line_);
+ if (is_tracing_startup_for_duration_) {
+ TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracingForDuration");
+ InitStartupTracingForDuration(parsed_command_line_);
}
#endif // !defined(OS_IOS)
@@ -1316,39 +1319,52 @@ void BrowserMainLoop::MainMessageLoopRun() {
base::FilePath BrowserMainLoop::GetStartupTraceFileName(
const base::CommandLine& command_line) const {
- base::FilePath trace_file = command_line.GetSwitchValuePath(
- switches::kTraceStartupFile);
- // trace_file = "none" means that startup events will show up for the next
- // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/
- // EndTracing, for example).
- if (trace_file == base::FilePath().AppendASCII("none"))
- return trace_file;
-
- if (trace_file.empty()) {
+ base::FilePath trace_file;
+ if (command_line.HasSwitch(switches::kTraceStartup)) {
+ trace_file = command_line.GetSwitchValuePath(
+ switches::kTraceStartupFile);
+ // trace_file = "none" means that startup events will show up for the next
+ // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/
+ // EndTracing, for example).
+ if (trace_file == base::FilePath().AppendASCII("none"))
+ return trace_file;
+
+ if (trace_file.empty()) {
+#if defined(OS_ANDROID)
+ TracingControllerAndroid::GenerateTracingFilePath(&trace_file);
+#else
+ // Default to saving the startup trace into the current dir.
+ trace_file = base::FilePath().AppendASCII("chrometrace.log");
+#endif
+ }
+ } else {
#if defined(OS_ANDROID)
TracingControllerAndroid::GenerateTracingFilePath(&trace_file);
#else
- // Default to saving the startup trace into the current dir.
- trace_file = base::FilePath().AppendASCII("chrometrace.log");
+ trace_file = tracing::TraceConfigFile::GetInstance()->GetResultFile();
#endif
}
return trace_file;
}
-void BrowserMainLoop::InitStartupTracing(
+void BrowserMainLoop::InitStartupTracingForDuration(
const base::CommandLine& command_line) {
- DCHECK(is_tracing_startup_);
+ DCHECK(is_tracing_startup_for_duration_);
startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_);
- std::string delay_str = command_line.GetSwitchValueASCII(
- switches::kTraceStartupDuration);
int delay_secs = 5;
- if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) {
- DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration
- << "=" << delay_str << " defaulting to 5 (secs)";
- delay_secs = 5;
+ if (command_line.HasSwitch(switches::kTraceStartup)) {
+ std::string delay_str = command_line.GetSwitchValueASCII(
+ switches::kTraceStartupDuration);
+ if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) {
+ DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration
+ << "=" << delay_str << " defaulting to 5 (secs)";
+ delay_secs = 5;
+ }
+ } else {
+ delay_secs = tracing::TraceConfigFile::GetInstance()->GetStartupDuration();
}
startup_trace_timer_.Start(FROM_HERE,
@@ -1358,9 +1374,9 @@ void BrowserMainLoop::InitStartupTracing(
}
void BrowserMainLoop::EndStartupTracing() {
- DCHECK(is_tracing_startup_);
+ DCHECK(is_tracing_startup_for_duration_);
- is_tracing_startup_ = false;
+ is_tracing_startup_for_duration_ = false;
TracingController::GetInstance()->DisableRecording(
TracingController::CreateFileSink(
startup_trace_file_,
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698