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

Unified Diff: base/metrics/histogram_persistence.cc

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: addressed final review comments by Alexei Created 4 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/metrics/histogram_samples.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_persistence.cc
diff --git a/base/metrics/histogram_persistence.cc b/base/metrics/histogram_persistence.cc
index 535d11409276ea117357676c64061ca7c3eb3f7b..bd250ec888a62a1998a4e762576b6bac388408b2 100644
--- a/base/metrics/histogram_persistence.cc
+++ b/base/metrics/histogram_persistence.cc
@@ -53,6 +53,9 @@ enum CreateHistogramResultType {
CREATE_HISTOGRAM_MAX
};
+// Name of histogram for storing results of local operations.
+const char kResultHistogram[] = "UMA.CreatePersistentHistogram.Result";
+
// Type identifiers used when storing in persistent memory so they can be
// identified during extraction; the first 4 bytes of the SHA1 of the name
// is used as a unique integer. A "version number" is added to the base
@@ -159,8 +162,7 @@ HistogramBase* GetCreateHistogramResultHistogram() {
}
histogram_pointer = LinearHistogram::FactoryGet(
- "UMA.CreatePersistentHistogram.Result",
- 1, CREATE_HISTOGRAM_MAX, CREATE_HISTOGRAM_MAX + 1,
+ kResultHistogram, 1, CREATE_HISTOGRAM_MAX, CREATE_HISTOGRAM_MAX + 1,
HistogramBase::kUmaTargetedHistogramFlag);
base::subtle::Release_Store(
&atomic_histogram_pointer,
@@ -210,6 +212,15 @@ ReleasePersistentHistogramMemoryAllocatorForTesting() {
ref, kTypeIdHistogram);
DCHECK(histogram_data);
StatisticsRecorder::ForgetHistogramForTesting(histogram_data->name);
+
+ // If a test breaks here then a memory region containing a histogram
+ // actively used by this code is being released back to the test.
+ // If that memory segment were to be deleted, future calls to create
+ // persistent histograms would crash. To avoid this, have the test call
+ // the method GetCreateHistogramResultHistogram() *before* setting the
+ // (temporary) memory allocator via SetPersistentMemoryAllocator() so
+ // that the histogram is instead allocated from the process heap.
+ DCHECK_NE(kResultHistogram, histogram_data->name);
}
}
@@ -480,7 +491,7 @@ HistogramBase* AllocatePersistentHistogram(
void ImportPersistentHistograms() {
// The lock protects against concurrent access to the iterator and is created
// in a thread-safe manner when needed.
- static base::LazyInstance<base::Lock> lock = LAZY_INSTANCE_INITIALIZER;
+ static base::LazyInstance<base::Lock>::Leaky lock = LAZY_INSTANCE_INITIALIZER;
if (g_allocator) {
base::AutoLock auto_lock(lock.Get());
@@ -492,7 +503,7 @@ void ImportPersistentHistograms() {
if (iter.is_clear())
g_allocator->CreateIterator(&iter);
- for (;;) {
+ while (true) {
HistogramBase* histogram = GetNextPersistentHistogram(g_allocator, &iter);
if (!histogram)
break;
« no previous file with comments | « no previous file | base/metrics/histogram_samples.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698