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

Side by Side Diff: content/browser/browser_main_loop.cc

Issue 1312833007: Revert of Reland [Startup Tracing] Add --trace-config-file flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/browser_main_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/browser_main_loop.h" 5 #include "content/browser/browser_main_loop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/memory_pressure_monitor.h" 11 #include "base/memory/memory_pressure_monitor.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/pending_task.h" 14 #include "base/pending_task.h"
15 #include "base/power_monitor/power_monitor.h" 15 #include "base/power_monitor/power_monitor.h"
16 #include "base/power_monitor/power_monitor_device_source.h" 16 #include "base/power_monitor/power_monitor_device_source.h"
17 #include "base/process/process_metrics.h" 17 #include "base/process/process_metrics.h"
18 #include "base/profiler/scoped_profile.h" 18 #include "base/profiler/scoped_profile.h"
19 #include "base/run_loop.h" 19 #include "base/run_loop.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_split.h" 22 #include "base/strings/string_split.h"
23 #include "base/system_monitor/system_monitor.h" 23 #include "base/system_monitor/system_monitor.h"
24 #include "base/thread_task_runner_handle.h" 24 #include "base/thread_task_runner_handle.h"
25 #include "base/threading/thread_restrictions.h" 25 #include "base/threading/thread_restrictions.h"
26 #include "base/timer/hi_res_timer_manager.h" 26 #include "base/timer/hi_res_timer_manager.h"
27 #include "base/trace_event/memory_dump_manager.h" 27 #include "base/trace_event/memory_dump_manager.h"
28 #include "base/trace_event/trace_event.h" 28 #include "base/trace_event/trace_event.h"
29 #include "components/tracing/trace_config_file.h"
30 #include "components/tracing/tracing_switches.h" 29 #include "components/tracing/tracing_switches.h"
31 #include "content/browser/browser_thread_impl.h" 30 #include "content/browser/browser_thread_impl.h"
32 #include "content/browser/device_sensors/device_inertial_sensor_service.h" 31 #include "content/browser/device_sensors/device_inertial_sensor_service.h"
33 #include "content/browser/dom_storage/dom_storage_area.h" 32 #include "content/browser/dom_storage/dom_storage_area.h"
34 #include "content/browser/download/save_file_manager.h" 33 #include "content/browser/download/save_file_manager.h"
35 #include "content/browser/gamepad/gamepad_service.h" 34 #include "content/browser/gamepad/gamepad_service.h"
36 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" 35 #include "content/browser/gpu/browser_gpu_channel_host_factory.h"
37 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" 36 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h"
38 #include "content/browser/gpu/compositor_util.h" 37 #include "content/browser/gpu/compositor_util.h"
39 #include "content/browser/gpu/gpu_data_manager_impl.h" 38 #include "content/browser/gpu/gpu_data_manager_impl.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 DCHECK_CURRENTLY_ON(BrowserThread::UI); 383 DCHECK_CURRENTLY_ON(BrowserThread::UI);
385 return g_current_browser_main_loop; 384 return g_current_browser_main_loop;
386 } 385 }
387 386
388 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters) 387 BrowserMainLoop::BrowserMainLoop(const MainFunctionParams& parameters)
389 : parameters_(parameters), 388 : parameters_(parameters),
390 parsed_command_line_(parameters.command_line), 389 parsed_command_line_(parameters.command_line),
391 result_code_(RESULT_CODE_NORMAL_EXIT), 390 result_code_(RESULT_CODE_NORMAL_EXIT),
392 created_threads_(false), 391 created_threads_(false),
393 // ContentMainRunner should have enabled tracing of the browser process 392 // ContentMainRunner should have enabled tracing of the browser process
394 // when kTraceStartup or kTraceConfigFile is in the command line. 393 // when kTraceStartup is in the command line.
395 is_tracing_startup_for_duration_( 394 is_tracing_startup_(
396 parameters.command_line.HasSwitch(switches::kTraceStartup) || 395 parameters.command_line.HasSwitch(switches::kTraceStartup)) {
397 (tracing::TraceConfigFile::GetInstance()->IsEnabled() &&
398 tracing::TraceConfigFile::GetInstance()->GetStartupDuration() > 0)) {
399 DCHECK(!g_current_browser_main_loop); 396 DCHECK(!g_current_browser_main_loop);
400 g_current_browser_main_loop = this; 397 g_current_browser_main_loop = this;
401 } 398 }
402 399
403 BrowserMainLoop::~BrowserMainLoop() { 400 BrowserMainLoop::~BrowserMainLoop() {
404 DCHECK_EQ(this, g_current_browser_main_loop); 401 DCHECK_EQ(this, g_current_browser_main_loop);
405 #if !defined(OS_IOS) 402 #if !defined(OS_IOS)
406 ui::Clipboard::DestroyClipboardForCurrentThread(); 403 ui::Clipboard::DestroyClipboardForCurrentThread();
407 #endif // !defined(OS_IOS) 404 #endif // !defined(OS_IOS)
408 g_current_browser_main_loop = NULL; 405 g_current_browser_main_loop = NULL;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 system_message_window_.reset(new SystemMessageWindowWin); 571 system_message_window_.reset(new SystemMessageWindowWin);
575 #endif 572 #endif
576 573
577 if (parts_) 574 if (parts_)
578 parts_->PostMainMessageLoopStart(); 575 parts_->PostMainMessageLoopStart();
579 576
580 #if !defined(OS_IOS) 577 #if !defined(OS_IOS)
581 // Start tracing to a file if needed. Only do this after starting the main 578 // Start tracing to a file if needed. Only do this after starting the main
582 // message loop to avoid calling MessagePumpForUI::ScheduleWork() before 579 // message loop to avoid calling MessagePumpForUI::ScheduleWork() before
583 // MessagePumpForUI::Start() as it will crash the browser. 580 // MessagePumpForUI::Start() as it will crash the browser.
584 if (is_tracing_startup_for_duration_) { 581 if (is_tracing_startup_) {
585 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracingForDuration"); 582 TRACE_EVENT0("startup", "BrowserMainLoop::InitStartupTracing");
586 InitStartupTracingForDuration(parsed_command_line_); 583 InitStartupTracing(parsed_command_line_);
587 } 584 }
588 #endif // !defined(OS_IOS) 585 #endif // !defined(OS_IOS)
589 586
590 #if defined(OS_ANDROID) 587 #if defined(OS_ANDROID)
591 { 588 {
592 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager"); 589 TRACE_EVENT0("startup", "BrowserMainLoop::Subsystem:SurfaceTextureManager");
593 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) { 590 if (parsed_command_line_.HasSwitch(switches::kSingleProcess)) {
594 SurfaceTextureManager::SetInstance( 591 SurfaceTextureManager::SetInstance(
595 InProcessSurfaceTextureManager::GetInstance()); 592 InProcessSurfaceTextureManager::GetInstance());
596 } else { 593 } else {
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 *parameters_.ui_task); 1309 *parameters_.ui_task);
1313 } 1310 }
1314 1311
1315 base::RunLoop run_loop; 1312 base::RunLoop run_loop;
1316 run_loop.Run(); 1313 run_loop.Run();
1317 #endif 1314 #endif
1318 } 1315 }
1319 1316
1320 base::FilePath BrowserMainLoop::GetStartupTraceFileName( 1317 base::FilePath BrowserMainLoop::GetStartupTraceFileName(
1321 const base::CommandLine& command_line) const { 1318 const base::CommandLine& command_line) const {
1322 base::FilePath trace_file; 1319 base::FilePath trace_file = command_line.GetSwitchValuePath(
1323 if (command_line.HasSwitch(switches::kTraceStartup)) { 1320 switches::kTraceStartupFile);
1324 trace_file = command_line.GetSwitchValuePath( 1321 // trace_file = "none" means that startup events will show up for the next
1325 switches::kTraceStartupFile); 1322 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/
1326 // trace_file = "none" means that startup events will show up for the next 1323 // EndTracing, for example).
1327 // begin/end tracing (via about:tracing or AutomationProxy::BeginTracing/ 1324 if (trace_file == base::FilePath().AppendASCII("none"))
1328 // EndTracing, for example). 1325 return trace_file;
1329 if (trace_file == base::FilePath().AppendASCII("none"))
1330 return trace_file;
1331 1326
1332 if (trace_file.empty()) { 1327 if (trace_file.empty()) {
1333 #if defined(OS_ANDROID)
1334 TracingControllerAndroid::GenerateTracingFilePath(&trace_file);
1335 #else
1336 // Default to saving the startup trace into the current dir.
1337 trace_file = base::FilePath().AppendASCII("chrometrace.log");
1338 #endif
1339 }
1340 } else {
1341 #if defined(OS_ANDROID) 1328 #if defined(OS_ANDROID)
1342 TracingControllerAndroid::GenerateTracingFilePath(&trace_file); 1329 TracingControllerAndroid::GenerateTracingFilePath(&trace_file);
1343 #else 1330 #else
1344 trace_file = tracing::TraceConfigFile::GetInstance()->GetResultFile(); 1331 // Default to saving the startup trace into the current dir.
1332 trace_file = base::FilePath().AppendASCII("chrometrace.log");
1345 #endif 1333 #endif
1346 } 1334 }
1347 1335
1348 return trace_file; 1336 return trace_file;
1349 } 1337 }
1350 1338
1351 void BrowserMainLoop::InitStartupTracingForDuration( 1339 void BrowserMainLoop::InitStartupTracing(
1352 const base::CommandLine& command_line) { 1340 const base::CommandLine& command_line) {
1353 DCHECK(is_tracing_startup_for_duration_); 1341 DCHECK(is_tracing_startup_);
1354 1342
1355 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_); 1343 startup_trace_file_ = GetStartupTraceFileName(parsed_command_line_);
1356 1344
1345 std::string delay_str = command_line.GetSwitchValueASCII(
1346 switches::kTraceStartupDuration);
1357 int delay_secs = 5; 1347 int delay_secs = 5;
1358 if (command_line.HasSwitch(switches::kTraceStartup)) { 1348 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) {
1359 std::string delay_str = command_line.GetSwitchValueASCII( 1349 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration
1360 switches::kTraceStartupDuration); 1350 << "=" << delay_str << " defaulting to 5 (secs)";
1361 if (!delay_str.empty() && !base::StringToInt(delay_str, &delay_secs)) { 1351 delay_secs = 5;
1362 DLOG(WARNING) << "Could not parse --" << switches::kTraceStartupDuration
1363 << "=" << delay_str << " defaulting to 5 (secs)";
1364 delay_secs = 5;
1365 }
1366 } else {
1367 delay_secs = tracing::TraceConfigFile::GetInstance()->GetStartupDuration();
1368 } 1352 }
1369 1353
1370 startup_trace_timer_.Start(FROM_HERE, 1354 startup_trace_timer_.Start(FROM_HERE,
1371 base::TimeDelta::FromSeconds(delay_secs), 1355 base::TimeDelta::FromSeconds(delay_secs),
1372 this, 1356 this,
1373 &BrowserMainLoop::EndStartupTracing); 1357 &BrowserMainLoop::EndStartupTracing);
1374 } 1358 }
1375 1359
1376 void BrowserMainLoop::EndStartupTracing() { 1360 void BrowserMainLoop::EndStartupTracing() {
1377 DCHECK(is_tracing_startup_for_duration_); 1361 DCHECK(is_tracing_startup_);
1378 1362
1379 is_tracing_startup_for_duration_ = false; 1363 is_tracing_startup_ = false;
1380 TracingController::GetInstance()->DisableRecording( 1364 TracingController::GetInstance()->DisableRecording(
1381 TracingController::CreateFileSink( 1365 TracingController::CreateFileSink(
1382 startup_trace_file_, 1366 startup_trace_file_,
1383 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); 1367 base::Bind(OnStoppedStartupTracing, startup_trace_file_)));
1384 } 1368 }
1385 1369
1386 } // namespace content 1370 } // namespace content
OLDNEW
« 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