OLD | NEW |
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/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
13 #include "base/metrics/histogram_persistence.h" | 13 #include "base/metrics/persistent_histogram_allocator.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "components/metrics/metrics_pref_names.h" | 18 #include "components/metrics/metrics_pref_names.h" |
19 | 19 |
20 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
21 #include "chrome/browser/chrome_browser_field_trials_mobile.h" | 21 #include "chrome/browser/chrome_browser_field_trials_mobile.h" |
22 #else | 22 #else |
23 #include "chrome/browser/chrome_browser_field_trials_desktop.h" | 23 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 // Check for feature enabling the use of persistent histogram storage and | 28 // Check for feature enabling the use of persistent histogram storage and |
29 // create an appropriate allocator for such if so. | 29 // create an appropriate allocator for such if so. |
30 void InstantiatePersistentHistograms() { | 30 void InstantiatePersistentHistograms() { |
31 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { | 31 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { |
32 const char kAllocatorName[] = "BrowserMetrics"; | 32 const char kAllocatorName[] = "BrowserMetrics"; |
33 // Create persistent/shared memory and allow histograms to be stored in it. | 33 // Create persistent/shared memory and allow histograms to be stored in it. |
34 // Memory that is not actualy used won't be physically mapped by the system. | 34 // Memory that is not actualy used won't be physically mapped by the system. |
35 // BrowserMetrics usage peaked around 95% of 2MiB as of 2016-02-20. | 35 // BrowserMetrics usage peaked around 95% of 2MiB as of 2016-02-20. |
36 base::SetPersistentHistogramMemoryAllocator( | 36 base::PersistentHistogramAllocator::SetGlobalAllocator( |
37 new base::LocalPersistentMemoryAllocator(3 << 20, // 3 MiB | 37 make_scoped_ptr(new base::PersistentHistogramAllocator( |
38 0x935DDD43, // SHA1(B...M...) | 38 make_scoped_ptr(new base::LocalPersistentMemoryAllocator( |
39 kAllocatorName)); | 39 3 << 20, // 3 MiB |
40 base::GetPersistentHistogramMemoryAllocator()->CreateTrackingHistograms( | 40 0x935DDD43, // SHA1(BrowserMetrics) |
41 kAllocatorName); | 41 kAllocatorName))))); |
| 42 base::PersistentHistogramAllocator::GetGlobalAllocator() |
| 43 ->CreateTrackingHistograms(kAllocatorName); |
42 } | 44 } |
43 } | 45 } |
44 | 46 |
45 } // namespace | 47 } // namespace |
46 | 48 |
47 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 49 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
48 const base::CommandLine& parsed_command_line) | 50 const base::CommandLine& parsed_command_line) |
49 : parsed_command_line_(parsed_command_line) { | 51 : parsed_command_line_(parsed_command_line) { |
50 } | 52 } |
51 | 53 |
52 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 54 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
53 } | 55 } |
54 | 56 |
55 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 57 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
56 // Field trials that are shared by all platforms. | 58 // Field trials that are shared by all platforms. |
57 InstantiateDynamicTrials(); | 59 InstantiateDynamicTrials(); |
58 | 60 |
59 #if defined(OS_ANDROID) | 61 #if defined(OS_ANDROID) |
60 chrome::SetupMobileFieldTrials(parsed_command_line_); | 62 chrome::SetupMobileFieldTrials(parsed_command_line_); |
61 #else | 63 #else |
62 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 64 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
63 #endif | 65 #endif |
64 } | 66 } |
65 | 67 |
66 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 68 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
67 // Persistent histograms must be enabled as soon as possible. | 69 // Persistent histograms must be enabled as soon as possible. |
68 InstantiatePersistentHistograms(); | 70 InstantiatePersistentHistograms(); |
69 } | 71 } |
OLD | NEW |