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

Side by Side Diff: base/metrics/histogram_persistence.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: cleanup on RenderProcessHostDestroyed instead of RenderProcessExited; use existing ScopedObserver c… Created 4 years, 9 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/histogram_persistence.h" 5 #include "base/metrics/histogram_persistence.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/statistics_recorder.h" 14 #include "base/metrics/statistics_recorder.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 16
16 namespace base { 17 namespace base {
17 18
18 namespace { 19 namespace {
19 20
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 183
183 void SetPersistentHistogramMemoryAllocator( 184 void SetPersistentHistogramMemoryAllocator(
184 PersistentMemoryAllocator* allocator) { 185 PersistentMemoryAllocator* allocator) {
185 // Releasing or changing an allocator is extremely dangerous because it 186 // Releasing or changing an allocator is extremely dangerous because it
186 // likely has histograms stored within it. If the backing memory is also 187 // likely has histograms stored within it. If the backing memory is also
187 // also released, future accesses to those histograms will seg-fault. 188 // also released, future accesses to those histograms will seg-fault.
188 CHECK(!g_allocator); 189 CHECK(!g_allocator);
189 g_allocator = allocator; 190 g_allocator = allocator;
190 } 191 }
191 192
193 SharedPersistentMemoryAllocator* CreateSharedPersistentHistogramMemoryAllocator(
194 size_t size,
195 StringPiece name,
196 uint64_t id) {
197 scoped_ptr<SharedMemory> shm(new SharedMemory());
198 shm->CreateAndMapAnonymous(size);
199 return new SharedPersistentMemoryAllocator(std::move(shm), id, name, false);
200 }
201
202 SharedPersistentMemoryAllocator* CreateSharedPersistentHistogramMemoryAllocator(
203 size_t size,
204 const SharedMemoryHandle& handle,
205 bool readonly) {
206 scoped_ptr<SharedMemory> shm(new SharedMemory(handle, readonly));
207 if (!shm->Map(size)) {
208 NOTREACHED();
209 return nullptr;
210 }
211 return new SharedPersistentMemoryAllocator(std::move(shm), 0, StringPiece(),
212 readonly);
213 }
214
192 PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator() { 215 PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator() {
193 return g_allocator; 216 return g_allocator;
194 } 217 }
195 218
196 PersistentMemoryAllocator* 219 PersistentMemoryAllocator*
197 ReleasePersistentHistogramMemoryAllocatorForTesting() { 220 ReleasePersistentHistogramMemoryAllocatorForTesting() {
198 PersistentMemoryAllocator* allocator = g_allocator; 221 PersistentMemoryAllocator* allocator = g_allocator;
199 if (!allocator) 222 if (!allocator)
200 return nullptr; 223 return nullptr;
201 224
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 while (true) { 530 while (true) {
508 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter); 531 HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter);
509 if (!histogram) 532 if (!histogram)
510 break; 533 break;
511 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram); 534 StatisticsRecorder::RegisterOrDeleteDuplicate(histogram);
512 } 535 }
513 } 536 }
514 } 537 }
515 538
516 } // namespace base 539 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698