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

Unified Diff: base/metrics/histogram_persistence.h

Issue 1425533011: Support "shared" histograms between processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shmem-alloc
Patch Set: addressed review comments by Alexei Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: base/metrics/histogram_persistence.h
diff --git a/base/metrics/histogram_persistence.h b/base/metrics/histogram_persistence.h
new file mode 100644
index 0000000000000000000000000000000000000000..d07f28c7324832d458ad47b7fc70fd0b510e8282
--- /dev/null
+++ b/base/metrics/histogram_persistence.h
@@ -0,0 +1,93 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
+#define BASE_METRICS_HISTOGRAM_PERSISTENCE_H_
+
+#include "base/base_export.h"
+#include "base/feature_list.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/metrics/histogram_base.h"
+#include "base/metrics/persistent_memory_allocator.h"
+
+namespace base {
+
+struct PersistentHistogramData;
+
+extern scoped_ptr<PersistentMemoryAllocator> allocator_;
+BASE_EXPORT extern const Feature kPersistentHistogramsFeature;
+
+// Access a PersistentMemoryAllocator for storing histograms in space that
+// can be persisted or shared between processes. There is only ever one
+// allocator for all such histograms created by a single process though one
+// process may access the histograms created by other processes if it has a
+// handle on its memory segment. This takes ownership of the object and
+// should not be changed without great care as it is likely that there will
+// be pointers to data held in that space.
+BASE_EXPORT void SetPersistentHistogramMemoryAllocator(
+ PersistentMemoryAllocator* a);
+BASE_EXPORT PersistentMemoryAllocator* GetPersistentHistogramMemoryAllocator();
+
+// This access to the persistent allocator is only for testing; it extracts
+// the current allocator completely. This allows easy creation of histograms
+// within persistent memory segments which can then be extracted and used
+// in other ways.
+BASE_EXPORT PersistentMemoryAllocator*
+ReleasePersistentHistogramMemoryAllocator();
+
+// Recreate a Histogram from data held in persistent memory. Though this
+// object will be local to the current process, the sample data will be
+// shared with all other threads referencing it. This method takes a |ref|
+// to the top- level histogram data and the |allocator| on which it is found.
+// This method will return nullptr if any problem is detected with the data.
+// The |allocator| may or may not be the same as the PersistentMemoryAllocator
+// set for general use so that this method can be used to extract Histograms
+// from persistent memory segments other than the default place that this
+// process is creating its own histograms. The caller must take ownership of
+// the returned object and destroy it when no longer needed.
+BASE_EXPORT HistogramBase* GetPersistentHistogram(
+ PersistentMemoryAllocator* allocator,
+ int32_t ref);
+
+// Get the next histogram in persistent data based on iterator. The caller
+// must take ownership of the returned object and destroy it when no longer
+// needed.
+BASE_EXPORT HistogramBase* GetNextPersistentHistogram(
+ PersistentMemoryAllocator* allocator,
+ PersistentMemoryAllocator::Iterator* iter);
+
+// Create a histogram based on persistent data.
+BASE_EXPORT HistogramBase* CreatePersistentHistogram(
+ PersistentMemoryAllocator* allocator,
+ PersistentHistogramData* histogram_data);
+
+// Finalize the creation of the histogram, making it available to other
+// processes if it is the registered instance.
+void FinalizePersistentHistogram(PersistentMemoryAllocator::Reference ref,
+ bool register);
Alexei Svitkine (slow) 2016/01/08 18:52:48 Nit: codereview is highlighting "register" because
bcwhite 2016/01/12 16:34:57 Done.
+
+// Allocate a new persistent histogram. This does *not* make the object
+// iterable in the allocator; call MakeIterable(ref) directly if that is
+// desired.
+BASE_EXPORT HistogramBase* AllocatePersistentHistogram(
+ PersistentMemoryAllocator* allocator,
+ HistogramType histogram_type,
+ const std::string& name,
+ int minimum,
+ int maximum,
+ const BucketRanges* bucket_ranges,
+ int32 flags,
+ PersistentMemoryAllocator::Reference* ref_ptr);
+
+// Import new histograms from attached PersistentMemoryAllocator. It's
+// possible for other processes to create histograms in the attached memory
+// segment; this adds those to the internal list of known histograms to
+// avoid creating duplicates that would have to merged during reporting.
+// Every call to this method resumes from the last entry it saw so it costs
+// nothing if nothing new has been added.
+void ImportPersistentHistograms();
+
+} // namespace base
+
+#endif // BASE_METRICS_HISTOGRAM_PERSISTENCE_H_

Powered by Google App Engine
This is Rietveld 408576698