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

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

Issue 2517193003: Fix adding duplicate trials to allocator (finally) (Closed)
Patch Set: address nit Created 4 years, 1 month 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
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
(...skipping 20 matching lines...) Expand all
31 const char kPersistentStringSeparator = '/'; // Currently a slash. 31 const char kPersistentStringSeparator = '/'; // Currently a slash.
32 32
33 // Define a marker character to be used as a prefix to a trial name on the 33 // Define a marker character to be used as a prefix to a trial name on the
34 // command line which forces its activation. 34 // command line which forces its activation.
35 const char kActivationMarker = '*'; 35 const char kActivationMarker = '*';
36 36
37 // Use shared memory to communicate field trial (experiment) state. Set to false 37 // Use shared memory to communicate field trial (experiment) state. Set to false
38 // for now while the implementation is fleshed out (e.g. data format, single 38 // for now while the implementation is fleshed out (e.g. data format, single
39 // shared memory segment). See https://codereview.chromium.org/2365273004/ and 39 // shared memory segment). See https://codereview.chromium.org/2365273004/ and
40 // crbug.com/653874 40 // crbug.com/653874
41 const bool kUseSharedMemoryForFieldTrials = false; 41 const bool kUseSharedMemoryForFieldTrials = false;
Alexei Svitkine (slow) 2016/11/21 19:20:10 This probably conflict with your other CL that fli
42 42
43 // Constants for the field trial allocator. 43 // Constants for the field trial allocator.
44 const char kAllocatorName[] = "FieldTrialAllocator"; 44 const char kAllocatorName[] = "FieldTrialAllocator";
45 const uint32_t kFieldTrialType = 0xABA17E13 + 2; // SHA1(FieldTrialEntry) v2 45 const uint32_t kFieldTrialType = 0xABA17E13 + 2; // SHA1(FieldTrialEntry) v2
46 46
47 // We allocate 64 KiB to hold all the field trial data. This should be enough, 47 // We allocate 64 KiB to hold all the field trial data. This should be enough,
48 // as currently we use ~8KiB for the field trials, and ~10KiB for experiment 48 // as currently we use ~8KiB for the field trials, and ~10KiB for experiment
49 // parameters (as of 9/11/2016). This also doesn't allocate all 64 KiB at once 49 // parameters (as of 9/11/2016). This also doesn't allocate all 64 KiB at once
50 // -- the pages only get mapped to physical memory when they are touched. If the 50 // -- the pages only get mapped to physical memory when they are touched. If the
51 // size of the allocated field trials does get larger than 64 KiB, then we will 51 // size of the allocated field trials does get larger than 64 KiB, then we will
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 void FieldTrial::FinalizeGroupChoiceImpl(bool is_locked) { 355 void FieldTrial::FinalizeGroupChoiceImpl(bool is_locked) {
356 if (group_ != kNotFinalized) 356 if (group_ != kNotFinalized)
357 return; 357 return;
358 accumulated_group_probability_ = divisor_; 358 accumulated_group_probability_ = divisor_;
359 // Here it's OK to use |kDefaultGroupNumber| since we can't be forced and not 359 // Here it's OK to use |kDefaultGroupNumber| since we can't be forced and not
360 // finalized. 360 // finalized.
361 DCHECK(!forced_); 361 DCHECK(!forced_);
362 SetGroupChoice(default_group_name_, kDefaultGroupNumber); 362 SetGroupChoice(default_group_name_, kDefaultGroupNumber);
363 363
364 // Add the field trial to shared memory. 364 // Add the field trial to shared memory.
365 if (kUseSharedMemoryForFieldTrials) 365 if (kUseSharedMemoryForFieldTrials && trial_registered_)
366 FieldTrialList::OnGroupFinalized(is_locked, this); 366 FieldTrialList::OnGroupFinalized(is_locked, this);
367 } 367 }
368 368
369 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const { 369 bool FieldTrial::GetActiveGroup(ActiveGroup* active_group) const {
370 if (!group_reported_ || !enable_field_trial_) 370 if (!group_reported_ || !enable_field_trial_)
371 return false; 371 return false;
372 DCHECK_NE(group_, kNotFinalized); 372 DCHECK_NE(group_, kNotFinalized);
373 active_group->trial_name = trial_name_; 373 active_group->trial_name = trial_name_;
374 active_group->group_name = group_name_; 374 active_group->group_name = group_name_;
375 return true; 375 return true;
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 return; 1010 return;
1011 } 1011 }
1012 AutoLock auto_lock(global_->lock_); 1012 AutoLock auto_lock(global_->lock_);
1013 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); 1013 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name();
1014 trial->AddRef(); 1014 trial->AddRef();
1015 trial->SetTrialRegistered(); 1015 trial->SetTrialRegistered();
1016 global_->registered_[trial->trial_name()] = trial; 1016 global_->registered_[trial->trial_name()] = trial;
1017 } 1017 }
1018 1018
1019 } // namespace base 1019 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/field_trial.h ('k') | base/metrics/field_trial_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698