From 7a7c00761f6294dc21c40cbe1737354e655cda9b Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 14 Jun 2021 16:04:43 -0700 Subject: [PATCH] Revert "Allow signposts to take advantage of deferred string substitution" This reverts commit 03841edde7eee21d1d450041ab9a113a7e1be869. Unfortunately this still breaks the LLDB standalone bot. --- lldb/include/lldb/Utility/Timer.h | 25 ++-------- .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 57 ---------------------- lldb/source/Utility/Timer.cpp | 5 +- llvm/include/llvm/Support/Signposts.h | 36 +------------- llvm/lib/Support/Signposts.cpp | 23 +++++---- llvm/lib/Support/Timer.cpp | 2 +- 6 files changed, 19 insertions(+), 129 deletions(-) diff --git a/lldb/include/lldb/Utility/Timer.h b/lldb/include/lldb/Utility/Timer.h index 1e47ac7..2b39881 100644 --- a/lldb/include/lldb/Utility/Timer.h +++ b/lldb/include/lldb/Utility/Timer.h @@ -10,16 +10,10 @@ #define LLDB_UTILITY_TIMER_H #include "lldb/lldb-defines.h" -#include "llvm/ADT/ScopeExit.h" #include "llvm/Support/Chrono.h" -#include "llvm/Support/Signposts.h" #include #include -namespace llvm { - class SignpostEmitter; -} - namespace lldb_private { class Stream; @@ -78,28 +72,15 @@ private: const Timer &operator=(const Timer &) = delete; }; -llvm::SignpostEmitter &GetSignposts(); - } // namespace lldb_private // Use a format string because LLVM_PRETTY_FUNCTION might not be a string // literal. #define LLDB_SCOPED_TIMER() \ static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \ - ::lldb_private::Timer _scoped_timer(_cat, "%s", LLVM_PRETTY_FUNCTION); \ - SIGNPOST_EMITTER_START_INTERVAL(::lldb_private::GetSignposts(), \ - &_scoped_timer, "%s", LLVM_PRETTY_FUNCTION); \ - auto _scoped_signpost = llvm::make_scope_exit([&_scoped_timer]() { \ - ::lldb_private::GetSignposts().endInterval(&_scoped_timer); \ - }) - -#define LLDB_SCOPED_TIMERF(FMT, ...) \ + ::lldb_private::Timer _scoped_timer(_cat, "%s", LLVM_PRETTY_FUNCTION) +#define LLDB_SCOPED_TIMERF(...) \ static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \ - ::lldb_private::Timer _scoped_timer(_cat, FMT, __VA_ARGS__); \ - SIGNPOST_EMITTER_START_INTERVAL(::lldb_private::GetSignposts(), \ - &_scoped_timer, FMT, __VA_ARGS__); \ - auto _scoped_signpost = llvm::make_scope_exit([&_scoped_timer]() { \ - ::lldb_private::GetSignposts().endInterval(&_scoped_timer); \ - }) + ::lldb_private::Timer _scoped_timer(_cat, __VA_ARGS__) #endif // LLDB_UTILITY_TIMER_H diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index bb745da..e015de5 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -65,63 +65,6 @@ #include // Unfortunately the signpost header pulls in the system MachO header, too. -#ifdef MH_MAGIC -#undef MH_MAGIC -#endif -#ifdef MH_CIGAM -#undef MH_CIGAM -#endif -#ifdef MH_MAGIC_64 -#undef MH_MAGIC_64 -#endif -#ifdef MH_CIGAM_64 -#undef MH_CIGAM_64 -#endif -#ifdef MH_OBJECT -#undef MH_OBJECT -#endif -#ifdef MH_EXECUTE -#undef MH_EXECUTE -#endif -#ifdef MH_FVMLIB -#undef MH_FVMLIB -#endif -#ifdef MH_CORE -#undef MH_CORE -#endif -#ifdef MH_PRELOAD -#undef MH_PRELOAD -#endif -#ifdef MH_DYLIB -#undef MH_DYLIB -#endif -#ifdef MH_DYLINKER -#undef MH_DYLINKER -#endif -#ifdef MH_DYLIB_STUB -#undef MH_DYLIB_STUB -#endif -#ifdef MH_DSYM -#undef MH_DSYM -#endif -#ifdef MH_BUNDLE -#undef MH_BUNDLE -#endif -#ifdef MH_KEXT_BUNDLE -#undef MH_KEXT_BUNDLE -#endif -#ifdef MH_NOUNDEFS -#undef MH_NOUNDEFS -#endif -#ifdef MH_INCRLINK -#undef MH_INCRLINK -#endif -#ifdef MH_DYLDLINK -#undef MH_DYLDLINK -#endif -#ifdef MH_BINDATLOAD -#undef MH_BINDATLOAD -#endif #ifdef CPU_TYPE_ARM #undef CPU_TYPE_ARM #endif diff --git a/lldb/source/Utility/Timer.cpp b/lldb/source/Utility/Timer.cpp index b59ce3b..2f3afe4 100644 --- a/lldb/source/Utility/Timer.cpp +++ b/lldb/source/Utility/Timer.cpp @@ -33,8 +33,6 @@ static std::atomic g_categories; /// Allows llvm::Timer to emit signposts when supported. static llvm::ManagedStatic Signposts; -llvm::SignpostEmitter &lldb_private::GetSignposts() { return *Signposts; } - std::atomic Timer::g_quiet(true); std::atomic Timer::g_display_depth(0); static std::mutex &GetFileMutex() { @@ -61,6 +59,7 @@ void Timer::SetQuiet(bool value) { g_quiet = value; } Timer::Timer(Timer::Category &category, const char *format, ...) : m_category(category), m_total_start(std::chrono::steady_clock::now()) { + Signposts->startInterval(this, m_category.GetName()); TimerStack &stack = GetTimerStackForCurrentThread(); stack.push_back(this); @@ -87,6 +86,8 @@ Timer::~Timer() { auto total_dur = stop_time - m_total_start; auto timer_dur = total_dur - m_child_duration; + Signposts->endInterval(this, m_category.GetName()); + TimerStack &stack = GetTimerStackForCurrentThread(); if (g_quiet && stack.size() <= g_display_depth) { std::lock_guard lock(GetFileMutex()); diff --git a/llvm/include/llvm/Support/Signposts.h b/llvm/include/llvm/Support/Signposts.h index 6a656fb..d31f3c1 100644 --- a/llvm/include/llvm/Support/Signposts.h +++ b/llvm/include/llvm/Support/Signposts.h @@ -18,17 +18,8 @@ #define LLVM_SUPPORT_SIGNPOSTS_H #include "llvm/ADT/StringRef.h" -#include "llvm/Config/config.h" #include -#if LLVM_SUPPORT_XCODE_SIGNPOSTS -#include -#include -#endif - -#define SIGNPOSTS_AVAILABLE() \ - __builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *) - namespace llvm { class SignpostEmitterImpl; @@ -45,33 +36,8 @@ public: /// Begin a signposted interval for a given object. void startInterval(const void *O, StringRef Name); - -#if LLVM_SUPPORT_XCODE_SIGNPOSTS - os_log_t &getLogger() const; - os_signpost_id_t getSignpostForObject(const void *O); -#endif - - /// A macro to take advantage of the special format string handling - /// in the os_signpost API. The format string substitution is - /// deferred to the log consumer and done outside of the - /// application. -#if LLVM_SUPPORT_XCODE_SIGNPOSTS -#define SIGNPOST_EMITTER_START_INTERVAL(SIGNPOST_EMITTER, O, ...) \ - do { \ - if ((SIGNPOST_EMITTER).isEnabled()) \ - if (SIGNPOSTS_AVAILABLE()) \ - os_signpost_interval_begin((SIGNPOST_EMITTER).getLogger(), \ - (SIGNPOST_EMITTER).getSignpostForObject(O), \ - "LLVM Timers", __VA_ARGS__); \ - } while (0) -#else -#define SIGNPOST_EMITTER_START_INTERVAL(SIGNPOST_EMITTER, O, ...) \ - do { \ - } while (0) -#endif - /// End a signposted interval for a given object. - void endInterval(const void *O); + void endInterval(const void *O, StringRef Name); }; } // end namespace llvm diff --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp index efa283c..7bf7b46 100644 --- a/llvm/lib/Support/Signposts.cpp +++ b/llvm/lib/Support/Signposts.cpp @@ -10,14 +10,19 @@ #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 +#include #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; @@ -35,13 +40,13 @@ struct LogDeleter { namespace llvm { class SignpostEmitterImpl { using LogPtrTy = std::unique_ptr; + using LogTy = LogPtrTy::element_type; LogPtrTy SignpostLog; DenseMap Signposts; sys::SmartMutex Mutex; -public: - os_log_t &getLogger() const { return *SignpostLog; } + LogTy &getLogger() const { return *SignpostLog; } os_signpost_id_t getSignpostForObject(const void *O) { sys::SmartScopedLock Lock(Mutex); const auto &I = Signposts.find(O); @@ -55,6 +60,7 @@ public: return Inserted.first->second; } +public: SignpostEmitterImpl() : SignpostLog(LogCreator()) {} bool isEnabled() const { @@ -73,7 +79,7 @@ public: } } - void endInterval(const void *O) { + void endInterval(const void *O, llvm::StringRef Name) { if (isEnabled()) { if (SIGNPOSTS_AVAILABLE()) { // Both strings used here are required to be constant literal strings. @@ -119,17 +125,10 @@ void SignpostEmitter::startInterval(const void *O, StringRef Name) { #endif // if !HAVE_ANY_SIGNPOST_IMPL } -#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) { +void SignpostEmitter::endInterval(const void *O, StringRef Name) { #if HAVE_ANY_SIGNPOST_IMPL if (Impl == nullptr) return; - Impl->endInterval(O); + Impl->endInterval(O, Name); #endif // if !HAVE_ANY_SIGNPOST_IMPL } diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index 8d421db..6e592db 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -174,7 +174,7 @@ void Timer::stopTimer() { Running = false; Time += TimeRecord::getCurrentTime(false); Time -= StartTime; - Signposts->endInterval(this); + Signposts->endInterval(this, getName()); } void Timer::clear() { -- 2.7.4