ART: Hide mutex in TimingLogger
Ensure that timing_logger.h does not pull in mutex.h.
Bug: 119869270
Test: m test-art-host
Change-Id: I84b92dbc435a3f273f3dc519bbf7948220636c2f
diff --git a/runtime/base/timing_logger.cc b/runtime/base/timing_logger.cc
index 23ec3e1..0a4cddd 100644
--- a/runtime/base/timing_logger.cc
+++ b/runtime/base/timing_logger.cc
@@ -21,6 +21,7 @@
#include <android-base/logging.h>
#include "base/histogram-inl.h"
+#include "base/mutex.h"
#include "base/stl_util.h"
#include "base/systrace.h"
#include "base/time_utils.h"
@@ -40,7 +41,7 @@
CumulativeLogger::CumulativeLogger(const std::string& name)
: name_(name),
lock_name_("CumulativeLoggerLock" + name),
- lock_(lock_name_.c_str(), kDefaultMutexLevel, true) {
+ lock_(new Mutex(lock_name_.c_str(), kDefaultMutexLevel, true)) {
Reset();
}
@@ -49,7 +50,7 @@
}
void CumulativeLogger::SetName(const std::string& name) {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
name_.assign(name);
}
@@ -57,19 +58,19 @@
}
void CumulativeLogger::End() {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
++iterations_;
}
void CumulativeLogger::Reset() {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
iterations_ = 0;
total_time_ = 0;
STLDeleteElements(&histograms_);
}
void CumulativeLogger::AddLogger(const TimingLogger &logger) {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
TimingLogger::TimingData timing_data(logger.CalculateTimingData());
const std::vector<TimingLogger::Timing>& timings = logger.GetTimings();
for (size_t i = 0; i < timings.size(); ++i) {
@@ -81,12 +82,12 @@
}
size_t CumulativeLogger::GetIterations() const {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
return iterations_;
}
void CumulativeLogger::Dump(std::ostream &os) const {
- MutexLock mu(Thread::Current(), lock_);
+ MutexLock mu(Thread::Current(), *GetLock());
DumpHistogram(os);
}
diff --git a/runtime/base/timing_logger.h b/runtime/base/timing_logger.h
index a8a6701..974a14d 100644
--- a/runtime/base/timing_logger.h
+++ b/runtime/base/timing_logger.h
@@ -18,10 +18,11 @@
#define ART_RUNTIME_BASE_TIMING_LOGGER_H_
#include "base/histogram.h"
+#include "base/locks.h"
#include "base/macros.h"
-#include "base/mutex.h"
#include "base/time_utils.h"
+#include <memory>
#include <set>
#include <string>
#include <vector>
@@ -34,17 +35,17 @@
explicit CumulativeLogger(const std::string& name);
~CumulativeLogger();
void Start();
- void End() REQUIRES(!lock_);
- void Reset() REQUIRES(!lock_);
- void Dump(std::ostream& os) const REQUIRES(!lock_);
+ void End() REQUIRES(!GetLock());
+ void Reset() REQUIRES(!GetLock());
+ void Dump(std::ostream& os) const REQUIRES(!GetLock());
uint64_t GetTotalNs() const {
return GetTotalTime() * kAdjust;
}
// Allow the name to be modified, particularly when the cumulative logger is a field within a
// parent class that is unable to determine the "name" of a sub-class.
- void SetName(const std::string& name) REQUIRES(!lock_);
- void AddLogger(const TimingLogger& logger) REQUIRES(!lock_);
- size_t GetIterations() const REQUIRES(!lock_);
+ void SetName(const std::string& name) REQUIRES(!GetLock());
+ void AddLogger(const TimingLogger& logger) REQUIRES(!GetLock());
+ size_t GetIterations() const REQUIRES(!GetLock());
private:
class HistogramComparator {
@@ -58,18 +59,22 @@
static constexpr size_t kDefaultBucketCount = 100;
static constexpr size_t kInitialBucketSize = 50; // 50 microseconds.
- void AddPair(const std::string &label, uint64_t delta_time)
- REQUIRES(lock_);
- void DumpHistogram(std::ostream &os) const REQUIRES(lock_);
+ void AddPair(const std::string &label, uint64_t delta_time) REQUIRES(GetLock());
+ void DumpHistogram(std::ostream &os) const REQUIRES(GetLock());
uint64_t GetTotalTime() const {
return total_time_;
}
+
+ Mutex* GetLock() const {
+ return lock_.get();
+ }
+
static const uint64_t kAdjust = 1000;
- std::set<Histogram<uint64_t>*, HistogramComparator> histograms_ GUARDED_BY(lock_);
+ std::set<Histogram<uint64_t>*, HistogramComparator> histograms_ GUARDED_BY(GetLock());
std::string name_;
const std::string lock_name_;
- mutable Mutex lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
- size_t iterations_ GUARDED_BY(lock_);
+ mutable std::unique_ptr<Mutex> lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
+ size_t iterations_ GUARDED_BY(GetLock());
uint64_t total_time_;
DISALLOW_COPY_AND_ASSIGN(CumulativeLogger);