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

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: addressed review comments by Greg 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"
10 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
11 #include "base/metrics/histogram_base.h"
12 #include "base/metrics/histogram_samples.h" 10 #include "base/metrics/histogram_samples.h"
13 #include "base/metrics/sparse_histogram.h" 11 #include "base/metrics/sparse_histogram.h"
14 #include "base/metrics/statistics_recorder.h" 12 #include "base/metrics/statistics_recorder.h"
15 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
16 14
17 // TODO(bcwhite): Order these methods to match the header file. The current 15 // 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 16 // order is only temporary in order to aid review of the transition from
19 // a non-class implementation. 17 // a non-class implementation.
20 18
21 namespace base { 19 namespace base {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 void PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory( 246 void PersistentHistogramAllocator::CreateGlobalAllocatorOnLocalMemory(
249 size_t size, 247 size_t size,
250 uint64_t id, 248 uint64_t id,
251 StringPiece name) { 249 StringPiece name) {
252 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( 250 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator(
253 make_scoped_ptr(new LocalPersistentMemoryAllocator(size, id, name))))); 251 make_scoped_ptr(new LocalPersistentMemoryAllocator(size, id, name)))));
254 } 252 }
255 253
256 // static 254 // static
257 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemory( 255 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemory(
256 scoped_ptr<SharedMemory> memory,
258 size_t size, 257 size_t size,
259 const SharedMemoryHandle& handle) { 258 uint64_t id,
259 StringPiece name) {
260 if (!memory->memory() && !memory->Map(size))
261 NOTREACHED();
262
263 if (memory->memory()) {
264 DCHECK_LE(memory->mapped_size(), size);
265 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator(
266 make_scoped_ptr(new SharedPersistentMemoryAllocator(
267 std::move(memory), id, name, /*readonly=*/false)))));
268 }
269 }
270
271 // static
272 void PersistentHistogramAllocator::CreateGlobalAllocatorOnSharedMemoryHandle(
273 const SharedMemoryHandle& handle,
274 size_t size) {
260 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false)); 275 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, /*readonly=*/false));
261 if (!shm->Map(size)) { 276 if (!shm->Map(size)) {
262 NOTREACHED(); 277 NOTREACHED();
263 return; 278 return;
264 } 279 }
265 280
281 DCHECK_LE(shm->mapped_size(), size);
266 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator( 282 SetGlobalAllocator(make_scoped_ptr(new PersistentHistogramAllocator(
267 make_scoped_ptr(new SharedPersistentMemoryAllocator( 283 make_scoped_ptr(new SharedPersistentMemoryAllocator(
268 std::move(shm), 0, StringPiece(), /*readonly=*/false))))); 284 std::move(shm), 0, StringPiece(), /*readonly=*/false)))));
269 } 285 }
270 286
271 // static 287 // static
272 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram( 288 scoped_ptr<HistogramBase> PersistentHistogramAllocator::CreateHistogram(
273 PersistentHistogramData* histogram_data_ptr) { 289 PersistentHistogramData* histogram_data_ptr) {
274 if (!histogram_data_ptr) { 290 if (!histogram_data_ptr) {
275 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER); 291 RecordCreateHistogramResult(CREATE_HISTOGRAM_INVALID_METADATA_POINTER);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 scoped_ptr<HistogramBase> histogram = 594 scoped_ptr<HistogramBase> histogram =
579 g_allocator->GetNextHistogramWithIgnore(&iter, last_created); 595 g_allocator->GetNextHistogramWithIgnore(&iter, last_created);
580 if (!histogram) 596 if (!histogram)
581 break; 597 break;
582 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release()); 598 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram.release());
583 } 599 }
584 } 600 }
585 } 601 }
586 602
587 } // namespace base 603 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698