Index: base/metrics/sparse_histogram.cc |
diff --git a/base/metrics/sparse_histogram.cc b/base/metrics/sparse_histogram.cc |
index c64f7cb1c649dff13de20a8a9ed04e3a320a1973..296c0179ab23ae279e541251843270bd1bc6c473 100644 |
--- a/base/metrics/sparse_histogram.cc |
+++ b/base/metrics/sparse_histogram.cc |
@@ -7,6 +7,7 @@ |
#include "base/metrics/sample_map.h" |
#include "base/metrics/statistics_recorder.h" |
#include "base/pickle.h" |
+#include "base/stringprintf.h" |
Ilya Sherman
2013/02/21 05:36:06
nit: Doesn't look like this is needed.
kaiwang
2013/02/27 04:39:42
Done.
|
#include "base/synchronization/lock.h" |
using std::map; |
@@ -19,9 +20,16 @@ typedef HistogramBase::Sample Sample; |
// static |
HistogramBase* SparseHistogram::FactoryGet(const string& name, int32 flags) { |
- // TODO(kaiwang): Register and get SparseHistogram with StatisticsRecorder. |
- HistogramBase* histogram = new SparseHistogram(name); |
- histogram->SetFlags(flags); |
+ HistogramBase* histogram = StatisticsRecorder::FindHistogram(name); |
+ |
+ if (!histogram) { |
+ // To avoid racy destruction at shutdown, the following will be leaked. |
+ HistogramBase* tentative_histogram = new SparseHistogram(name); |
+ tentative_histogram->SetFlags(flags); |
+ histogram = |
+ StatisticsRecorder::RegisterOrDeleteDuplicate(tentative_histogram); |
+ } |
+ CHECK_EQ(SPARSE_HISTOGRAM, histogram->GetHistogramType()); |
Ilya Sherman
2013/02/21 05:36:06
nit: DCHECK_EQ
kaiwang
2013/02/27 04:39:42
This is following histogram.h
Seems this kind of e
Ilya Sherman
2013/02/28 00:29:56
They shouldn't be. It would be good to fix histog
kaiwang
2013/02/28 04:58:05
Done.
|
return histogram; |
} |