From c560fc0b430816825add4125134b20eb791f6036 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Wed, 16 Jul 2014 09:57:39 -0700 Subject: [PATCH] ART: Report cputime in dex2oat Add ProcessCpuNanoTime. Log cputime in dex2oat completion message. Sample: dex2oat took 20.036s(64.843s cpu) (threads: 48) arena alloc=25MB (26760672B) java alloc=2MB (2311688B) native alloc=44MB (46792784B) free=35MB (37502896B) Test: m test-art-host Change-Id: I78646c4808c8205f7f8e7995a82a1ba63cd15298 --- dex2oat/dex2oat.cc | 6 +++++- runtime/base/time_utils.cc | 11 +++++++++++ runtime/base/time_utils.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc index 264be99fc..0edbd11fb 100644 --- a/dex2oat/dex2oat.cc +++ b/dex2oat/dex2oat.cc @@ -518,6 +518,7 @@ class Dex2Oat FINAL { runtime_(nullptr), thread_count_(sysconf(_SC_NPROCESSORS_CONF)), start_ns_(NanoTime()), + start_cputime_ns_(ProcessCpuNanoTime()), oat_fd_(-1), input_vdex_fd_(-1), output_vdex_fd_(-1), @@ -2595,7 +2596,9 @@ class Dex2Oat FINAL { // Note: when creation of a runtime fails, e.g., when trying to compile an app but when there // is no image, there won't be a Runtime::Current(). // Note: driver creation can fail when loading an invalid dex file. - LOG(INFO) << "dex2oat took " << PrettyDuration(NanoTime() - start_ns_) + LOG(INFO) << "dex2oat took " + << PrettyDuration(NanoTime() - start_ns_) + << "(" << PrettyDuration(ProcessCpuNanoTime() - start_cputime_ns_) << " cpu)" << " (threads: " << thread_count_ << ") " << ((Runtime::Current() != nullptr && driver_ != nullptr) ? driver_->GetMemoryUsageString(kIsDebugBuild || VLOG_IS_ON(compiler)) : @@ -2643,6 +2646,7 @@ class Dex2Oat FINAL { size_t thread_count_; uint64_t start_ns_; + uint64_t start_cputime_ns_; std::unique_ptr watchdog_; std::vector> oat_files_; std::vector> vdex_files_; diff --git a/runtime/base/time_utils.cc b/runtime/base/time_utils.cc index 3e5bac848..57f198d7e 100644 --- a/runtime/base/time_utils.cc +++ b/runtime/base/time_utils.cc @@ -167,6 +167,17 @@ uint64_t ThreadCpuNanoTime() { #endif } +uint64_t ProcessCpuNanoTime() { +#if defined(__linux__) + timespec now; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now); + return static_cast(now.tv_sec) * UINT64_C(1000000000) + now.tv_nsec; +#else + UNIMPLEMENTED(WARNING); + return -1; +#endif +} + void NanoSleep(uint64_t ns) { timespec tm; tm.tv_sec = ns / MsToNs(1000); diff --git a/runtime/base/time_utils.h b/runtime/base/time_utils.h index 383b52fb3..dbb8bcd4d 100644 --- a/runtime/base/time_utils.h +++ b/runtime/base/time_utils.h @@ -62,6 +62,9 @@ uint64_t NanoTime(); // Returns the thread-specific CPU-time clock in nanoseconds or -1 if unavailable. uint64_t ThreadCpuNanoTime(); +// Returns the process CPU-time clock in nanoseconds or -1 if unavailable. +uint64_t ProcessCpuNanoTime(); + // Converts the given number of nanoseconds to milliseconds. static constexpr inline uint64_t NsToMs(uint64_t ns) { return ns / 1000 / 1000; -- 2.11.0