Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/metrics/field_trial.h" | 5 #include "base/metrics/field_trial.h" |
| 6 | 6 |
| 7 #include "base/build_time.h" | 7 #include "base/build_time.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/sha1.h" | 10 #include "base/sha1.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 exploded.day_of_week = 0; // Should be unused. | 31 exploded.day_of_week = 0; // Should be unused. |
| 32 exploded.day_of_month = day_of_month; | 32 exploded.day_of_month = day_of_month; |
| 33 exploded.hour = 0; | 33 exploded.hour = 0; |
| 34 exploded.minute = 0; | 34 exploded.minute = 0; |
| 35 exploded.second = 0; | 35 exploded.second = 0; |
| 36 exploded.millisecond = 0; | 36 exploded.millisecond = 0; |
| 37 | 37 |
| 38 return Time::FromLocalExploded(exploded); | 38 return Time::FromLocalExploded(exploded); |
| 39 } | 39 } |
| 40 | 40 |
| 41 // Returns the boundary value for comparing against the FieldTrial's added | |
| 42 // groups for a given |divisor| (total probability) and |entropy_value|. | |
| 43 FieldTrial::Probability GetGroupBoundaryValue( | |
| 44 FieldTrial::Probability divisor, | |
| 45 double entropy_value) { | |
| 46 // Add a tiny epsilon value to get consistent results when converting floating | |
| 47 // 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
| |
| 48 // | |
| 49 // static_cast<FieldTrial::Probability>(100 * 0.56) == 56 | |
| 50 // static_cast<FieldTrial::Probability>(100 * 0.57) == 56 | |
| 51 // static_cast<FieldTrial::Probability>(100 * 0.58) == 57 | |
| 52 // static_cast<FieldTrial::Probability>(100 * 0.59) == 59 | |
| 53 const double kEpsilon = 1e-8; | |
| 54 return static_cast<FieldTrial::Probability>(divisor * entropy_value + | |
| 55 kEpsilon); | |
| 56 } | |
| 57 | |
| 41 } // namespace | 58 } // namespace |
| 42 | 59 |
| 43 static const char kHistogramFieldTrialSeparator('_'); | |
| 44 | |
| 45 // statics | 60 // statics |
| 46 const int FieldTrial::kNotFinalized = -1; | 61 const int FieldTrial::kNotFinalized = -1; |
| 47 const int FieldTrial::kDefaultGroupNumber = 0; | 62 const int FieldTrial::kDefaultGroupNumber = 0; |
| 48 bool FieldTrial::enable_benchmarking_ = false; | 63 bool FieldTrial::enable_benchmarking_ = false; |
| 49 | 64 |
| 50 const char FieldTrialList::kPersistentStringSeparator('/'); | 65 const char FieldTrialList::kPersistentStringSeparator('/'); |
| 51 int FieldTrialList::kNoExpirationYear = 0; | 66 int FieldTrialList::kNoExpirationYear = 0; |
| 52 | 67 |
| 53 //------------------------------------------------------------------------------ | 68 //------------------------------------------------------------------------------ |
| 54 // FieldTrial methods and members. | 69 // FieldTrial methods and members. |
| 55 | 70 |
| 56 FieldTrial::FieldTrial(const std::string& trial_name, | 71 FieldTrial::FieldTrial(const std::string& trial_name, |
| 57 const Probability total_probability, | 72 const Probability total_probability, |
| 58 const std::string& default_group_name, | 73 const std::string& default_group_name, |
| 59 double entropy_value) | 74 double entropy_value) |
| 60 : trial_name_(trial_name), | 75 : trial_name_(trial_name), |
| 61 divisor_(total_probability), | 76 divisor_(total_probability), |
| 62 default_group_name_(default_group_name), | 77 default_group_name_(default_group_name), |
| 63 random_(static_cast<Probability>(divisor_ * entropy_value)), | 78 random_(GetGroupBoundaryValue(total_probability, entropy_value)), |
| 64 accumulated_group_probability_(0), | 79 accumulated_group_probability_(0), |
| 65 next_group_number_(kDefaultGroupNumber + 1), | 80 next_group_number_(kDefaultGroupNumber + 1), |
| 66 group_(kNotFinalized), | 81 group_(kNotFinalized), |
| 67 enable_field_trial_(true), | 82 enable_field_trial_(true), |
| 68 forced_(false), | 83 forced_(false), |
| 69 group_reported_(false) { | 84 group_reported_(false) { |
| 70 DCHECK_GT(total_probability, 0); | 85 DCHECK_GT(total_probability, 0); |
| 71 DCHECK(!trial_name_.empty()); | 86 DCHECK(!trial_name_.empty()); |
| 72 DCHECK(!default_group_name_.empty()); | 87 DCHECK(!default_group_name_.empty()); |
| 73 } | 88 } |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 used_without_global_ = true; | 503 used_without_global_ = true; |
| 489 return; | 504 return; |
| 490 } | 505 } |
| 491 AutoLock auto_lock(global_->lock_); | 506 AutoLock auto_lock(global_->lock_); |
| 492 DCHECK(!global_->PreLockedFind(trial->trial_name())); | 507 DCHECK(!global_->PreLockedFind(trial->trial_name())); |
| 493 trial->AddRef(); | 508 trial->AddRef(); |
| 494 global_->registered_[trial->trial_name()] = trial; | 509 global_->registered_[trial->trial_name()] = trial; |
| 495 } | 510 } |
| 496 | 511 |
| 497 } // namespace base | 512 } // namespace base |
| OLD | NEW |