Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/persistent_histogram_allocator.h" | 5 #include "base/metrics/persistent_histogram_allocator.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
|
grt (UTC plus 2)
2016/04/01 14:22:48
remove these two -- already included in .h
bcwhite
2016/04/01 16:50:26
Done.
| |
| 10 #include "base/memory/shared_memory.h" | |
| 10 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
|
grt (UTC plus 2)
2016/04/01 14:22:48
remove this -- already included in .h
bcwhite
2016/04/01 16:50:26
Done.
| |
| 12 #include "base/metrics/histogram_samples.h" | 13 #include "base/metrics/histogram_samples.h" |
| 13 #include "base/metrics/sparse_histogram.h" | 14 #include "base/metrics/sparse_histogram.h" |
| 14 #include "base/metrics/statistics_recorder.h" | 15 #include "base/metrics/statistics_recorder.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 | 17 |
| 17 // TODO(bcwhite): Order these methods to match the header file. The current | 18 // TODO(bcwhite): Order these methods to match the header file. The current |
| 18 // order is only temporary in order to aid review of the transition from | 19 // order is only temporary in order to aid review of the transition from |
| 19 // a non-class implementation. | 20 // a non-class implementation. |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 void PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( | 249 void PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( |
| 249 size_t size, | 250 size_t size, |
| 250 uint64_t id, | 251 uint64_t id, |
| 251 StringPiece name) { | 252 StringPiece name) { |
| 252 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( | 253 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( |
| 253 make_scoped_ptr(new LocalPersistentMemoryAllocator(size, id, name))))); | 254 make_scoped_ptr(new LocalPersistentMemoryAllocator(size, id, name))))); |
| 254 } | 255 } |
| 255 | 256 |
| 256 // static | 257 // static |
| 257 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemory( | 258 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemory( |
| 259 scoped_ptr<SharedMemory> memory, | |
| 258 size_t size, | 260 size_t size, |
| 259 const SharedMemoryHandle& handle) { | 261 uint64_t id, |
| 262 StringPiece name) { | |
| 263 if (!memory->memory() && !memory->Map(size)) | |
| 264 NOTREACHED(); | |
| 265 | |
| 266 if (memory->memory()) { | |
| 267 DCHECK_LE(memory->mapped_size(), size); | |
| 268 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( | |
| 269 make_scoped_ptr(new SharedPersistentMemoryAllocator( | |
| 270 std::move(memory), id, name, /*readonly=*/false))))); | |
| 271 } | |
| 272 } | |
| 273 | |
| 274 // static | |
| 275 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemoryHandle( | |
| 276 const SharedMemoryHandle& handle, | |
| 277 size_t size) { | |
| 260 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false)); | 278 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false)); |
|
grt (UTC plus 2)
2016/04/01 14:22:48
iiuc, this effectively takes ownership of |handle|
bcwhite
2016/04/01 16:50:26
The passing convention matches that of the SharedM
| |
| 261 if (!shm->Map(size)) { | 279 if (!shm->Map(size)) { |
| 262 NOTREACHED(); | 280 NOTREACHED(); |
| 263 return; | 281 return; |
| 264 } | 282 } |
| 265 | 283 |
| 284 DCHECK_LE(shm->mapped_size(), size); | |
| 266 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( | 285 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( |
| 267 make_scoped_ptr(new SharedPersistentMemoryAllocator( | 286 make_scoped_ptr(new SharedPersistentMemoryAllocator( |
| 268 std::move(shm), 0, StringPiece(), /*readonly=*/false))))); | 287 std::move(shm), 0, StringPiece(), /*readonly=*/false))))); |
| 269 } | 288 } |
| 270 | 289 |
| 271 // static | 290 // static |
| 272 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram( | 291 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram( |
| 273 PersistentHistogramData* histogram_data_ptr) { | 292 PersistentHistogramData* histogram_data_ptr) { |
| 274 if (!histogram_data_ptr) { | 293 if (!histogram_data_ptr) { |
| 275 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER); | 294 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 scoped_ptr<HistogramBase> histogram = | 597 scoped_ptr<HistogramBase> histogram = |
| 579 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); | 598 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); |
| 580 if (!histogram) | 599 if (!histogram) |
| 581 break; | 600 break; |
| 582 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); | 601 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); |
| 583 } | 602 } |
| 584 } | 603 } |
| 585 } | 604 } |
| 586 | 605 |
| 587 } // namespace base | 606 } // namespace base |
| OLD | NEW |