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

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

Issue 311313005: Add --trace-rotate-startup-file option and store unsaved trace data on exit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows build. Created 6 years, 6 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.cc ('k') | content/browser/browser_shutdown_profile_dumper.h » ('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/public/browser/browser_main_runner.h" 5 #include "content/public/browser/browser_main_runner.h"
6 6
7 #include "base/allocator/allocator_shim.h" 7 #include "base/allocator/allocator_shim.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 DCHECK(initialization_started_); 123 DCHECK(initialization_started_);
124 DCHECK(!is_shutdown_); 124 DCHECK(!is_shutdown_);
125 #ifdef LEAK_SANITIZER 125 #ifdef LEAK_SANITIZER
126 // Invoke leak detection now, to avoid dealing with shutdown-only leaks. 126 // Invoke leak detection now, to avoid dealing with shutdown-only leaks.
127 // Normally this will have already happened in 127 // Normally this will have already happened in
128 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is 128 // BroserProcessImpl::ReleaseModule(), so this call has no effect. This is
129 // only for processes which do not instantiate a BrowserProcess. 129 // only for processes which do not instantiate a BrowserProcess.
130 // If leaks are found, the process will exit here. 130 // If leaks are found, the process will exit here.
131 __lsan_do_leak_check(); 131 __lsan_do_leak_check();
132 #endif 132 #endif
133 // If startup tracing has not been finished yet, replace it's dumper.
134 scoped_ptr<BrowserShutdownProfileDumper> startup_profiler;
135 if (main_loop_->is_tracing_startup()) {
136 startup_profiler.reset(
137 new BrowserShutdownProfileDumper(main_loop_->startup_trace_file()));
138 main_loop_->StopStartupTracingTimer();
139 }
140
133 // The shutdown tracing got enabled in AttemptUserExit earlier, but someone 141 // The shutdown tracing got enabled in AttemptUserExit earlier, but someone
134 // needs to write the result to disc. For that a dumper needs to get created 142 // needs to write the result to disc. For that a dumper needs to get created
135 // which will dump the traces to disc when it gets destroyed. 143 // which will dump the traces to disc when it gets destroyed.
136 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 144 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
137 scoped_ptr<BrowserShutdownProfileDumper> profiler; 145 scoped_ptr<BrowserShutdownProfileDumper> shutdown_profiler;
138 if (command_line.HasSwitch(switches::kTraceShutdown)) 146 if (command_line.HasSwitch(switches::kTraceShutdown)) {
139 profiler.reset(new BrowserShutdownProfileDumper()); 147 shutdown_profiler.reset(
148 new BrowserShutdownProfileDumper(GetShutdownProfileFileName()));
149 }
140 150
141 { 151 {
142 // The trace event has to stay between profiler creation and destruction. 152 // The trace event has to stay between profiler creation and destruction.
143 TRACE_EVENT0("shutdown", "BrowserMainRunner"); 153 TRACE_EVENT0("shutdown", "BrowserMainRunner");
144 g_exited_main_message_loop = true; 154 g_exited_main_message_loop = true;
145 155
146 main_loop_->ShutdownThreadsAndCleanUp(); 156 main_loop_->ShutdownThreadsAndCleanUp();
147 157
148 ui::ShutdownInputMethod(); 158 ui::ShutdownInputMethod();
149 #if defined(OS_WIN) 159 #if defined(OS_WIN)
150 ole_initializer_.reset(NULL); 160 ole_initializer_.reset(NULL);
151 #endif 161 #endif
152 162
153 main_loop_.reset(NULL); 163 main_loop_.reset(NULL);
154 164
155 notification_service_.reset(NULL); 165 notification_service_.reset(NULL);
156 166
157 is_shutdown_ = true; 167 is_shutdown_ = true;
158 } 168 }
159 } 169 }
160 170
161 protected: 171 protected:
172 // Returns the file name where we should save the shutdown trace dump to.
173 static base::FilePath GetShutdownProfileFileName() {
174 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
175 base::FilePath trace_file =
176 command_line.GetSwitchValuePath(switches::kTraceShutdownFile);
177
178 if (!trace_file.empty())
179 return trace_file;
180
181 // Default to saving the startup trace into the current dir.
182 return base::FilePath().AppendASCII("chrometrace.log");
183 }
184
162 // True if we have started to initialize the runner. 185 // True if we have started to initialize the runner.
163 bool initialization_started_; 186 bool initialization_started_;
164 187
165 // True if the runner has been shut down. 188 // True if the runner has been shut down.
166 bool is_shutdown_; 189 bool is_shutdown_;
167 190
168 scoped_ptr<NotificationServiceImpl> notification_service_; 191 scoped_ptr<NotificationServiceImpl> notification_service_;
169 scoped_ptr<BrowserMainLoop> main_loop_; 192 scoped_ptr<BrowserMainLoop> main_loop_;
170 #if defined(OS_WIN) 193 #if defined(OS_WIN)
171 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_; 194 scoped_ptr<ui::ScopedOleInitializer> ole_initializer_;
172 #endif 195 #endif
173 196
174 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl); 197 DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl);
175 }; 198 };
176 199
177 // static 200 // static
178 BrowserMainRunner* BrowserMainRunner::Create() { 201 BrowserMainRunner* BrowserMainRunner::Create() {
179 return new BrowserMainRunnerImpl(); 202 return new BrowserMainRunnerImpl();
180 } 203 }
181 204
182 } // namespace content 205 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.cc ('k') | content/browser/browser_shutdown_profile_dumper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698