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_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 // create an appropriate allocator for such 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 const char kAllocatorName[] = "BrowserMetrics"; |
| 33 // Create persistent/shared memory and allow histograms to be stored in it. | 36 // 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. | 37 // 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. | 38 // BrowserMetrics usage peaked around 95% of 2MiB as of 2016-02-20. |
| 36 base::GlobalHistogramAllocator::CreateWithLocalMemory( | 39 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
| 37 3 << 20, // 3 MiB | 40 3 << 20, // 3 MiB |
| 38 0x935DDD43, // SHA1(BrowserMetrics) | 41 0x935DDD43, // SHA1(BrowserMetrics) |
| 39 kAllocatorName); | 42 kAllocatorName); |
| 40 base::GlobalHistogramAllocator::Get()->CreateTrackingHistograms( | 43 base::GlobalHistogramAllocator::Get()->CreateTrackingHistograms( |
| 41 kAllocatorName); | 44 kAllocatorName); |
| 45 | |
| 46 // Set the destination for where these will be persistent. This shouldn't | |
|
Ilya Sherman
2016/04/19 00:57:46
nit: s/persistent/persisted
bcwhite
2016/04/19 16:33:38
Done.
| |
| 47 // be necessary because it's done in chrome_metrics_service_client.cc where | |
| 48 // the reading of this file is configured but field trials don't get done | |
| 49 // until after that point so there is no global allocator to configure | |
| 50 // when that code runs. This won't be a problem when this (eventually) | |
| 51 // becomes standard and is enabled during early startup. | |
| 52 base::FilePath metrics_file; | |
| 53 if (base::PathService::Get(chrome::DIR_USER_DATA, &metrics_file)) { | |
| 54 metrics_file = metrics_file.AppendASCII(kAllocatorName) | |
| 55 .AddExtension(FILE_PATH_LITERAL(".pma")); | |
| 56 base::GlobalHistogramAllocator::Get() | |
| 57 ->SetPersistentLocation(metrics_file); | |
| 58 } | |
|
Ilya Sherman
2016/04/19 00:57:46
I think I'd prefer to always set the location from
bcwhite
2016/04/19 16:33:38
I could add Disable/Enable methods to the GlobalHi
| |
| 42 } | 59 } |
| 43 } | 60 } |
| 44 | 61 |
| 45 } // namespace | 62 } // namespace |
| 46 | 63 |
| 47 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 64 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
| 48 const base::CommandLine& parsed_command_line) | 65 const base::CommandLine& parsed_command_line) |
| 49 : parsed_command_line_(parsed_command_line) { | 66 : parsed_command_line_(parsed_command_line) { |
| 50 } | 67 } |
| 51 | 68 |
| 52 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 69 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
| 53 } | 70 } |
| 54 | 71 |
| 55 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 72 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
| 56 // Field trials that are shared by all platforms. | 73 // Field trials that are shared by all platforms. |
| 57 InstantiateDynamicTrials(); | 74 InstantiateDynamicTrials(); |
| 58 | 75 |
| 59 #if defined(OS_ANDROID) | 76 #if defined(OS_ANDROID) |
| 60 chrome::SetupMobileFieldTrials(parsed_command_line_); | 77 chrome::SetupMobileFieldTrials(parsed_command_line_); |
| 61 #else | 78 #else |
| 62 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 79 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
| 63 #endif | 80 #endif |
| 64 } | 81 } |
| 65 | 82 |
| 66 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 83 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
| 67 // Persistent histograms must be enabled as soon as possible. | 84 // Persistent histograms must be enabled as soon as possible. |
| 68 InstantiatePersistentHistograms(); | 85 InstantiatePersistentHistograms(); |
| 69 } | 86 } |
| OLD | NEW |