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

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

Issue 9117037: Added a Unique ID for a Field Trial containing it's hashed name and the selected group ID. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 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') | base/metrics/field_trial.cc » ('J')
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #include "base/synchronization/lock.h" 85 #include "base/synchronization/lock.h"
86 #include "base/time.h" 86 #include "base/time.h"
87 87
88 namespace base { 88 namespace base {
89 89
90 class FieldTrialList; 90 class FieldTrialList;
91 91
92 class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> { 92 class BASE_EXPORT FieldTrial : public RefCounted<FieldTrial> {
93 public: 93 public:
94 typedef int Probability; // Probability type for being selected in a trial. 94 typedef int Probability; // Probability type for being selected in a trial.
95 // The Unique ID of a trial, first element is a hashed value of the name
96 // and the second one is the group identifier.
97 struct NameGroupId{
98 uint32 name;
99 uint32 group;
100 };
95 101
96 // A return value to indicate that a given instance has not yet had a group 102 // A return value to indicate that a given instance has not yet had a group
97 // assignment (and hence is not yet participating in the trial). 103 // assignment (and hence is not yet participating in the trial).
98 static const int kNotFinalized; 104 static const int kNotFinalized;
99 105
100 // This is the group number of the 'default' group. This provides an easy way 106 // This is the group number of the 'default' group. This provides an easy way
101 // to assign all the remaining probability to a group ('default'). 107 // to assign all the remaining probability to a group ('default').
102 static const int kDefaultGroupNumber; 108 static const int kDefaultGroupNumber;
103 109
104 // The name is used to register the instance with the FieldTrialList class, 110 // The name is used to register the instance with the FieldTrialList class,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // Return the randomly selected group number that was assigned. 147 // Return the randomly selected group number that was assigned.
142 // Return kDefaultGroupNumber if the instance is in the 'default' group. 148 // Return kDefaultGroupNumber if the instance is in the 'default' group.
143 // Note that this will force an instance to participate, and make it illegal 149 // Note that this will force an instance to participate, and make it illegal
144 // to attempt to probabilistically add any other groups to the trial. 150 // to attempt to probabilistically add any other groups to the trial.
145 int group(); 151 int group();
146 152
147 // If the group's name is empty, a string version containing the group 153 // If the group's name is empty, a string version containing the group
148 // number is used as the group name. 154 // number is used as the group name.
149 std::string group_name(); 155 std::string group_name();
150 156
157 // Gets the unique identifier of the Field Trial, but only if a winner was
158 // elected. Returns true if a winner is returned, false otherwise.
159 bool GetNameGroupId(NameGroupId* name_group_id);
160
151 // Return the default group name of the FieldTrial. 161 // Return the default group name of the FieldTrial.
152 std::string default_group_name() const { return default_group_name_; } 162 std::string default_group_name() const { return default_group_name_; }
153 163
154 // Helper function for the most common use: as an argument to specify the 164 // Helper function for the most common use: as an argument to specify the
155 // name of a HISTOGRAM. Use the original histogram name as the name_prefix. 165 // name of a HISTOGRAM. Use the original histogram name as the name_prefix.
156 static std::string MakeName(const std::string& name_prefix, 166 static std::string MakeName(const std::string& name_prefix,
157 const std::string& trial_name); 167 const std::string& trial_name);
158 168
159 // Enable benchmarking sets field trials to a common setting. 169 // Enable benchmarking sets field trials to a common setting.
160 static void EnableBenchmarking(); 170 static void EnableBenchmarking();
161 171
162 private: 172 private:
163 // Allow tests to access our innards for testing purposes. 173 // Allow tests to access our innards for testing purposes.
164 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Registration); 174 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Registration);
165 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, AbsoluteProbabilities); 175 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, AbsoluteProbabilities);
166 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, RemainingProbability); 176 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, RemainingProbability);
167 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FiftyFiftyProbability); 177 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, FiftyFiftyProbability);
168 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, MiddleProbabilities); 178 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, MiddleProbabilities);
169 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, OneWinner); 179 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, OneWinner);
170 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DisableProbability); 180 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DisableProbability);
171 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Save); 181 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, Save);
172 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore); 182 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, DuplicateRestore);
173 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, MakeName); 183 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, MakeName);
174 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientId); 184 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientId);
175 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientIdIsUniform); 185 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, HashClientIdIsUniform);
176 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, UseOneTimeRandomization); 186 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, UseOneTimeRandomization);
187 FRIEND_TEST_ALL_PREFIXES(FieldTrialTest, NameGroupIds);
177 188
178 friend class base::FieldTrialList; 189 friend class base::FieldTrialList;
179 190
180 friend class RefCounted<FieldTrial>; 191 friend class RefCounted<FieldTrial>;
181 192
182 virtual ~FieldTrial(); 193 virtual ~FieldTrial();
183 194
184 // Returns the group_name. A winner need not have been chosen. 195 // Returns the group_name. A winner need not have been chosen.
185 std::string group_name_internal() const { return group_name_; } 196 std::string group_name_internal() const { return group_name_; }
186 197
187 // Calculates a uniformly-distributed double between [0.0, 1.0) given 198 // Calculates a uniformly-distributed double between [0.0, 1.0) given
188 // a |client_id| and a |trial_name| (the latter is used as salt to avoid 199 // a |client_id| and a |trial_name| (the latter is used as salt to avoid
189 // separate one-time randomized trials from all having the same results). 200 // separate one-time randomized trials from all having the same results).
190 static double HashClientId(const std::string& client_id, 201 static double HashClientId(const std::string& client_id,
191 const std::string& trial_name); 202 const std::string& trial_name);
192 203
204 // Creates unique identifier for the trial by hashing the name string.
205 static uint32 HashName(const std::string& name);
206
193 // The name of the field trial, as can be found via the FieldTrialList. 207 // The name of the field trial, as can be found via the FieldTrialList.
194 const std::string name_; 208 const std::string name_;
195 209
210 // The hashed name of the field trial to be sent as a unique identifier.
211 const uint32 name_hash_;
212
196 // The maximum sum of all probabilities supplied, which corresponds to 100%. 213 // The maximum sum of all probabilities supplied, which corresponds to 100%.
197 // This is the scaling factor used to adjust supplied probabilities. 214 // This is the scaling factor used to adjust supplied probabilities.
198 const Probability divisor_; 215 const Probability divisor_;
199 216
200 // The name of the default group. 217 // The name of the default group.
201 const std::string default_group_name_; 218 const std::string default_group_name_;
202 219
203 // The randomly selected probability that is used to select a group (or have 220 // The randomly selected probability that is used to select a group (or have
204 // the instance not participate). It is the product of divisor_ and a random 221 // the instance not participate). It is the product of divisor_ and a random
205 // number between [0, 1). 222 // number between [0, 1).
206 Probability random_; 223 Probability random_;
207 224
208 // Sum of the probabilities of all appended groups. 225 // Sum of the probabilities of all appended groups.
209 Probability accumulated_group_probability_; 226 Probability accumulated_group_probability_;
210 227
211 int next_group_number_; 228 int next_group_number_;
212 229
213 // The pseudo-randomly assigned group number. 230 // The pseudo-randomly assigned group number.
214 // This is kNotFinalized if no group has been assigned. 231 // This is kNotFinalized if no group has been assigned.
215 int group_; 232 int group_;
216 233
217 // A textual name for the randomly selected group. Valid after |group()| 234 // A textual name for the randomly selected group. Valid after |group()|
218 // has been called. 235 // has been called.
219 std::string group_name_; 236 std::string group_name_;
220 237
238 // The hashed name of the group to be sent as a unique identifier.
239 // Is not valid while group_ is equal to kNotFinalized.
jar (doing other things) 2012/01/24 21:51:23 Since you don't have synchronization, you need to
MAD 2012/01/25 00:14:48 Done.
240 uint32 group_name_hash_;
241
221 // When enable_field_trial_ is false, field trial reverts to the 'default' 242 // When enable_field_trial_ is false, field trial reverts to the 'default'
222 // group. 243 // group.
223 bool enable_field_trial_; 244 bool enable_field_trial_;
224 245
225 // When benchmarking is enabled, field trials all revert to the 'default' 246 // When benchmarking is enabled, field trials all revert to the 'default'
226 // group. 247 // group.
227 static bool enable_benchmarking_; 248 static bool enable_benchmarking_;
228 249
229 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 250 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
230 }; 251 };
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 299
279 // Returns the group name chosen for the named trial, or the 300 // Returns the group name chosen for the named trial, or the
280 // empty string if the trial does not exist. 301 // empty string if the trial does not exist.
281 static std::string FindFullName(const std::string& name); 302 static std::string FindFullName(const std::string& name);
282 303
283 // Returns true if the named trial has been registered. 304 // Returns true if the named trial has been registered.
284 static bool TrialExists(const std::string& name); 305 static bool TrialExists(const std::string& name);
285 306
286 // Create a persistent representation of all FieldTrial instances and the 307 // Create a persistent representation of all FieldTrial instances and the
287 // |client_id()| state for resurrection in another process. This allows 308 // |client_id()| state for resurrection in another process. This allows
288 // randomization to be done in one process, and secondary processes can by 309 // randomization to be done in one process, and secondary processes can be
289 // synchronized on the result. The resulting string contains the 310 // synchronized on the result. The resulting string contains the
290 // |client_id()|, the names, the trial name, and a "/" separator. 311 // |client_id()|, the names, the trial name, and a "/" separator.
291 static void StatesToString(std::string* output); 312 static void StatesToString(std::string* output);
292 313
314 // Returns an array of Unique IDs for each currently running Field Trials.
315 static void GetFieldTrialNameGroupIds(
316 std::vector<FieldTrial::NameGroupId>* name_group_ids);
317
293 // Use a previously generated state string (re: StatesToString()) augment the 318 // Use a previously generated state string (re: StatesToString()) augment the
294 // current list of field tests to include the supplied tests, and using a 100% 319 // current list of field tests to include the supplied tests, and using a 100%
295 // probability for each test, force them to have the same group string. This 320 // probability for each test, force them to have the same group string. This
296 // is commonly used in a non-browser process, to carry randomly selected state 321 // is commonly used in a non-browser process, to carry randomly selected state
297 // in a browser process into this non-browser process. This method calls 322 // in a browser process into this non-browser process. This method calls
298 // CreateFieldTrial to create the FieldTrial in the non-browser process. 323 // CreateFieldTrial to create the FieldTrial in the non-browser process.
299 // Currently only the group_name_ and name_ are restored, as well as the 324 // Currently only the group_name_ and name_ are restored, as well as the
300 // |client_id()| state, that could be used for one-time randomized trials 325 // |client_id()| state, that could be used for one-time randomized trials
301 // set up only in child processes. 326 // set up only in child processes.
302 static bool CreateTrialsInChildProcess(const std::string& prior_trials); 327 static bool CreateTrialsInChildProcess(const std::string& prior_trials);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 404
380 // List of observers to be notified when a group is selected for a FieldTrial. 405 // List of observers to be notified when a group is selected for a FieldTrial.
381 ObserverList<Observer> observer_list_; 406 ObserverList<Observer> observer_list_;
382 407
383 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 408 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
384 }; 409 };
385 410
386 } // namespace base 411 } // namespace base
387 412
388 #endif // BASE_METRICS_FIELD_TRIAL_H_ 413 #endif // BASE_METRICS_FIELD_TRIAL_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | base/metrics/field_trial.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698