[metrics] Add metrics to Runtime, implement ClassVerificationTotalTime
This creates the main metrics struct and makes it readily accessible for
ART components that want to start collecting metrics. It also implements
the ClassVerificationTime metric.
Test: m test-art-host-gtest-art_runtime_tests
Test: m test-art-host-gtest-art_libartbase_tests
Bug: 170149255
Change-Id: I33b5b2dd40127074619750d6730db220e3ed1257
diff --git a/libartbase/base/metrics.h b/libartbase/base/metrics.h
index d403834..f2852b4 100644
--- a/libartbase/base/metrics.h
+++ b/libartbase/base/metrics.h
@@ -33,7 +33,6 @@
// COUNTER(counter_name)
#define ART_COUNTERS(COUNTER) COUNTER(ClassVerificationTotalTime)
-// TODO: ClassVerificationTime serves as a mock for now. Implementation will come later.
// HISTOGRAM(counter_name, num_buckets, minimum_value, maximum_value)
//
@@ -248,13 +247,15 @@
start_time_microseconds_ = MicroTime();
}
- void Stop() {
+ // Stops a running timer. Returns the time elapsed since starting the timer in microseconds.
+ uint64_t Stop() {
DCHECK(running_);
uint64_t stop_time_microseconds = MicroTime();
running_ = false;
- metric_->Add(
- static_cast<typename Metric::value_t>(stop_time_microseconds - start_time_microseconds_));
+ uint64_t elapsed_time = stop_time_microseconds - start_time_microseconds_;
+ metric_->Add(static_cast<typename Metric::value_t>(elapsed_time));
+ return elapsed_time;
}
private: