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

Side by Side Diff: base/metrics/field_trial.h

Issue 6317004: Feature to disable field trials in old versions of Chromium. Field trials... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // FieldTrial is a class for handling details of statistical experiments 5 // FieldTrial is a class for handling details of statistical experiments
6 // performed by actual users in the field (i.e., in a shipped or beta product). 6 // performed by actual users in the field (i.e., in a shipped or beta product).
7 // All code is called exclusively on the UI thread currently. 7 // All code is called exclusively on the UI thread currently.
8 // 8 //
9 // The simplest example is an experiment to see whether one of two options 9 // The simplest example is an experiment to see whether one of two options
10 // produces "better" results across our user population. In that scenario, UMA 10 // produces "better" results across our user population. In that scenario, UMA
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 //------------------------------------------------------------------------------ 60 //------------------------------------------------------------------------------
61 61
62 #ifndef BASE_METRICS_FIELD_TRIAL_H_ 62 #ifndef BASE_METRICS_FIELD_TRIAL_H_
63 #define BASE_METRICS_FIELD_TRIAL_H_ 63 #define BASE_METRICS_FIELD_TRIAL_H_
64 #pragma once 64 #pragma once
65 65
66 #include <map> 66 #include <map>
67 #include <string> 67 #include <string>
68 68
69 #include "base/gtest_prod_util.h"
69 #include "base/lock.h" 70 #include "base/lock.h"
70 #include "base/ref_counted.h" 71 #include "base/ref_counted.h"
71 #include "base/time.h" 72 #include "base/time.h"
72 73
73 namespace base { 74 namespace base {
74 75
76 class FieldTrialList;
77
75 class FieldTrial : public RefCounted<FieldTrial> { 78 class FieldTrial : public RefCounted<FieldTrial> {
76 public: 79 public:
77 typedef int Probability; // Probability type for being selected in a trial. 80 typedef int Probability; // Probability type for being selected in a trial.
78 81
79 // A return value to indicate that a given instance has not yet had a group 82 // A return value to indicate that a given instance has not yet had a group
80 // assignment (and hence is not yet participating in the trial). 83 // assignment (and hence is not yet participating in the trial).
81 static const int kNotParticipating; 84 static const int kNotFinalized;
82 85
83 // Provide an easy way to assign all remaining probability to a group. Note 86 // This is the group number of the 'default' group. This provides an easy way
84 // that this will force an instance to participate, and make it illegal to 87 // to assign all the remaining probability to a group ('default').
85 // attempt to probabalistically add any other groups to the trial. When doing 88 static const int kDefaultGroupNumber;
86 // A/B tests with timings, it is often best to define all groups, so that
87 // histograms will get unique names via the MakeName() methods.
88 static const Probability kAllRemainingProbability;
89 89
90 // The name is used to register the instance with the FieldTrialList class, 90 // The name is used to register the instance with the FieldTrialList class,
91 // and can be used to find the trial (only one trial can be present for each 91 // and can be used to find the trial (only one trial can be present for each
92 // name). 92 // name).
93 // Group probabilities that are later supplied must sum to less than or equal 93 // Group probabilities that are later supplied must sum to less than or equal
94 // to the total_probability. 94 // to the total_probability. Arguments year, month and day_of_month specify
95 FieldTrial(const std::string& name, Probability total_probability); 95 // the expiration time. If the build time is after the expiration time then
96 // the field trial reverts to the 'default' group.
97 FieldTrial(const std::string& name, Probability total_probability,
98 const std::string& default_group_name, const int year,
99 const int month, const int day_of_month);
96 100
97 // Establish the name and probability of the next group in this trial. 101 // Establish the name and probability of the next group in this trial.
98 // Sometimes, based on construction randomization, this call may causes the 102 // Sometimes, based on construction randomization, this call may causes the
jar (doing other things) 2011/01/19 06:53:56 nit: existing typo? causes-->cause
rtenneti 2011/01/19 07:24:34 Done.
99 // provided group to be *THE* group selected for use in this instance. 103 // provided group to be *THE* group selected for use in this instance.
100 int AppendGroup(const std::string& name, Probability group_probability); 104 int AppendGroup(const std::string& name, Probability group_probability);
101 105
102 // Return the name of the FieldTrial (excluding the group name). 106 // Return the name of the FieldTrial (excluding the group name).
103 std::string name() const { return name_; } 107 std::string name() const { return name_; }
104 108
105 // Return the randomly selected group number that was assigned. 109 // Return the randomly selected group number that was assigned.
106 // Return kNotParticipating if the instance is not participating in the 110 // Return kDefaultGroupNumber if the instance is in the 'default' group.
107 // experiment. 111 // Note that this will force an instance to participate, and make it illegal
108 int group() const { return group_; } 112 // to attempt to probabalistically add any other groups to the trial.
113 int group();
109 114
110 // If the field trial is not in an experiment, this returns the empty string. 115 // If the field trial is not in an experiment, this returns the empty string.
111 // if the group's name is empty, a name of "_" concatenated with the group 116 // if the group's name is empty, a name of "_" concatenated with the group
112 // number is used as the group name. 117 // number is used as the group name.
113 std::string group_name() const { return group_name_; } 118 std::string group_name();
119
120 // Return the default group name of the FieldTrial.
121 std::string default_group_name() const { return default_group_name_; }
114 122
115 // Helper function for the most common use: as an argument to specifiy the 123 // Helper function for the most common use: as an argument to specifiy the
116 // name of a HISTOGRAM. Use the original histogram name as the name_prefix. 124 // name of a HISTOGRAM. Use the original histogram name as the name_prefix.
117 static std::string MakeName(const std::string& name_prefix, 125 static std::string MakeName(const std::string& name_prefix,
118 const std::string& trial_name); 126 const std::string& trial_name);
119 127
120 // Enable benchmarking sets field trials to a common setting. 128 // Enable benchmarking sets field trials to a common setting.
121 static void EnableBenchmarking(); 129 static void EnableBenchmarking();
122 130
123 private: 131 private:
132 // Allow tests to access our innards for testing purposes.
133 FRIEND_TEST(FieldTrialTest, Registration);
134 FRIEND_TEST(FieldTrialTest, AbsoluteProbabilities);
135 FRIEND_TEST(FieldTrialTest, RemainingProbability);
136 FRIEND_TEST(FieldTrialTest, FiftyFiftyProbability);
137 FRIEND_TEST(FieldTrialTest, MiddleProbabilities);
138 FRIEND_TEST(FieldTrialTest, OneWinner);
139 FRIEND_TEST(FieldTrialTest, DisableProbability);
140 FRIEND_TEST(FieldTrialTest, Save);
141 FRIEND_TEST(FieldTrialTest, DuplicateRestore);
142 FRIEND_TEST(FieldTrialTest, MakeName);
143
144 friend class base::FieldTrialList;
145
124 friend class RefCounted<FieldTrial>; 146 friend class RefCounted<FieldTrial>;
125 147
126 virtual ~FieldTrial(); 148 virtual ~FieldTrial();
127 149
150 // Returns the group_name. A winner need not have been chosen.
151 std::string group_name_internal() const { return group_name_; }
152
153 // Get build time.
154 static Time GetBuildTime();
155
128 // The name of the field trial, as can be found via the FieldTrialList. 156 // The name of the field trial, as can be found via the FieldTrialList.
129 // This is empty of the trial is not in the experiment. 157 // This is empty of the trial is not in the experiment.
130 const std::string name_; 158 const std::string name_;
131 159
132 // The maximum sum of all probabilities supplied, which corresponds to 100%. 160 // The maximum sum of all probabilities supplied, which corresponds to 100%.
133 // This is the scaling factor used to adjust supplied probabilities. 161 // This is the scaling factor used to adjust supplied probabilities.
134 Probability divisor_; 162 const Probability divisor_;
163
164 // The name of the default group.
165 const std::string default_group_name_;
135 166
136 // The randomly selected probability that is used to select a group (or have 167 // The randomly selected probability that is used to select a group (or have
137 // the instance not participate). It is the product of divisor_ and a random 168 // the instance not participate). It is the product of divisor_ and a random
138 // number between [0, 1). 169 // number between [0, 1).
139 Probability random_; 170 Probability random_;
140 171
141 // Sum of the probabilities of all appended groups. 172 // Sum of the probabilities of all appended groups.
142 Probability accumulated_group_probability_; 173 Probability accumulated_group_probability_;
143 174
144 int next_group_number_; 175 int next_group_number_;
145 176
146 // The pseudo-randomly assigned group number. 177 // The pseudo-randomly assigned group number.
147 // This is kNotParticipating if no group has been assigned. 178 // This is kNotFinalized if no group has been assigned.
148 int group_; 179 int group_;
149 180
150 // A textual name for the randomly selected group, including the Trial name. 181 // A textual name for the randomly selected group. If this Trial is not a
151 // If this Trial is not a member of an group, this string is empty. 182 // member of an group, this string is empty.
152 std::string group_name_; 183 std::string group_name_;
153 184
185 // When disable_field_trial_ is true, field trial reverts to the 'default'
186 // group.
187 bool disable_field_trial_;
188
154 // When benchmarking is enabled, field trials all revert to the 'default' 189 // When benchmarking is enabled, field trials all revert to the 'default'
155 // bucket. 190 // group.
156 static bool enable_benchmarking_; 191 static bool enable_benchmarking_;
157 192
158 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 193 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
159 }; 194 };
160 195
161 //------------------------------------------------------------------------------ 196 //------------------------------------------------------------------------------
162 // Class with a list of all active field trials. A trial is active if it has 197 // Class with a list of all active field trials. A trial is active if it has
163 // been registered, which includes evaluating its state based on its probaility. 198 // been registered, which includes evaluating its state based on its probaility.
164 // Only one instance of this class exists. 199 // Only one instance of this class exists.
165 class FieldTrialList { 200 class FieldTrialList {
(...skipping 26 matching lines...) Expand all
192 // The resulting string contains only the names, the trial name, and a "/" 227 // The resulting string contains only the names, the trial name, and a "/"
193 // separator. 228 // separator.
194 static void StatesToString(std::string* output); 229 static void StatesToString(std::string* output);
195 230
196 // Use a previously generated state string (re: StatesToString()) augment the 231 // Use a previously generated state string (re: StatesToString()) augment the
197 // current list of field tests to include the supplied tests, and using a 100% 232 // current list of field tests to include the supplied tests, and using a 100%
198 // probability for each test, force them to have the same group string. This 233 // probability for each test, force them to have the same group string. This
199 // is commonly used in a sub-process, to carry randomly selected state in a 234 // is commonly used in a sub-process, to carry randomly selected state in a
200 // parent process into this sub-process. 235 // parent process into this sub-process.
201 // Currently only the group_name_ and name_ are restored. 236 // Currently only the group_name_ and name_ are restored.
202 static bool StringAugmentsState(const std::string& prior_state); 237 static bool CreateTrialsInChildProcess(const std::string& prior_trials);
203 238
204 // The time of construction of the global map is recorded in a static variable 239 // The time of construction of the global map is recorded in a static variable
205 // and is commonly used by experiments to identify the time since the start 240 // and is commonly used by experiments to identify the time since the start
206 // of the application. In some experiments it may be useful to discount 241 // of the application. In some experiments it may be useful to discount
207 // data that is gathered before the application has reached sufficient 242 // data that is gathered before the application has reached sufficient
208 // stability (example: most DLL have loaded, etc.) 243 // stability (example: most DLL have loaded, etc.)
209 static TimeTicks application_start_time() { 244 static TimeTicks application_start_time() {
210 if (global_) 245 if (global_)
211 return global_->application_start_time_; 246 return global_->application_start_time_;
212 // For testing purposes only, or when we don't yet have a start time. 247 // For testing purposes only, or when we don't yet have a start time.
(...skipping 26 matching lines...) Expand all
239 Lock lock_; 274 Lock lock_;
240 RegistrationList registered_; 275 RegistrationList registered_;
241 276
242 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 277 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
243 }; 278 };
244 279
245 } // namespace base 280 } // namespace base
246 281
247 #endif // BASE_METRICS_FIELD_TRIAL_H_ 282 #endif // BASE_METRICS_FIELD_TRIAL_H_
248 283
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698