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 <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 24 matching lines...) Expand all Loading... | |
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; |
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 + 1; // SHA1(FieldTrialEntry) v1 | 45 const uint32_t kFieldTrialType = 0xABA17E13 + 1; // SHA1(FieldTrialEntry) v1 |
bcwhite
2016/11/08 20:30:02
Blank line after.
lawrencewu
2016/11/09 18:06:46
Done.
| |
46 // We allocate 64 KiB to hold all the field trial data. This should be enough, | |
bcwhite
2016/11/08 20:30:02
Include the date when this was true. Also, commen
lawrencewu
2016/11/09 18:06:46
Done.
| |
47 // as currently we use ~8KiB for the field trials, and ~10KiB for experiment | |
48 // parameters. This also doesn't allocate all 64 KiB at once -- the pages only | |
49 // get mapped to physical memory when they are touched. | |
46 #if !defined(OS_NACL) | 50 #if !defined(OS_NACL) |
47 const size_t kFieldTrialAllocationSize = 4 << 10; // 4 KiB = one page | 51 const size_t kFieldTrialAllocationSize = 4 << 14; |
bcwhite
2016/11/08 20:14:32
Please do this as
64 << 10 // 64 KiB
lawrencewu
2016/11/09 18:06:46
Done.
| |
48 #endif | 52 #endif |
49 | 53 |
50 // We create one FieldTrialEntry per field trial in shared memory, via | 54 // We create one FieldTrialEntry per field trial in shared memory, via |
51 // AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a base::Pickle | 55 // AddToAllocatorWhileLocked. The FieldTrialEntry is followed by a base::Pickle |
52 // object that we unpickle and read from. | 56 // object that we unpickle and read from. |
bcwhite
2016/11/08 20:30:02
Comment that any changes to this structure require
lawrencewu
2016/11/09 18:06:46
Done.
| |
53 struct FieldTrialEntry { | 57 struct FieldTrialEntry { |
54 bool activated; | 58 bool activated; |
bcwhite
2016/11/08 20:30:02
This should be a fixed size (i.e. uint32_t) so tha
lawrencewu
2016/11/09 18:06:46
Done.
| |
55 | 59 |
56 // Size of the pickled structure, NOT the total size of this entry. | 60 // Size of the pickled structure, NOT the total size of this entry. |
57 uint32_t size; | 61 uint32_t size; |
58 | 62 |
59 // Calling this is only valid when the entry is initialized. That is, it | 63 // Calling this is only valid when the entry is initialized. That is, it |
60 // resides in shared memory and has a pickle containing the trial name and | 64 // resides in shared memory and has a pickle containing the trial name and |
61 // group name following it. | 65 // group name following it. |
62 bool GetTrialAndGroupName(StringPiece* trial_name, | 66 bool GetTrialAndGroupName(StringPiece* trial_name, |
63 StringPiece* group_name) const { | 67 StringPiece* group_name) const { |
64 char* src = reinterpret_cast<char*>(const_cast<FieldTrialEntry*>(this)) + | 68 char* src = reinterpret_cast<char*>(const_cast<FieldTrialEntry*>(this)) + |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
173 HANDLE CreateReadOnlyHandle(SharedPersistentMemoryAllocator* allocator) { | 177 HANDLE CreateReadOnlyHandle(SharedPersistentMemoryAllocator* allocator) { |
174 HANDLE src = allocator->shared_memory()->handle().GetHandle(); | 178 HANDLE src = allocator->shared_memory()->handle().GetHandle(); |
175 ProcessHandle process = GetCurrentProcess(); | 179 ProcessHandle process = GetCurrentProcess(); |
176 DWORD access = SECTION_MAP_READ | SECTION_QUERY; | 180 DWORD access = SECTION_MAP_READ | SECTION_QUERY; |
177 HANDLE dst; | 181 HANDLE dst; |
178 if (!::DuplicateHandle(process, src, process, &dst, access, true, 0)) | 182 if (!::DuplicateHandle(process, src, process, &dst, access, true, 0)) |
179 return nullptr; | 183 return nullptr; |
180 return dst; | 184 return dst; |
181 } | 185 } |
186 | |
187 void ReportFieldTrialAllocatorUsage( | |
bcwhite
2016/11/08 20:14:32
Don't need this.
lawrencewu
2016/11/09 18:06:46
Removed.
| |
188 SharedPersistentMemoryAllocator* allocator) { | |
189 size_t used = allocator->used(); | |
190 UMA_HISTOGRAM_COUNTS_100000("UMA.FieldTrialAllocator.Used", used); | |
191 int used_percent = used / kFieldTrialAllocationSize; | |
192 UMA_HISTOGRAM_PERCENTAGE("UMA.FieldTrialAllocator.UsedPct", | |
193 used_percent * 100); | |
194 } | |
182 #endif | 195 #endif |
183 | 196 |
184 } // namespace | 197 } // namespace |
185 | 198 |
186 // statics | 199 // statics |
187 const int FieldTrial::kNotFinalized = -1; | 200 const int FieldTrial::kNotFinalized = -1; |
188 const int FieldTrial::kDefaultGroupNumber = 0; | 201 const int FieldTrial::kDefaultGroupNumber = 0; |
189 bool FieldTrial::enable_benchmarking_ = false; | 202 bool FieldTrial::enable_benchmarking_ = false; |
190 | 203 |
191 int FieldTrialList::kNoExpirationYear = 0; | 204 int FieldTrialList::kNoExpirationYear = 0; |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 // command-line flag. The child process will do the reverse conversions to | 734 // command-line flag. The child process will do the reverse conversions to |
722 // retrieve the handle. See http://stackoverflow.com/a/153077 | 735 // retrieve the handle. See http://stackoverflow.com/a/153077 |
723 auto uintptr_handle = | 736 auto uintptr_handle = |
724 reinterpret_cast<uintptr_t>(global_->readonly_allocator_handle_); | 737 reinterpret_cast<uintptr_t>(global_->readonly_allocator_handle_); |
725 size_t field_trial_length = | 738 size_t field_trial_length = |
726 global_->field_trial_allocator_->shared_memory()->mapped_size(); | 739 global_->field_trial_allocator_->shared_memory()->mapped_size(); |
727 std::string field_trial_handle = std::to_string(uintptr_handle) + "," + | 740 std::string field_trial_handle = std::to_string(uintptr_handle) + "," + |
728 std::to_string(field_trial_length); | 741 std::to_string(field_trial_length); |
729 | 742 |
730 cmd_line->AppendSwitchASCII(field_trial_handle_switch, field_trial_handle); | 743 cmd_line->AppendSwitchASCII(field_trial_handle_switch, field_trial_handle); |
731 UMA_HISTOGRAM_COUNTS_10000("UMA.FieldTrialAllocator.Size", | 744 ReportFieldTrialAllocatorUsage(global_->field_trial_allocator_.get()); |
bcwhite
2016/11/08 20:14:32
When you create the allocator, call
allocator->Cr
lawrencewu
2016/11/09 18:06:46
Done. But this will get called on every subprocess
bcwhite
2016/11/09 18:57:37
Not ideal but acceptable. If you can call it once
lawrencewu
2016/11/09 19:15:00
Acknowledged.
| |
732 field_trial_length); | |
733 return; | 745 return; |
734 } | 746 } |
735 #endif | 747 #endif |
736 | 748 |
737 AddForceFieldTrialsFlag(cmd_line); | 749 AddForceFieldTrialsFlag(cmd_line); |
738 } | 750 } |
739 | 751 |
740 // static | 752 // static |
741 FieldTrial* FieldTrialList::CreateFieldTrial( | 753 FieldTrial* FieldTrialList::CreateFieldTrial( |
742 const std::string& name, | 754 const std::string& name, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
972 return; | 984 return; |
973 } | 985 } |
974 AutoLock auto_lock(global_->lock_); | 986 AutoLock auto_lock(global_->lock_); |
975 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); | 987 CHECK(!global_->PreLockedFind(trial->trial_name())) << trial->trial_name(); |
976 trial->AddRef(); | 988 trial->AddRef(); |
977 trial->SetTrialRegistered(); | 989 trial->SetTrialRegistered(); |
978 global_->registered_[trial->trial_name()] = trial; | 990 global_->registered_[trial->trial_name()] = trial; |
979 } | 991 } |
980 | 992 |
981 } // namespace base | 993 } // namespace base |
OLD | NEW |