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

Side by Side Diff: chrome/browser/chrome_browser_field_trials.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 "chrome/browser/chrome_browser_field_trials.h" 5 #include "chrome/browser/chrome_browser_field_trials.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
11 #include "base/files/file_path.h"
11 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram_base.h" 13 #include "base/metrics/histogram_base.h"
13 #include "base/metrics/persistent_histogram_allocator.h" 14 #include "base/metrics/persistent_histogram_allocator.h"
15 #include "base/path_service.h"
14 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
16 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/common/chrome_paths.h"
17 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
18 #include "components/metrics/metrics_pref_names.h" 21 #include "components/metrics/metrics_pref_names.h"
19 22
20 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
21 #include "chrome/browser/chrome_browser_field_trials_mobile.h" 24 #include "chrome/browser/chrome_browser_field_trials_mobile.h"
22 #else 25 #else
23 #include "chrome/browser/chrome_browser_field_trials_desktop.h" 26 #include "chrome/browser/chrome_browser_field_trials_desktop.h"
24 #endif 27 #endif
25 28
26 namespace { 29 namespace {
27 30
28 // Check for feature enabling the use of persistent histogram storage and 31 // Check for feature enabling the use of persistent histogram storage and
29 // create an appropriate allocator for such if so. 32 // enable the global allocator if so.
30 void InstantiatePersistentHistograms() { 33 void InstantiatePersistentHistograms() {
31 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { 34 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) {
32 const char kAllocatorName[] = "BrowserMetrics"; 35 base::GlobalHistogramAllocator::Enable();
Ilya Sherman 2016/04/25 19:48:40 It seems odd to have this as a static method. Why
bcwhite 2016/04/25 20:37:17 I considered both. The general differentiation ha
Ilya Sherman 2016/04/25 21:12:11 I don't really follow, sorry. In any case, I don'
bcwhite 2016/04/26 13:32:30 My style matches yours but I've been previously as
Ilya Sherman 2016/04/26 20:01:24 Okay, I agree that if the base PHA class doesn't n
33 // Create persistent/shared memory and allow histograms to be stored in it. 36 base::GlobalHistogramAllocator* allocator =
34 // Memory that is not actualy used won't be physically mapped by the system. 37 base::GlobalHistogramAllocator::Get();
35 // BrowserMetrics usage peaked around 95% of 2MiB as of 2016-02-20. 38 DCHECK(allocator); // Should have been created during startup.
36 base::GlobalHistogramAllocator::CreateWithLocalMemory( 39 allocator->CreateTrackingHistograms(allocator->Name());
37 3 << 20, // 3 MiB
38 0x935DDD43, // SHA1(BrowserMetrics)
39 kAllocatorName);
40 base::GlobalHistogramAllocator::Get()->CreateTrackingHistograms(
41 kAllocatorName);
42 } 40 }
43 } 41 }
44 42
45 } // namespace 43 } // namespace
46 44
47 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( 45 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials(
48 const base::CommandLine& parsed_command_line) 46 const base::CommandLine& parsed_command_line)
49 : parsed_command_line_(parsed_command_line) { 47 : parsed_command_line_(parsed_command_line) {
50 } 48 }
51 49
52 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { 50 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() {
53 } 51 }
54 52
55 void ChromeBrowserFieldTrials::SetupFieldTrials() { 53 void ChromeBrowserFieldTrials::SetupFieldTrials() {
56 // Field trials that are shared by all platforms. 54 // Field trials that are shared by all platforms.
57 InstantiateDynamicTrials(); 55 InstantiateDynamicTrials();
58 56
59 #if defined(OS_ANDROID) 57 #if defined(OS_ANDROID)
60 chrome::SetupMobileFieldTrials(parsed_command_line_); 58 chrome::SetupMobileFieldTrials(parsed_command_line_);
61 #else 59 #else
62 chrome::SetupDesktopFieldTrials(parsed_command_line_); 60 chrome::SetupDesktopFieldTrials(parsed_command_line_);
63 #endif 61 #endif
64 } 62 }
65 63
66 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { 64 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() {
67 // Persistent histograms must be enabled as soon as possible. 65 // Persistent histograms must be enabled as soon as possible.
68 InstantiatePersistentHistograms(); 66 InstantiatePersistentHistograms();
69 } 67 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698