Chromium Code Reviews| 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" |
| 21 | 24 |
| 22 #if defined(OS_ANDROID) | 25 #if defined(OS_ANDROID) |
| 23 #include "chrome/browser/chrome_browser_field_trials_mobile.h" | 26 #include "chrome/browser/chrome_browser_field_trials_mobile.h" |
| 24 #else | 27 #else |
| 25 #include "chrome/browser/chrome_browser_field_trials_desktop.h" | 28 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
| 26 #endif | 29 #endif |
| 27 | 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 // Check for feature enabling the use of persistent histogram storage and | 33 // Check for feature enabling the use of persistent histogram storage and |
| 31 // enable the global allocator if so. | 34 // enable the global allocator if so. |
| 32 void InstantiatePersistentHistograms() { | 35 void InstantiatePersistentHistograms() { |
| 33 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { | 36 const std::string feature_group = base::FieldTrialList::FindFullName( |
| 34 // Create persistent/shared memory and allow histograms to be stored in | 37 base::kPersistentHistogramsFeature.name); |
| 35 // it. Memory that is not actualy used won't be physically mapped by the | 38 |
| 36 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | 39 base::FilePath metrics_dir; |
| 37 // as of 2016-02-20. | 40 if (!base::PathService::Get(chrome::DIR_USER_DATA, &metrics_dir)) { |
| 41 NOTREACHED(); | |
| 42 return; | |
| 43 } | |
| 44 | |
| 45 base::FilePath metrics_file = | |
| 46 metrics_dir | |
| 47 .AppendASCII(ChromeMetricsServiceClient::kBrowserMetricsName) | |
| 48 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
| 49 base::FilePath active_file = | |
| 50 metrics_dir | |
| 51 .AppendASCII( | |
| 52 std::string(ChromeMetricsServiceClient::kBrowserMetricsName) + | |
| 53 "-active") | |
| 54 .AddExtension(base::PersistentMemoryAllocator::kFileExtension); | |
| 55 | |
| 56 // Move any existing "active" file to the final name from which it will be | |
| 57 // read when reporting initial stability metrics. If there is no file to | |
| 58 // move, remove any old, existing file from before the previous session. | |
| 59 if (!base::ReplaceFile(active_file, metrics_file, nullptr)) | |
| 60 base::DeleteFile(metrics_file, /*recursive=*/false); | |
| 61 | |
| 62 // Stop here if the feature is not enabled. | |
| 63 if (feature_group.empty() || feature_group == "Disabled") | |
|
Alexei Svitkine (slow)
2016/06/16 11:36:57
Please don't use == to compare groups. Best practi
bcwhite
2016/06/16 14:21:08
I started down that path but found it more complic
Alexei Svitkine (slow)
2016/06/16 14:28:02
String =='s is fine for variations params, since t
bcwhite
2016/06/16 14:31:43
I meant the experiment name as in "Enabled", "Disa
Alexei Svitkine (slow)
2016/06/16 14:34:40
Because we're discouraging using experiment name t
| |
| 64 return; | |
| 65 | |
| 66 // Create persistent/shared memory and allow histograms to be stored in | |
| 67 // it. Memory that is not actualy used won't be physically mapped by the | |
| 68 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB | |
| 69 // as of 2016-02-20. | |
| 70 const size_t kAllocSize = 3 << 20; // 3 MiB | |
| 71 const uint32_t kAllocId = 0x935DDD43; // SHA1(BrowserMetrics) | |
| 72 if (feature_group == "Enabled") { | |
| 38 base::GlobalHistogramAllocator::CreateWithLocalMemory( | 73 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
| 39 3 << 20, // 3 MiB | 74 kAllocSize, kAllocId, |
| 40 0x935DDD43, // SHA1(BrowserMetrics) | |
| 41 ChromeMetricsServiceClient::kBrowserMetricsName); | 75 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 42 base::GlobalHistogramAllocator* allocator = | 76 } else if (feature_group == "MappedFile") { |
| 43 base::GlobalHistogramAllocator::Get(); | 77 // Create global allocator with the "active" file. |
| 44 allocator->CreateTrackingHistograms( | 78 base::GlobalHistogramAllocator::CreateWithFile( |
| 79 active_file, kAllocSize, kAllocId, | |
| 45 ChromeMetricsServiceClient::kBrowserMetricsName); | 80 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 81 } else { | |
| 82 // Shouldn't happen but fail gracefully if it does. | |
| 83 NOTREACHED() << feature_group; | |
| 84 return; | |
| 46 } | 85 } |
| 86 | |
| 87 base::GlobalHistogramAllocator* allocator = | |
| 88 base::GlobalHistogramAllocator::Get(); | |
| 89 allocator->CreateTrackingHistograms( | |
| 90 ChromeMetricsServiceClient::kBrowserMetricsName); | |
| 91 allocator->SetPersistentLocation(active_file); | |
| 47 } | 92 } |
| 48 | 93 |
| 49 } // namespace | 94 } // namespace |
| 50 | 95 |
| 51 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 96 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
| 52 const base::CommandLine& parsed_command_line) | 97 const base::CommandLine& parsed_command_line) |
| 53 : parsed_command_line_(parsed_command_line) { | 98 : parsed_command_line_(parsed_command_line) { |
| 54 } | 99 } |
| 55 | 100 |
| 56 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 101 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
| 57 } | 102 } |
| 58 | 103 |
| 59 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 104 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
| 60 // Field trials that are shared by all platforms. | 105 // Field trials that are shared by all platforms. |
| 61 InstantiateDynamicTrials(); | 106 InstantiateDynamicTrials(); |
| 62 | 107 |
| 63 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) |
| 64 chrome::SetupMobileFieldTrials(parsed_command_line_); | 109 chrome::SetupMobileFieldTrials(parsed_command_line_); |
| 65 #else | 110 #else |
| 66 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 111 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
| 67 #endif | 112 #endif |
| 68 } | 113 } |
| 69 | 114 |
| 70 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 115 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
| 71 // Persistent histograms must be enabled as soon as possible. | 116 // Persistent histograms must be enabled as soon as possible. |
| 72 InstantiatePersistentHistograms(); | 117 InstantiatePersistentHistograms(); |
| 73 tracing::SetupBackgroundTracingFieldTrial(); | 118 tracing::SetupBackgroundTracingFieldTrial(); |
| 74 } | 119 } |
| OLD | NEW |