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. |
32 void InstantiatePersistentHistograms() { | 36 void InstantiatePersistentHistograms() { |
Alexei Svitkine (slow)
2016/06/28 15:08:00
Both this code and corresponding code in chrome_me
bcwhite
2016/06/29 03:17:03
Acknowledged.
| |
33 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { | 37 base::FilePath metrics_dir; |
34 // Create persistent/shared memory and allow histograms to be stored in | 38 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 | 39 return; |
36 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | 40 |
37 // as of 2016-02-20. | 41 base::FilePath metrics_file = |
42 metrics_dir | |
43 .AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName) | |
44 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
45 base::FilePath active_file = | |
46 metrics_dir | |
47 .AppendASCII( | |
48 std::string(ChromeMetricsServiceClient::kBrowserMetricsName) + | |
49 "-active") | |
50 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
51 | |
52 // Move any existing "active" file to the final name from which it will be | |
53 // read when reporting initial stability metrics. If there is no file to | |
Alexei Svitkine (slow)
2016/06/28 15:08:00
I'm not sure this behavior makes sense.
The initi
bcwhite
2016/06/29 03:17:03
The FileMetricsProvider, when doing RecordInitialH
| |
54 // move, remove any old, existing file from before the previous session. | |
55 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) | |
56 base::DeleteFile(metrics_file, /*recursive=*/false); | |
57 | |
58 // Create persistent/shared memory and allow histograms to be stored in | |
59 // it. Memory that is not actualy used won't be physically mapped by the | |
60 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | |
61 // as of 2016-02-20. | |
62 const size_t kAllocSize = 3 << 20; // 3 MiB | |
63 const uint32_t kAllocId = 0x935DDD43; // SHA1(BrowserMetrics) | |
64 std::string storage = variations::GetVariationParamValue( | |
Alexei Svitkine (slow)
2016/06/28 15:08:00
Use GetVariationParamValueByFeature().
bcwhite
2016/06/29 03:17:03
Done.
| |
65 base::kPersistentHistogramsFeature.name, "storage"); | |
66 if (storage == "MappedFile") { | |
67 // Create global allocator with the "active" file. | |
68 base::GlobalHistogramAllocator::CreateWithFile( | |
69 active_file, kAllocSize, kAllocId, | |
70 ChromeMetricsServiceClient::kBrowserMetricsName); | |
71 } else if (storage == "LocalMemory") { | |
72 // Use local memory for storage even though it will not persist across | |
73 // an unclean shutdown. | |
38 base::GlobalHistogramAllocator::CreateWithLocalMemory( | 74 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
39 3 << 20, // 3 MiB | 75 kAllocSize, kAllocId, ChromeMetricsServiceClient::kBrowserMetricsName); |
40 0x935DDD43, // SHA1(BrowserMetrics) | 76 } else { |
41 ChromeMetricsServiceClient::kBrowserMetricsName); | 77 // Persistent metric storage is disabled. |
42 base::GlobalHistogramAllocator* allocator = | 78 return; |
43 base::GlobalHistogramAllocator::Get(); | |
44 allocator->CreateTrackingHistograms( | |
45 ChromeMetricsServiceClient::kBrowserMetricsName); | |
46 } | 79 } |
80 | |
81 base::GlobalHistogramAllocator* allocator = | |
82 base::GlobalHistogramAllocator::Get(); | |
83 allocator->CreateTrackingHistograms( | |
84 ChromeMetricsServiceClient::kBrowserMetricsName); | |
85 allocator->SetPersistentLocation(active_file); | |
47 } | 86 } |
48 | 87 |
49 } // namespace | 88 } // namespace |
50 | 89 |
51 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 90 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
52 const base::CommandLine& parsed_command_line) | 91 const base::CommandLine& parsed_command_line) |
53 : parsed_command_line_(parsed_command_line) { | 92 : parsed_command_line_(parsed_command_line) { |
54 } | 93 } |
55 | 94 |
56 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 95 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
57 } | 96 } |
58 | 97 |
59 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 98 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
60 // Field trials that are shared by all platforms. | 99 // Field trials that are shared by all platforms. |
61 InstantiateDynamicTrials(); | 100 InstantiateDynamicTrials(); |
62 | 101 |
63 #if defined(OS_ANDROID) | 102 #if defined(OS_ANDROID) |
64 chrome::SetupMobileFieldTrials(parsed_command_line_); | 103 chrome::SetupMobileFieldTrials(parsed_command_line_); |
65 #else | 104 #else |
66 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 105 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
67 #endif | 106 #endif |
68 } | 107 } |
69 | 108 |
70 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 109 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
71 // Persistent histograms must be enabled as soon as possible. | 110 // Persistent histograms must be enabled as soon as possible. |
72 InstantiatePersistentHistograms(); | 111 InstantiatePersistentHistograms(); |
73 tracing::SetupBackgroundTracingFieldTrial(); | 112 tracing::SetupBackgroundTracingFieldTrial(); |
74 } | 113 } |
OLD | NEW |