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

Unified Diff: base/metrics/histogram_base.cc

Issue 2973863002: Remove std::string histogram name from HistogramBase object.
Patch Set: rebased Created 3 years, 4 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 | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_base_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/histogram_base.cc
diff --git a/base/metrics/histogram_base.cc b/base/metrics/histogram_base.cc
index 5e9de6f02a38435ec7db095776e9e1145f3d185c..0bb89a75f649c77c892ff0dfa67699bcc056f209 100644
--- a/base/metrics/histogram_base.cc
+++ b/base/metrics/histogram_base.cc
@@ -7,17 +7,21 @@
#include <limits.h>
#include <memory>
+#include <set>
#include <utility>
#include "base/json/json_string_value_serializer.h"
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/metrics/histogram.h"
+#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/sparse_histogram.h"
#include "base/metrics/statistics_recorder.h"
#include "base/pickle.h"
#include "base/process/process_handle.h"
#include "base/strings/stringprintf.h"
+#include "base/synchronization/lock.h"
#include "base/values.h"
namespace base {
@@ -63,14 +67,13 @@ HistogramBase* DeserializeHistogramInfo(PickleIterator* iter) {
const HistogramBase::Sample HistogramBase::kSampleType_MAX = INT_MAX;
HistogramBase* HistogramBase::report_histogram_ = nullptr;
-HistogramBase::HistogramBase(const std::string& name)
- : histogram_name_(name),
- flags_(kNoFlags) {}
+HistogramBase::HistogramBase(const char* name)
+ : histogram_name_(name), flags_(kNoFlags) {}
HistogramBase::~HistogramBase() {}
void HistogramBase::CheckName(const StringPiece& name) const {
- DCHECK_EQ(histogram_name(), name);
+ DCHECK_EQ(StringPiece(histogram_name()), name);
}
void HistogramBase::SetFlags(int32_t flags) {
@@ -190,6 +193,19 @@ void HistogramBase::WriteAsciiBucketValue(Count current,
}
// static
+char const* HistogramBase::GetPermanentName(const std::string& name) {
+ // A set of histogram names that provides the "permanent" lifetime required
+ // by histogram objects for those strings that are not already code constants
+ // or held in persistent memory.
+ static LazyInstance<std::set<std::string>>::Leaky permanent_names;
+ static LazyInstance<Lock>::Leaky permanent_names_lock;
+
+ AutoLock lock(permanent_names_lock.Get());
+ auto result = permanent_names.Get().insert(name);
+ return result.first->c_str();
+}
+
+// static
void HistogramBase::ReportHistogramActivity(const HistogramBase& histogram,
ReportActivity activity) {
if (!report_histogram_)
« no previous file with comments | « base/metrics/histogram_base.h ('k') | base/metrics/histogram_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698