-
Notifications
You must be signed in to change notification settings - Fork 0
/
044.patch
81 lines (74 loc) · 2.47 KB
/
044.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--- a/base/metrics/sparse_histogram.cc 2017-10-04 18:07:32.000000000 -0400
+++ b/base/metrics/sparse_histogram.cc 2017-10-08 20:11:37.671771593 -0400
@@ -24,7 +24,12 @@
// static
HistogramBase* SparseHistogram::FactoryGet(const std::string& name,
int32_t flags) {
- HistogramBase* histogram = StatisticsRecorder::FindHistogram(name);
+ const bool enabled_ = HistogramBase::MetricsEnabled();
+ std::string overridden_name = HistogramBase::kDummySparseName;
+ if (enabled_)
+ overridden_name = name;
+
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(overridden_name);
if (!histogram) {
// Try to create the histogram using a "persistent" allocator. As of
// 2016-02-25, the availability of such is controlled by a base::Feature
@@ -36,7 +41,7 @@
PersistentHistogramAllocator* allocator = GlobalHistogramAllocator::Get();
if (allocator) {
tentative_histogram = allocator->AllocateHistogram(
- SPARSE_HISTOGRAM, name, 0, 0, nullptr, flags, &histogram_ref);
+ SPARSE_HISTOGRAM, overridden_name, 0, 0, nullptr, flags, &histogram_ref);
}
// Handle the case where no persistent allocator is present or the
@@ -45,7 +50,7 @@
DCHECK(!histogram_ref); // Should never have been set.
DCHECK(!allocator); // Shouldn't have failed.
flags &= ~HistogramBase::kIsPersistent;
- tentative_histogram.reset(new SparseHistogram(name));
+ tentative_histogram.reset(new SparseHistogram(overridden_name));
tentative_histogram->SetFlags(flags);
}
@@ -68,6 +73,10 @@
ReportHistogramActivity(*histogram, HISTOGRAM_LOOKUP);
}
+ if (!enabled_)
+ return histogram;
+
+ histogram->enabled = true;
CHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType());
return histogram;
}
@@ -100,11 +109,17 @@
return false;
}
+ if (!enabled)
+ return;
+
void SparseHistogram::Add(Sample value) {
AddCount(value, 1);
}
void SparseHistogram::AddCount(Sample value, int count) {
+ if (!enabled)
+ return;
+
if (count <= 0) {
NOTREACHED();
return;
@@ -150,11 +165,17 @@
}
void SparseHistogram::AddSamples(const HistogramSamples& samples) {
+ if (!enabled)
+ return;
+
base::AutoLock auto_lock(lock_);
unlogged_samples_->Add(samples);
}
bool SparseHistogram::AddSamplesFromPickle(PickleIterator* iter) {
+ if (!enabled)
+ return;
+
base::AutoLock auto_lock(lock_);
return unlogged_samples_->AddFromPickle(iter);
}