diff options
author | 2017-12-06 14:17:22 -0800 | |
---|---|---|
committer | 2017-12-08 02:54:45 +0000 | |
commit | dfebbac8e30172169dbdaaf7e6a0be51433d57f1 (patch) | |
tree | 3c751ff6792aaf88706fd0b3e0ed77d2cc4f83c2 | |
parent | 92ab698e46dba3b6cff1457f47bfc344cb03f7ec (diff) |
ART: Add ScopedTrace constructor with lambda
In an effort to allow more complex and expensive atrace tagging,
add a ScopedTrace constructor that uses a passed-in lambda to
compute the string lazily.
Add a macro to simplify usage.
Test: m
Change-Id: I3b4576d786177042922fef0d05161e4cc11144d4
-rw-r--r-- | runtime/base/systrace.h | 13 | ||||
-rw-r--r-- | runtime/verifier/method_verifier.cc | 2 |
2 files changed, 14 insertions, 1 deletions
diff --git a/runtime/base/systrace.h b/runtime/base/systrace.h index 06db48a576..c6b6ff1d43 100644 --- a/runtime/base/systrace.h +++ b/runtime/base/systrace.h @@ -23,6 +23,8 @@ #include <string> +#include "android-base/stringprintf.h" + namespace art { class ScopedTrace { @@ -30,6 +32,12 @@ class ScopedTrace { explicit ScopedTrace(const char* name) { ATRACE_BEGIN(name); } + template <typename Fn> + explicit ScopedTrace(Fn fn) { + if (ATRACE_ENABLED()) { + ATRACE_BEGIN(fn().c_str()); + } + } explicit ScopedTrace(const std::string& name) : ScopedTrace(name.c_str()) {} @@ -38,6 +46,11 @@ class ScopedTrace { } }; +#define SCOPED_TRACE(fmtstr, ...) \ + ::art::ScopedTrace trace ## __LINE__([&]() { \ + return ::android::base::StringPrintf((fmtstr), __VA_ARGS__); \ + }) + } // namespace art #endif // ART_RUNTIME_BASE_SYSTRACE_H_ diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index be58a57c24..8bd3098998 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -284,7 +284,7 @@ FailureKind MethodVerifier::VerifyClass(Thread* self, bool allow_soft_failures, HardFailLogMode log_level, std::string* error) { - ScopedTrace trace(__FUNCTION__); + SCOPED_TRACE("VerifyClass %s", PrettyDescriptor(dex_file->GetClassDescriptor(class_def)).c_str()); // A class must not be abstract and final. if ((class_def.access_flags_ & (kAccAbstract | kAccFinal)) == (kAccAbstract | kAccFinal)) { |