Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: chrome/browser/chrome_browser_field_trials.cc

Issue 2010173005: Support experiment to store persistent metrics in memory-mapped file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved file cleanup to anonymous function Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
Ilya Sherman 2016/06/17 19:54:32 nit: Please move this down to where it's used.
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();
Ilya Sherman 2016/06/17 19:54:32 nit: Chrome style guidelines recommend either a NO
bcwhite 2016/06/20 16:21:28 Done.
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")
64 return;
Ilya Sherman 2016/06/17 19:54:32 Please use the FeatureList API to test whether the
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, ChromeMetricsServiceClient::kBrowserMetricsName);
40 0x935DDD43, // SHA1(BrowserMetrics) 75 } else if (feature_group == "MappedFile") {
76 // Create global allocator with the "active" file.
77 base::GlobalHistogramAllocator::CreateWithFile(
78 active_file, kAllocSize, kAllocId,
41 ChromeMetricsServiceClient::kBrowserMetricsName); 79 ChromeMetricsServiceClient::kBrowserMetricsName);
Ilya Sherman 2016/06/17 19:54:32 I *think* the latest advice that I saw about using
Ilya Sherman 2016/06/17 19:57:23 Ah, I actually wrote this before going back and re
bcwhite 2016/06/20 16:21:28 Done.
42 base::GlobalHistogramAllocator* allocator = 80 } else {
43 base::GlobalHistogramAllocator::Get(); 81 // Shouldn't happen but fail gracefully if it does.
44 allocator->CreateTrackingHistograms( 82 NOTREACHED() << feature_group;
45 ChromeMetricsServiceClient::kBrowserMetricsName); 83 return;
Ilya Sherman 2016/06/17 19:54:32 nit: Ditto about NOTREACHED() or early return. In
46 } 84 }
85
86 base::GlobalHistogramAllocator* allocator =
87 base::GlobalHistogramAllocator::Get();
88 allocator->CreateTrackingHistograms(
89 ChromeMetricsServiceClient::kBrowserMetricsName);
90 allocator->SetPersistentLocation(active_file);
47 } 91 }
48 92
49 } // namespace 93 } // namespace
50 94
51 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials( 95 ChromeBrowserFieldTrials::ChromeBrowserFieldTrials(
52 const base::CommandLine& parsed_command_line) 96 const base::CommandLine& parsed_command_line)
53 : parsed_command_line_(parsed_command_line) { 97 : parsed_command_line_(parsed_command_line) {
54 } 98 }
55 99
56 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() { 100 ChromeBrowserFieldTrials::~ChromeBrowserFieldTrials() {
57 } 101 }
58 102
59 void ChromeBrowserFieldTrials::SetupFieldTrials() { 103 void ChromeBrowserFieldTrials::SetupFieldTrials() {
60 // Field trials that are shared by all platforms. 104 // Field trials that are shared by all platforms.
61 InstantiateDynamicTrials(); 105 InstantiateDynamicTrials();
62 106
63 #if defined(OS_ANDROID) 107 #if defined(OS_ANDROID)
64 chrome::SetupMobileFieldTrials(parsed_command_line_); 108 chrome::SetupMobileFieldTrials(parsed_command_line_);
65 #else 109 #else
66 chrome::SetupDesktopFieldTrials(parsed_command_line_); 110 chrome::SetupDesktopFieldTrials(parsed_command_line_);
67 #endif 111 #endif
68 } 112 }
69 113
70 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() { 114 void ChromeBrowserFieldTrials::InstantiateDynamicTrials() {
71 // Persistent histograms must be enabled as soon as possible. 115 // Persistent histograms must be enabled as soon as possible.
72 InstantiatePersistentHistograms(); 116 InstantiatePersistentHistograms();
73 tracing::SetupBackgroundTracingFieldTrial(); 117 tracing::SetupBackgroundTracingFieldTrial();
74 } 118 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698