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

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

Issue 6213001: disable field trials if the build is 30 days or older (Closed) Base URL: http://src.chromium.org/svn/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') | net/disk_cache/backend_impl.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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/lock.h" 69 #include "base/lock.h"
70 #include "base/logging.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
75 class FieldTrial : public RefCounted<FieldTrial> { 76 class FieldTrial : public RefCounted<FieldTrial> {
76 public: 77 public:
77 typedef int Probability; // Probability type for being selected in a trial. 78 typedef int Probability; // Probability type for being selected in a trial.
78 79
79 // A return value to indicate that a given instance has not yet had a group 80 // A return value to indicate that a given instance has not yet had a group
(...skipping 23 matching lines...) Expand all
103 std::string name() const { return name_; } 104 std::string name() const { return name_; }
104 105
105 // Return the randomly selected group number that was assigned. 106 // Return the randomly selected group number that was assigned.
106 // Return kNotParticipating if the instance is not participating in the 107 // Return kNotParticipating if the instance is not participating in the
107 // experiment. 108 // experiment.
108 int group() const { return group_; } 109 int group() const { return group_; }
109 110
110 // If the field trial is not in an experiment, this returns the empty string. 111 // 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 112 // if the group's name is empty, a name of "_" concatenated with the group
112 // number is used as the group name. 113 // number is used as the group name.
113 std::string group_name() const { return group_name_; } 114 std::string group_name() const {
115 DCHECK(all_remaining_probability_set_);
116 return group_name_;
117 }
118
119 // Set the usage_timeout from build time of the module to disable Field Trial.
120 void SetUsageTimeout(const base::TimeDelta& usage_timeout);
121
122 base::TimeDelta usageTimeout() const {
123 return usage_timeout_;
124 }
114 125
115 // Helper function for the most common use: as an argument to specifiy the 126 // 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. 127 // name of a HISTOGRAM. Use the original histogram name as the name_prefix.
117 static std::string MakeName(const std::string& name_prefix, 128 static std::string MakeName(const std::string& name_prefix,
118 const std::string& trial_name); 129 const std::string& trial_name);
119 130
120 // Enable benchmarking sets field trials to a common setting. 131 // Enable benchmarking sets field trials to a common setting.
121 static void EnableBenchmarking(); 132 static void EnableBenchmarking();
122 133
123 private: 134 private:
124 friend class RefCounted<FieldTrial>; 135 friend class RefCounted<FieldTrial>;
125 136
126 virtual ~FieldTrial(); 137 virtual ~FieldTrial();
127 138
139 // Determine if the field trial is to be disabled or not based on
140 // usage_timeout_, build time of the module and Now(). This method sets
141 // disable_field_trial_ to true, if the difference between build time of the
142 // module and Now() is greater than usage_timeout_. If disable_field_trial_ is
143 // true then the field trial reverts to the 'default' bucket.
144 static bool ShouldFieldTrialBeDisabled(
145 const base::TimeDelta& usage_timeout);
146
147 // Get build time.
148 static Time GetBuildTime();
149
128 // The name of the field trial, as can be found via the FieldTrialList. 150 // 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. 151 // This is empty of the trial is not in the experiment.
130 const std::string name_; 152 const std::string name_;
131 153
132 // The maximum sum of all probabilities supplied, which corresponds to 100%. 154 // The maximum sum of all probabilities supplied, which corresponds to 100%.
133 // This is the scaling factor used to adjust supplied probabilities. 155 // This is the scaling factor used to adjust supplied probabilities.
134 Probability divisor_; 156 Probability divisor_;
135 157
136 // The randomly selected probability that is used to select a group (or have 158 // 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 159 // the instance not participate). It is the product of divisor_ and a random
138 // number between [0, 1). 160 // number between [0, 1).
139 Probability random_; 161 Probability random_;
140 162
141 // Sum of the probabilities of all appended groups. 163 // Sum of the probabilities of all appended groups.
142 Probability accumulated_group_probability_; 164 Probability accumulated_group_probability_;
143 165
144 int next_group_number_; 166 int next_group_number_;
145 167
146 // The pseudo-randomly assigned group number. 168 // The pseudo-randomly assigned group number.
147 // This is kNotParticipating if no group has been assigned. 169 // This is kNotParticipating if no group has been assigned.
148 int group_; 170 int group_;
149 171
150 // A textual name for the randomly selected group, including the Trial name. 172 // A textual name for the randomly selected group, including the Trial name.
151 // If this Trial is not a member of an group, this string is empty. 173 // If this Trial is not a member of an group, this string is empty.
152 std::string group_name_; 174 std::string group_name_;
153 175
176 // Used to assert that kAllRemainingProbability is beig used.
177 // bucket.
178 bool all_remaining_probability_set_;
179
180 // The default value (all remaining probabilities) can be selected after the
181 // usage_timeout, which is based on the build time of the module.
182 base::TimeDelta usage_timeout_;
183
184 // When disable_field_trial_ is true, field trial reverts to the 'default'
185 // bucket.
186 bool disable_field_trial_;
187
154 // When benchmarking is enabled, field trials all revert to the 'default' 188 // When benchmarking is enabled, field trials all revert to the 'default'
155 // bucket. 189 // bucket.
156 static bool enable_benchmarking_; 190 static bool enable_benchmarking_;
157 191
158 DISALLOW_COPY_AND_ASSIGN(FieldTrial); 192 DISALLOW_COPY_AND_ASSIGN(FieldTrial);
159 }; 193 };
160 194
161 //------------------------------------------------------------------------------ 195 //------------------------------------------------------------------------------
162 // Class with a list of all active field trials. A trial is active if it has 196 // 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. 197 // been registered, which includes evaluating its state based on its probaility.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 Lock lock_; 273 Lock lock_;
240 RegistrationList registered_; 274 RegistrationList registered_;
241 275
242 DISALLOW_COPY_AND_ASSIGN(FieldTrialList); 276 DISALLOW_COPY_AND_ASSIGN(FieldTrialList);
243 }; 277 };
244 278
245 } // namespace base 279 } // namespace base
246 280
247 #endif // BASE_METRICS_FIELD_TRIAL_H_ 281 #endif // BASE_METRICS_FIELD_TRIAL_H_
248 282
OLDNEW
« no previous file with comments | « no previous file | base/metrics/field_trial.cc » ('j') | net/disk_cache/backend_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698