OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/common/metrics/variations/uniformity_field_trials.h" | |
6 | |
7 #include "base/metrics/field_trial.h" | |
8 #include "base/stringprintf.h" | |
9 #include "chrome/common/metrics/variations/variations_util.h" | |
10 | |
11 namespace { | |
12 | |
13 // Set up a uniformity field trial. |one_time_randomized| indicates if the | |
14 // field trial is one-time randomized or session-randomized. |trial_name_string| | |
15 // must contain a "%d" since the percentage of the group will be inserted in | |
16 // the trial name. |num_trial_groups| must be a divisor of 100 (e.g. 5, 20) | |
17 void SetupSingleUniformityFieldTrial( | |
18 bool one_time_randomized, | |
19 const std::string& trial_name_string, | |
20 const chrome_variations::VariationID trial_base_id, | |
21 int num_trial_groups) { | |
22 // Probability per group remains constant for all uniformity trials, what | |
23 // changes is the probability divisor. | |
24 static const base::FieldTrial::Probability kProbabilityPerGroup = 1; | |
25 const std::string kDefaultGroupName = "default"; | |
26 const base::FieldTrial::Probability divisor = num_trial_groups; | |
27 | |
28 DCHECK_EQ(100 % num_trial_groups, 0); | |
29 const int group_percent = 100 / num_trial_groups; | |
30 const std::string trial_name = StringPrintf(trial_name_string.c_str(), | |
31 group_percent); | |
32 | |
33 DVLOG(1) << "Trial name = " << trial_name; | |
34 | |
35 scoped_refptr<base::FieldTrial> trial( | |
36 base::FieldTrialList::FactoryGetFieldTrial( | |
37 trial_name, divisor, kDefaultGroupName, 2015, 1, 1, NULL)); | |
38 if (one_time_randomized) | |
39 trial->UseOneTimeRandomization(); | |
40 chrome_variations::AssociateGoogleVariationID( | |
41 chrome_variations::GOOGLE_WEB_PROPERTIES, trial_name, kDefaultGroupName, | |
42 trial_base_id); | |
43 chrome_variations::AssociateGoogleVariationID( | |
44 chrome_variations::GOOGLE_UPDATE_SERVICE, trial_name, kDefaultGroupName, | |
45 trial_base_id); | |
46 | |
47 // Loop starts with group 1 because the field trial automatically creates a | |
48 // default group, which would be group 0. | |
49 for (int group_number = 1; group_number < num_trial_groups; ++group_number) { | |
50 const std::string group_name = StringPrintf("group_%02d", group_number); | |
51 DVLOG(1) << " Group name = " << group_name; | |
52 trial->AppendGroup(group_name, kProbabilityPerGroup); | |
53 chrome_variations::AssociateGoogleVariationID( | |
54 chrome_variations::GOOGLE_WEB_PROPERTIES, trial_name, group_name, | |
55 static_cast<chrome_variations::VariationID>(trial_base_id + | |
56 group_number)); | |
57 chrome_variations::AssociateGoogleVariationID( | |
58 chrome_variations::GOOGLE_UPDATE_SERVICE, trial_name, group_name, | |
59 static_cast<chrome_variations::VariationID>(trial_base_id + | |
60 group_number)); | |
61 } | |
62 | |
63 // Now that all groups have been appended, call group() on the trial to | |
64 // ensure that our trial is registered. This resolves an off-by-one issue | |
65 // where the default group never gets chosen if we don't "use" the trial. | |
66 const int chosen_group = trial->group(); | |
67 DVLOG(1) << "Chosen Group: " << chosen_group; | |
68 } | |
69 | |
70 // Setup a 50% uniformity trial for new installs only. This is accomplished by | |
71 // disabling the trial on clients that were installed before a specified date. | |
72 void SetupNewInstallUniformityTrial(const base::Time& install_date) { | |
73 const base::Time::Exploded kStartDate = { | |
74 2012, 11, 0, 6, // Nov 6, 2012 | |
75 0, 0, 0, 0 // 00:00:00.000 | |
76 }; | |
77 scoped_refptr<base::FieldTrial> trial( | |
78 base::FieldTrialList::FactoryGetFieldTrial( | |
79 "UMA-New-Install-Uniformity-Trial", 100, "Disabled", | |
80 2015, 1, 1, NULL)); | |
81 trial->UseOneTimeRandomization(); | |
82 trial->AppendGroup("Control", 50); | |
83 trial->AppendGroup("Experiment", 50); | |
84 const base::Time start_date = base::Time::FromLocalExploded(kStartDate); | |
85 if (install_date < start_date) | |
86 trial->Disable(); | |
87 else | |
88 trial->group(); | |
89 } | |
90 | |
91 } // namespace | |
92 | |
93 namespace chrome_variations { | |
94 | |
95 void SetupUniformityFieldTrials(const base::Time& install_date) { | |
96 // One field trial will be created for each entry in this array. The i'th | |
97 // field trial will have |trial_sizes[i]| groups in it, including the default | |
98 // group. Each group will have a probability of 1/|trial_sizes[i]|. | |
99 const int num_trial_groups[] = { 100, 20, 10, 5, 2 }; | |
100 | |
101 // Declare our variation ID bases along side this array so we can loop over it | |
102 // and assign the IDs appropriately. So for example, the 1 percent experiments | |
103 // should have a size of 100 (100/100 = 1). | |
104 const chrome_variations::VariationID trial_base_ids[] = { | |
105 chrome_variations::UNIFORMITY_1_PERCENT_BASE, | |
106 chrome_variations::UNIFORMITY_5_PERCENT_BASE, | |
Alexei Svitkine (slow)
2013/02/27 16:24:55
Nit: Indent 2? Alternatively, indent 4 the kStartD
SteveT
2013/02/27 16:33:48
Haha, I had originally made this indent 2 but then
| |
107 chrome_variations::UNIFORMITY_10_PERCENT_BASE, | |
108 chrome_variations::UNIFORMITY_20_PERCENT_BASE, | |
109 chrome_variations::UNIFORMITY_50_PERCENT_BASE | |
110 }; | |
111 | |
112 const std::string kOneTimeRandomizedTrialName = | |
113 "UMA-Uniformity-Trial-%d-Percent"; | |
114 for (size_t i = 0; i < arraysize(num_trial_groups); ++i) { | |
115 SetupSingleUniformityFieldTrial(true, kOneTimeRandomizedTrialName, | |
116 trial_base_ids[i], num_trial_groups[i]); | |
117 } | |
118 | |
119 // Setup a 5% session-randomized uniformity trial. | |
120 const std::string kSessionRandomizedTrialName = | |
121 "UMA-Session-Randomized-Uniformity-Trial-%d-Percent"; | |
122 SetupSingleUniformityFieldTrial(false, kSessionRandomizedTrialName, | |
123 chrome_variations::UNIFORMITY_SESSION_RANDOMIZED_5_PERCENT_BASE, 20); | |
124 | |
125 SetupNewInstallUniformityTrial(install_date); | |
126 } | |
127 | |
128 } // namespace chrome_variations | |
OLD | NEW |