Fixes for timing logger and histogram.
Reorder when the index is checked in Percentile to avoid reading from a
negative index.
Add missing copyright to histogram unit test.
Switch histogram test to use UniquePtr rather than new/delete (MeanTest had
missed the delete).
Make timing/cumulative logger fields that can be const const. Document SetName
for cumulative logger. Place the cumulative logger's std::string lock name in
the cumulative logger so its lifespan is clearly the same.
Change-Id: I4056c6b6ee8efdb73f7b10f690fc9d959fd4a569
diff --git a/src/base/timing_logger.cc b/src/base/timing_logger.cc
index d2c7eef..6d5586c 100644
--- a/src/base/timing_logger.cc
+++ b/src/base/timing_logger.cc
@@ -70,15 +70,20 @@
os << name_ << ": end, " << NsToMs(GetTotalNs()) << " ms\n";
}
-CumulativeLogger::CumulativeLogger(const std::string &name)
+CumulativeLogger::CumulativeLogger(const std::string& name)
: name_(name),
- lock_(("CumulativeLoggerLock" + name).c_str(), kDefaultMutexLevel, true) {
+ lock_name_("CumulativeLoggerLock" + name),
+ lock_(lock_name_.c_str(), kDefaultMutexLevel, true) {
Reset();
}
-CumulativeLogger::~CumulativeLogger() { STLDeleteElements(&histograms_); }
+CumulativeLogger::~CumulativeLogger() {
+ STLDeleteElements(&histograms_);
+}
-void CumulativeLogger::SetName(const std::string &name) { name_ = name; }
+void CumulativeLogger::SetName(const std::string& name) {
+ name_ = name;
+}
void CumulativeLogger::Start() {
MutexLock mu(Thread::Current(), lock_);