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

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

Issue 1671933002: Create and pass shared-histogram-allocator from browser to renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hsm-merge
Patch Set: rebased (use new PersistentHistogramAllocator) Created 4 years, 8 months 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
OLDNEW
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"
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"
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.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()) {
264 if (!memory->Map(size))
Alexei Svitkine (slow) 2016/03/29 17:51:24 Nit: Combine with the above if and then remove {}'
bcwhite 2016/03/30 21:25:55 Done.
265 NOTREACHED();
266 }
267
268 if (memory->memory()) {
269 DCHECK_LE(memory->mapped_size(), size);
270 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator(
271 make_scoped_ptr(new SharedPersistentMemoryAllocator(
272 std::move(memory), id, name, /*readonly=*/false)))));
273 }
274 }
275
276 // static
277 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemoryHandle(
278 const SharedMemoryHandle& handle,
279 size_t size) {
260 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false)); 280 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false));
261 if (!shm->Map(size)) { 281 if (!shm->Map(size)) {
262 NOTREACHED(); 282 NOTREACHED();
263 return; 283 return;
264 } 284 }
265 285
286 DCHECK_LE(shm->mapped_size(), size);
266 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( 287 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator(
267 make_scoped_ptr(new SharedPersistentMemoryAllocator( 288 make_scoped_ptr(new SharedPersistentMemoryAllocator(
268 std::move(shm), 0, StringPiece(), /*readonly=*/false))))); 289 std::move(shm), 0, StringPiece(), /*readonly=*/false)))));
269 } 290 }
270 291
271 // static 292 // static
272 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram( 293 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram(
273 PersistentHistogramData* histogram_data_ptr) { 294 PersistentHistogramData* histogram_data_ptr) {
274 if (!histogram_data_ptr) { 295 if (!histogram_data_ptr) {
275 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER); 296 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 scoped_ptr<HistogramBase> histogram = 599 scoped_ptr<HistogramBase> histogram =
579 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); 600 g_allocator->GetNextHistogramWithIgnore(&iter, last_created);
580 if (!histogram) 601 if (!histogram)
581 break; 602 break;
582 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); 603 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release());
583 } 604 }
584 } 605 }
585 } 606 }
586 607
587 } // namespace base 608 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698