diff options
author | Adrian Prantl <aprantl@apple.com> | 2021-06-11 15:18:25 -0700 |
---|---|---|
committer | Adrian Prantl <aprantl@apple.com> | 2021-06-11 16:35:43 -0700 |
commit | 541ccd1c1bb23e1e20a382844b35312c0caffd79 (patch) | |
tree | a8654906fa2061e39e4bcb3457801b804738f5f6 /llvm/lib/Support/Signposts.cpp | |
parent | 0276cc742bfc0829a56dba043625510b0f61326a (diff) | |
download | llvm-541ccd1c1bb23e1e20a382844b35312c0caffd79.zip llvm-541ccd1c1bb23e1e20a382844b35312c0caffd79.tar.gz llvm-541ccd1c1bb23e1e20a382844b35312c0caffd79.tar.bz2 |
Allow signposts to take advantage of deferred string substitution
One nice feature of the os_signpost API is that format string
substitutions happen in the consumer, not the logging
application. LLVM's current Signpost class doesn't take advantage of
this though and instead always uses a static "Begin/End %s" format
string.
This patch uses variadic macros to allow the API to be used as
intended. Unfortunately, the primary use-case I had in mind (the
LLDB_SCOPED_TIMER() macro) does not get much better from this, because
__PRETTY_FUNCTION__ is *not* a macro, but a static string, so
signposts created by LLDB_SCOPED_TIMER() still use a static "%s"
format string. At least LLDB_SCOPED_TIMERF() works as intended.
Differential Revision: https://reviews.llvm.org/D103575
Diffstat (limited to 'llvm/lib/Support/Signposts.cpp')
-rw-r--r-- | llvm/lib/Support/Signposts.cpp | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp index 7bf7b46..efa283c 100644 --- a/llvm/lib/Support/Signposts.cpp +++ b/llvm/lib/Support/Signposts.cpp @@ -10,19 +10,14 @@ #include "llvm/Support/Signposts.h" #include "llvm/Support/Timer.h" -#include "llvm/Config/config.h" #if LLVM_SUPPORT_XCODE_SIGNPOSTS #include "llvm/ADT/DenseMap.h" #include "llvm/Support/Mutex.h" -#include <Availability.h> -#include <os/signpost.h> #endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS using namespace llvm; #if LLVM_SUPPORT_XCODE_SIGNPOSTS -#define SIGNPOSTS_AVAILABLE() \ - __builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *) namespace { os_log_t *LogCreator() { os_log_t *X = new os_log_t; @@ -40,13 +35,13 @@ struct LogDeleter { namespace llvm { class SignpostEmitterImpl { using LogPtrTy = std::unique_ptr<os_log_t, LogDeleter>; - using LogTy = LogPtrTy::element_type; LogPtrTy SignpostLog; DenseMap<const void *, os_signpost_id_t> Signposts; sys::SmartMutex<true> Mutex; - LogTy &getLogger() const { return *SignpostLog; } +public: + os_log_t &getLogger() const { return *SignpostLog; } os_signpost_id_t getSignpostForObject(const void *O) { sys::SmartScopedLock<true> Lock(Mutex); const auto &I = Signposts.find(O); @@ -60,7 +55,6 @@ class SignpostEmitterImpl { return Inserted.first->second; } -public: SignpostEmitterImpl() : SignpostLog(LogCreator()) {} bool isEnabled() const { @@ -79,7 +73,7 @@ public: } } - void endInterval(const void *O, llvm::StringRef Name) { + void endInterval(const void *O) { if (isEnabled()) { if (SIGNPOSTS_AVAILABLE()) { // Both strings used here are required to be constant literal strings. @@ -125,10 +119,17 @@ void SignpostEmitter::startInterval(const void *O, StringRef Name) { #endif // if !HAVE_ANY_SIGNPOST_IMPL } -void SignpostEmitter::endInterval(const void *O, StringRef Name) { +#if HAVE_ANY_SIGNPOST_IMPL +os_log_t &SignpostEmitter::getLogger() const { return Impl->getLogger(); } +os_signpost_id_t SignpostEmitter::getSignpostForObject(const void *O) { + return Impl->getSignpostForObject(O); +} +#endif + +void SignpostEmitter::endInterval(const void *O) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - Impl->endInterval(O, Name); + Impl->endInterval(O); #endif // if !HAVE_ANY_SIGNPOST_IMPL } |