| 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/persistent_histogram_allocator.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/browser/metrics/chrome_metrics_service_client.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "components/metrics/metrics_pref_names.h" | 19 #include "components/metrics/metrics_pref_names.h" |
| 19 | 20 |
| 20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 21 #include "chrome/browser/chrome_browser_field_trials_mobile.h" | 22 #include "chrome/browser/chrome_browser_field_trials_mobile.h" |
| 22 #else | 23 #else |
| 23 #include "chrome/browser/chrome_browser_field_trials_desktop.h" | 24 #include "chrome/browser/chrome_browser_field_trials_desktop.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // Check for feature enabling the use of persistent histogram storage and | 29 // Check for feature enabling the use of persistent histogram storage and |
| 29 // enable the global allocator if so. | 30 // enable the global allocator if so. |
| 30 void InstantiatePersistentHistograms() { | 31 void InstantiatePersistentHistograms() { |
| 31 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { | 32 if (base::FeatureList::IsEnabled(base::kPersistentHistogramsFeature)) { |
| 32 base::GlobalHistogramAllocator::Enable(); | 33 // Create persistent/shared memory and allow histograms to be stored in |
| 34 // it. Memory that is not actualy used won't be physically mapped by the |
| 35 // system. BrowserMetrics usage, as reported in UMA, peaked around 1.9MiB |
| 36 // as of 2016-02-20. |
| 37 base::GlobalHistogramAllocator::CreateWithLocalMemory( |
| 38 3 << 20, // 3 MiB |
| 39 0x935DDD43, // SHA1(BrowserMetrics) |
| 40 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 33 base::GlobalHistogramAllocator* allocator = | 41 base::GlobalHistogramAllocator* allocator = |
| 34 base::GlobalHistogramAllocator::Get(); | 42 base::GlobalHistogramAllocator::Get(); |
| 35 DCHECK(allocator); // Should have been created during startup. | 43 allocator->CreateTrackingHistograms( |
| 36 allocator->CreateTrackingHistograms(allocator->Name()); | 44 ChromeMetricsServiceClient::kBrowserMetricsName); |
| 37 } | 45 } |
| 38 } | 46 } |
| 39 | 47 |
| 40 } // namespace | 48 } // namespace |
| 41 | 49 |
| 42 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( | 50 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( |
| 43 const base::CommandLine& parsed_command_line) | 51 const base::CommandLine& parsed_command_line) |
| 44 : parsed_command_line_(parsed_command_line) { | 52 : parsed_command_line_(parsed_command_line) { |
| 45 } | 53 } |
| 46 | 54 |
| 47 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { | 55 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { |
| 48 } | 56 } |
| 49 | 57 |
| 50 void ChromeBrowserFieldTrials::SetupFieldTrials() { | 58 void ChromeBrowserFieldTrials::SetupFieldTrials() { |
| 51 // Field trials that are shared by all platforms. | 59 // Field trials that are shared by all platforms. |
| 52 InstantiateDynamicTrials(); | 60 InstantiateDynamicTrials(); |
| 53 | 61 |
| 54 #if defined(OS_ANDROID) | 62 #if defined(OS_ANDROID) |
| 55 chrome::SetupMobileFieldTrials(parsed_command_line_); | 63 chrome::SetupMobileFieldTrials(parsed_command_line_); |
| 56 #else | 64 #else |
| 57 chrome::SetupDesktopFieldTrials(parsed_command_line_); | 65 chrome::SetupDesktopFieldTrials(parsed_command_line_); |
| 58 #endif | 66 #endif |
| 59 } | 67 } |
| 60 | 68 |
| 61 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { | 69 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { |
| 62 // Persistent histograms must be enabled as soon as possible. | 70 // Persistent histograms must be enabled as soon as possible. |
| 63 InstantiatePersistentHistograms(); | 71 InstantiatePersistentHistograms(); |
| 64 } | 72 } |
| OLD | NEW |