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

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

Issue 1891913002: Support saving browser metrics to disk and reading them during next run. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments by Ilya Created 4 years, 8 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
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/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/persistent_histogram_allocator.h"
14 #include "base/metrics/statistics_recorder.h" 15 #include "base/metrics/statistics_recorder.h"
15 #include "base/profiler/scoped_profile.h" 16 #include "base/profiler/scoped_profile.h"
16 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 19 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
19 #include "base/trace_event/trace_event.h" 20 #include "base/trace_event/trace_event.h"
20 #include "base/tracked_objects.h" 21 #include "base/tracked_objects.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "components/tracing/trace_config_file.h" 23 #include "components/tracing/trace_config_file.h"
23 #include "components/tracing/tracing_switches.h" 24 #include "components/tracing/tracing_switches.h"
(...skipping 29 matching lines...) Expand all
53 public: 54 public:
54 BrowserMainRunnerImpl() 55 BrowserMainRunnerImpl()
55 : initialization_started_(false), is_shutdown_(false) {} 56 : initialization_started_(false), is_shutdown_(false) {}
56 57
57 ~BrowserMainRunnerImpl() override { 58 ~BrowserMainRunnerImpl() override {
58 if (initialization_started_ && !is_shutdown_) 59 if (initialization_started_ && !is_shutdown_)
59 Shutdown(); 60 Shutdown();
60 } 61 }
61 62
62 int Initialize(const MainFunctionParams& parameters) override { 63 int Initialize(const MainFunctionParams& parameters) override {
64 // Create persistent/shared memory and allow histograms to be stored in it.
65 // Memory that is not actualy used won't be physically mapped by the system.
66 // BrowserMetrics usage peaked around 95% of 2MiB as of 2016-02-20.
Ilya Sherman 2016/04/25 19:48:41 nit: "95% of 2MiB" is confusing -- it kind of soun
bcwhite 2016/04/25 20:37:17 That is what it means. Better to just say "1.9MiB
67 base::GlobalHistogramAllocator::CreateWithLocalMemory(
68 3 << 20, // 3 MiB
69 0x935DDD43, // SHA1(BrowserMetrics)
70 "BrowserMetrics");
71 base::GlobalHistogramAllocator::Disable(); // Enabled by experiment only.
72
63 SCOPED_UMA_HISTOGRAM_LONG_TIMER( 73 SCOPED_UMA_HISTOGRAM_LONG_TIMER(
64 "Startup.BrowserMainRunnerImplInitializeLongTime"); 74 "Startup.BrowserMainRunnerImplInitializeLongTime");
65 75
66 // TODO(vadimt, yiyaoliu): Remove all tracked_objects references below once 76 // TODO(vadimt, yiyaoliu): Remove all tracked_objects references below once
67 // crbug.com/453640 is fixed. 77 // crbug.com/453640 is fixed.
68 tracked_objects::ThreadData::InitializeThreadContext(kMainThreadName); 78 tracked_objects::ThreadData::InitializeThreadContext(kMainThreadName);
69 base::trace_event::AllocationContextTracker::SetCurrentThreadName( 79 base::trace_event::AllocationContextTracker::SetCurrentThreadName(
70 kMainThreadName); 80 kMainThreadName);
71 TRACK_SCOPED_REGION( 81 TRACK_SCOPED_REGION(
72 "Startup", "BrowserMainRunnerImpl::Initialize"); 82 "Startup", "BrowserMainRunnerImpl::Initialize");
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring 227 // Forcefully terminates the RunLoop inside MessagePumpForUI, ensuring
218 // proper shutdown for content_browsertests. Shutdown() is not used by 228 // proper shutdown for content_browsertests. Shutdown() is not used by
219 // the actual browser. 229 // the actual browser.
220 if (base::MessageLoop::current()->is_running()) 230 if (base::MessageLoop::current()->is_running())
221 base::MessageLoop::current()->QuitNow(); 231 base::MessageLoop::current()->QuitNow();
222 #endif 232 #endif
223 main_loop_.reset(NULL); 233 main_loop_.reset(NULL);
224 234
225 notification_service_.reset(NULL); 235 notification_service_.reset(NULL);
226 236
237 // Dump all the persistent metrics to a file for upload during the next
238 // run of the browser.
239 base::GlobalHistogramAllocator* allocator =
240 base::GlobalHistogramAllocator::Get();
241 if (allocator)
Ilya Sherman 2016/04/25 19:48:41 Under what circumstances can the allocator be null
bcwhite 2016/04/25 20:37:17 It will be null if the allocator has been disabled
Ilya Sherman 2016/04/25 21:12:11 Yikes, that is so confusing that it confused me ev
bcwhite 2016/04/26 13:32:30 Acknowledged.
242 allocator->WriteToPersistentLocation();
243
227 is_shutdown_ = true; 244 is_shutdown_ = true;
228 } 245 }
229 } 246 }
230 247
231 protected: 248 protected:
232 // True if we have started to initialize the runner. 249 // True if we have started to initialize the runner.
233 bool initialization_started_; 250 bool initialization_started_;
234 251
235 // True if the runner has been shut down. 252 // True if the runner has been shut down.
236 bool is_shutdown_; 253 bool is_shutdown_;
(...skipping 12 matching lines...) Expand all
249 BrowserMainRunner* BrowserMainRunner::Create() { 266 BrowserMainRunner* BrowserMainRunner::Create() {
250 return new BrowserMainRunnerImpl(); 267 return new BrowserMainRunnerImpl();
251 } 268 }
252 269
253 // static 270 // static
254 bool BrowserMainRunner::ExitedMainMessageLoop() { 271 bool BrowserMainRunner::ExitedMainMessageLoop() {
255 return g_exited_main_message_loop; 272 return g_exited_main_message_loop;
256 } 273 }
257 274
258 } // namespace content 275 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698