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/files/file_util.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" |
17 #include "chrome/browser/metrics/chrome_metrics_service_client.h" | 19 #include "chrome/browser/metrics/chrome_metrics_service_client.h" |
18 #include "chrome/browser/tracing/background_tracing_field_trial.h" | 20 #include "chrome/browser/tracing/background_tracing_field_trial.h" |
21 #include "chrome/common/chrome_paths.h" | |
19 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
20 #include "components/metrics/metrics_pref_names.h" | 23 #include "components/metrics/metrics_pref_names.h" |
24 #include "components/variations/variations_associated_data.h" | |
21 | 25 |
22 #if defined(OS_ANDROID) | 26 #if defined(OS_ANDROID) |
23 #include "chrome/browser/chrome_browser_field_trials_mobile.h" | 27 #include "chrome/browser/chrome_browser_field_trials_mobile.h" |
24 #else | 28 #else |
25 #include "chrome/browser/chrome_browser_field_trials_desktop.h" | 29 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
26 #endif | 30 #endif |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 // Check for feature enabling the use of persistent histogram storage and | 34 // Check for feature enabling the use of persistent histogram storage and |
31 // enable the global allocator if so. | 35 // enable the global allocator if so. |
36 // TODO(bcwhite): Move this and CreateInstallerFileMetricsProvider into a new | |
37 // file and make kBrowserMetricsName local to that file. | |
32 void InstantiatePersistentHistograms() { | 38 void InstantiatePersistentHistograms() { |
33 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { | 39 base::FilePath metrics_dir; |
34 // Create persistent/shared memory and allow histograms to be stored in | 40 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) |
35 // it. Memory that is not actualy used won't be physically mapped by the | 41 return; |
36 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | 42 |
37 // as of 2016-02-20. | 43 base::FilePath metrics_file = |
44 metrics_dir | |
45 .AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName) | |
46 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
47 base::FilePath active_file = | |
48 metrics_dir | |
49 .AppendASCII( | |
50 std::string(ChromeMetricsServiceClient::kBrowserMetricsName) + | |
51 "-active") | |
52 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
53 | |
54 // Move any existing "active" file to the final name from which it will be | |
55 // read when reporting initial stability metrics. If there is no file to | |
56 // move, remove any old, existing file from before the previous session. | |
57 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) | |
58 base::DeleteFile(metrics_file, /*recursive=*/false); | |
59 | |
60 // Create persistent/shared memory and allow histograms to be stored in | |
61 // it. Memory that is not actualy used won't be physically mapped by the | |
62 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | |
63 // as of 2016-02-20. | |
64 const size_t kAllocSize = 3 << 20; // 3 MiB | |
Ilya Sherman
2016/06/29 20:41:38
Unrelated to this CL: What happens if the alloc si
bcwhite
2016/06/30 22:56:12
In that case, new histograms will get allocated fr
Ilya Sherman
2016/06/30 23:16:48
Okay, sounds good. Do we have metrics in place to
bcwhite
2016/07/11 18:06:39
Not directly. There is a measure of how much of t
| |
65 const uint32_t kAllocId = 0x935DDD43; // SHA1(BrowserMetrics) | |
66 std::string storage = variations::GetVariationParamValueByFeature( | |
67 base::kPersistentHistogramsFeature, "storage"); | |
68 if (storage == "MappedFile") { | |
69 // Create global allocator with the "active" file. | |
70 base::GlobalHistogramAllocator::CreateWithFile( | |
71 active_file, kAllocSize, kAllocId, | |
72 ChromeMetricsServiceClient::kBrowserMetricsName); | |
73 } else if (storage == "LocalMemory") { | |
74 // Use local memory for storage even though it will not persist across | |
75 // an unclean shutdown. | |
38 base::GlobalHistogramAllocator::CreateWithLocalMemory( | 76 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
39 3 << 20, // 3 MiB | 77 kAllocSize, kAllocId, ChromeMetricsServiceClient::kBrowserMetricsName); |
40 0x935DDD43, // SHA1(BrowserMetrics) | 78 } else { |
41 ChromeMetricsServiceClient::kBrowserMetricsName); | 79 // Persistent metric storage is disabled. |
42 base::GlobalHistogramAllocator* allocator = | 80 return; |
43 base::GlobalHistogramAllocator::Get(); | |
44 allocator->CreateTrackingHistograms( | |
45 ChromeMetricsServiceClient::kBrowserMetricsName); | |
46 } | 81 } |
82 | |
83 base::GlobalHistogramAllocator* allocator = | |
84 base::GlobalHistogramAllocator::Get(); | |
85 allocator->CreateTrackingHistograms( | |
86 ChromeMetricsServiceClient::kBrowserMetricsName); | |
87 allocator->SetPersistentLocation(active_file); | |
47 } | 88 } |
48 | 89 |
49 } // namespace | 90 } // namespace |
50 | 91 |
51 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 92 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
52 const base::CommandLine& parsed_command_line) | 93 const base::CommandLine& parsed_command_line) |
53 : parsed_command_line_(parsed_command_line) { | 94 : parsed_command_line_(parsed_command_line) { |
54 } | 95 } |
55 | 96 |
56 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 97 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
57 } | 98 } |
58 | 99 |
59 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 100 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
60 // Field trials that are shared by all platforms. | 101 // Field trials that are shared by all platforms. |
61 InstantiateDynamicTrials(); | 102 InstantiateDynamicTrials(); |
62 | 103 |
63 #if defined(OS_ANDROID) | 104 #if defined(OS_ANDROID) |
64 chrome::SetupMobileFieldTrials(parsed_command_line_); | 105 chrome::SetupMobileFieldTrials(parsed_command_line_); |
65 #else | 106 #else |
66 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 107 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
67 #endif | 108 #endif |
68 } | 109 } |
69 | 110 |
70 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 111 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
71 // Persistent histograms must be enabled as soon as possible. | 112 // Persistent histograms must be enabled as soon as possible. |
72 InstantiatePersistentHistograms(); | 113 InstantiatePersistentHistograms(); |
73 tracing::SetupBackgroundTracingFieldTrial(); | 114 tracing::SetupBackgroundTracingFieldTrial(); |
74 } | 115 } |
OLD | NEW |