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
diff --git a/runtime/base/systrace.h b/runtime/base/systrace.h
index 06db48a..c6b6ff1 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 @@
   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 @@
   }
 };
 
+#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 be58a57..8bd3098 100644
--- a/runtime/verifier/method_verifier.cc
+++ b/runtime/verifier/method_verifier.cc
@@ -284,7 +284,7 @@
                                         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)) {