diff options
author | 2017-12-08 12:15:22 -0800 | |
---|---|---|
committer | 2017-12-08 12:22:21 -0800 | |
commit | c654816053ae07fb1f129d705e94b76e59f37454 (patch) | |
tree | 867d678ab3f6e0f4af70da98e935aafae0c6126c | |
parent | 8f1a586fd4ac9796e75b2b18638e39b33ad6e9a2 (diff) |
ART: Change SCOPED_TRACE implementation
Move to a LOG-like usage pattern. This improves usability in the
presence of lock annotations.
Demonstrate in the JIT compiler, where a lambda would require
a REQUIRES_SHARED annotation.
Test: m
Test: manual
Change-Id: I9da2bfb29ed11660dbeb6f114a3d6c7ffef3a26d
-rw-r--r-- | compiler/Android.bp | 7 | ||||
-rw-r--r-- | compiler/jit/jit_compiler.cc | 3 | ||||
-rw-r--r-- | runtime/base/systrace.h | 36 | ||||
-rw-r--r-- | runtime/verifier/method_verifier.cc | 2 |
4 files changed, 37 insertions, 11 deletions
diff --git a/compiler/Android.bp b/compiler/Android.bp index 37a18cb9e9..fc19b54131 100644 --- a/compiler/Android.bp +++ b/compiler/Android.bp @@ -181,15 +181,10 @@ art_cc_defaults { ], }, }, - target: { - android: { - // For atrace. - shared_libs: ["libcutils"], - }, - }, generated_sources: ["art_compiler_operator_srcs"], shared_libs: [ "libbase", + "libcutils", // for atrace. "liblzma", ], include_dirs: ["art/disassembler"], diff --git a/compiler/jit/jit_compiler.cc b/compiler/jit/jit_compiler.cc index 74603c668f..88e3e5b230 100644 --- a/compiler/jit/jit_compiler.cc +++ b/compiler/jit/jit_compiler.cc @@ -23,6 +23,7 @@ #include "art_method-inl.h" #include "base/logging.h" // For VLOG #include "base/stringpiece.h" +#include "base/systrace.h" #include "base/time_utils.h" #include "base/timing_logger.h" #include "base/unix_file/fd_file.h" @@ -163,6 +164,8 @@ JitCompiler::~JitCompiler() { } bool JitCompiler::CompileMethod(Thread* self, ArtMethod* method, bool osr) { + SCOPED_TRACE << "JIT compiling " << method->PrettyMethod(); + DCHECK(!method->IsProxyMethod()); DCHECK(method->GetDeclaringClass()->IsResolved()); diff --git a/runtime/base/systrace.h b/runtime/base/systrace.h index c6b6ff1d43..08ab93d232 100644 --- a/runtime/base/systrace.h +++ b/runtime/base/systrace.h @@ -21,6 +21,7 @@ #include <cutils/trace.h> #include <utils/Trace.h> +#include <sstream> #include <string> #include "android-base/stringprintf.h" @@ -46,10 +47,37 @@ class ScopedTrace { } }; -#define SCOPED_TRACE(fmtstr, ...) \ - ::art::ScopedTrace trace ## __LINE__([&]() { \ - return ::android::base::StringPrintf((fmtstr), __VA_ARGS__); \ - }) +// Helper for the SCOPED_TRACE macro. Do not use directly. +class ScopedTraceNoStart { + public: + ScopedTraceNoStart() { + } + + ~ScopedTraceNoStart() { + ATRACE_END(); + } + + // Message helper for the macro. Do not use directly. + class ScopedTraceMessageHelper { + public: + ScopedTraceMessageHelper() { + } + ~ScopedTraceMessageHelper() { + ATRACE_BEGIN(buffer_.str().c_str()); + } + + std::ostream& stream() { + return buffer_; + } + + private: + std::ostringstream buffer_; + }; +}; + +#define SCOPED_TRACE \ + ::art::ScopedTraceNoStart trace ## __LINE__; \ + (ATRACE_ENABLED()) && ::art::ScopedTraceNoStart::ScopedTraceMessageHelper().stream() } // namespace art diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 271e2133cc..154292d460 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -283,7 +283,7 @@ FailureKind MethodVerifier::VerifyClass(Thread* self, bool allow_soft_failures, HardFailLogMode log_level, std::string* error) { - SCOPED_TRACE("VerifyClass %s", PrettyDescriptor(dex_file->GetClassDescriptor(class_def)).c_str()); + SCOPED_TRACE << "VerifyClass " << PrettyDescriptor(dex_file->GetClassDescriptor(class_def)); // A class must not be abstract and final. if ((class_def.access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) { |