Chromium Code Reviews| Index: base/metrics/field_trial.cc |
| =================================================================== |
| --- base/metrics/field_trial.cc (revision 222861) |
| +++ base/metrics/field_trial.cc (working copy) |
| @@ -38,10 +38,25 @@ |
| return Time::FromLocalExploded(exploded); |
| } |
| +// Returns the boundary value for comparing against the FieldTrial's added |
| +// groups for a given |divisor| (total probability) and |entropy_value|. |
| +FieldTrial::Probability GetGroupBoundaryValue( |
| + FieldTrial::Probability divisor, |
| + double entropy_value) { |
| + // Add a tiny epsilon value to get consistent results when converting floating |
| + // points to int. Without it, boundary values have inconsistent results, e.g.: |
|
jar (doing other things)
2013/09/16 21:54:40
Isn't what you really want is rounding, rather tha
Alexei Svitkine (slow)
2013/09/16 22:30:46
I don't think so, let me see if you agree. Here's
jar (doing other things)
2013/09/18 01:38:24
I think rounding is incorrect (I should have looke
Alexei Svitkine (slow)
2013/09/18 16:39:53
I agree that this is a potential issue. I think it
|
| + // |
| + // static_cast<FieldTrial::Probability>(100 * 0.56) == 56 |
| + // static_cast<FieldTrial::Probability>(100 * 0.57) == 56 |
| + // static_cast<FieldTrial::Probability>(100 * 0.58) == 57 |
| + // static_cast<FieldTrial::Probability>(100 * 0.59) == 59 |
| + const double kEpsilon = 1e-8; |
| + return static_cast<FieldTrial::Probability>(divisor * entropy_value + |
| + kEpsilon); |
| +} |
| + |
| } // namespace |
| -static const char kHistogramFieldTrialSeparator('_'); |
| - |
| // statics |
| const int FieldTrial::kNotFinalized = -1; |
| const int FieldTrial::kDefaultGroupNumber = 0; |
| @@ -60,7 +75,7 @@ |
| : trial_name_(trial_name), |
| divisor_(total_probability), |
| default_group_name_(default_group_name), |
| - random_(static_cast<Probability>(divisor_ * entropy_value)), |
| + random_(GetGroupBoundaryValue(total_probability, entropy_value)), |
| accumulated_group_probability_(0), |
| next_group_number_(kDefaultGroupNumber + 1), |
| group_(kNotFinalized), |