Skip to content

Commit b90f9be

Browse files
committed
Revert "Allow signposts to take advantage of deferred string substitution"
I forgot to make the LLDB macro conditional on Linux. This reverts commit 541ccd1.
1 parent f6dea2e commit b90f9be

File tree

5 files changed

+19
-66
lines changed

5 files changed

+19
-66
lines changed

lldb/include/lldb/Utility/Timer.h

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,10 @@
1010
#define LLDB_UTILITY_TIMER_H
1111

1212
#include "lldb/lldb-defines.h"
13-
#include "llvm/ADT/ScopeExit.h"
1413
#include "llvm/Support/Chrono.h"
15-
#include "llvm/Support/Signposts.h"
1614
#include <atomic>
1715
#include <cstdint>
1816

19-
namespace llvm {
20-
class SignpostEmitter;
21-
}
22-
2317
namespace lldb_private {
2418
class Stream;
2519

@@ -78,28 +72,15 @@ class Timer {
7872
const Timer &operator=(const Timer &) = delete;
7973
};
8074

81-
llvm::SignpostEmitter &GetSignposts();
82-
8375
} // namespace lldb_private
8476

8577
// Use a format string because LLVM_PRETTY_FUNCTION might not be a string
8678
// literal.
8779
#define LLDB_SCOPED_TIMER() \
8880
static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
89-
::lldb_private::Timer _scoped_timer(_cat, "%s", LLVM_PRETTY_FUNCTION); \
90-
SIGNPOST_EMITTER_START_INTERVAL(::lldb_private::GetSignposts(), \
91-
&_scoped_timer, "%s", LLVM_PRETTY_FUNCTION); \
92-
auto _scoped_signpost = llvm::make_scope_exit([&_scoped_timer]() { \
93-
::lldb_private::GetSignposts().endInterval(&_scoped_timer); \
94-
})
95-
96-
#define LLDB_SCOPED_TIMERF(FMT, ...) \
81+
::lldb_private::Timer _scoped_timer(_cat, "%s", LLVM_PRETTY_FUNCTION)
82+
#define LLDB_SCOPED_TIMERF(...) \
9783
static ::lldb_private::Timer::Category _cat(LLVM_PRETTY_FUNCTION); \
98-
::lldb_private::Timer _scoped_timer(_cat, FMT, __VA_ARGS__); \
99-
SIGNPOST_EMITTER_START_INTERVAL(::lldb_private::GetSignposts(), \
100-
&_scoped_timer, FMT, __VA_ARGS__); \
101-
auto _scoped_signpost = llvm::make_scope_exit([&_scoped_timer]() { \
102-
::lldb_private::GetSignposts().endInterval(&_scoped_timer); \
103-
})
84+
::lldb_private::Timer _scoped_timer(_cat, __VA_ARGS__)
10485

10586
#endif // LLDB_UTILITY_TIMER_H

lldb/source/Utility/Timer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ static std::atomic<Timer::Category *> g_categories;
3333
/// Allows llvm::Timer to emit signposts when supported.
3434
static llvm::ManagedStatic<llvm::SignpostEmitter> Signposts;
3535

36-
llvm::SignpostEmitter &lldb_private::GetSignposts() { return *Signposts; }
37-
3836
std::atomic<bool> Timer::g_quiet(true);
3937
std::atomic<unsigned> Timer::g_display_depth(0);
4038
static std::mutex &GetFileMutex() {
@@ -61,6 +59,7 @@ void Timer::SetQuiet(bool value) { g_quiet = value; }
6159

6260
Timer::Timer(Timer::Category &category, const char *format, ...)
6361
: m_category(category), m_total_start(std::chrono::steady_clock::now()) {
62+
Signposts->startInterval(this, m_category.GetName());
6463
TimerStack &stack = GetTimerStackForCurrentThread();
6564

6665
stack.push_back(this);
@@ -87,6 +86,8 @@ Timer::~Timer() {
8786
auto total_dur = stop_time - m_total_start;
8887
auto timer_dur = total_dur - m_child_duration;
8988

89+
Signposts->endInterval(this, m_category.GetName());
90+
9091
TimerStack &stack = GetTimerStackForCurrentThread();
9192
if (g_quiet && stack.size() <= g_display_depth) {
9293
std::lock_guard<std::mutex> lock(GetFileMutex());

llvm/include/llvm/Support/Signposts.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,8 @@
1818
#define LLVM_SUPPORT_SIGNPOSTS_H
1919

2020
#include "llvm/ADT/StringRef.h"
21-
#include "llvm/Config/config.h"
2221
#include <memory>
2322

24-
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
25-
#include <Availability.h>
26-
#include <os/signpost.h>
27-
#endif
28-
29-
#define SIGNPOSTS_AVAILABLE() \
30-
__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *)
31-
3223
namespace llvm {
3324
class SignpostEmitterImpl;
3425

@@ -45,27 +36,8 @@ class SignpostEmitter {
4536

4637
/// Begin a signposted interval for a given object.
4738
void startInterval(const void *O, StringRef Name);
48-
49-
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
50-
os_log_t &getLogger() const;
51-
os_signpost_id_t getSignpostForObject(const void *O);
52-
#endif
53-
54-
/// A macro to take advantage of the special format string handling
55-
/// in the os_signpost API. The format string substitution is
56-
/// deferred to the log consumer and done outside of the
57-
/// application.
58-
#define SIGNPOST_EMITTER_START_INTERVAL(SIGNPOST_EMITTER, O, ...) \
59-
do { \
60-
if ((SIGNPOST_EMITTER).isEnabled()) \
61-
if (SIGNPOSTS_AVAILABLE()) \
62-
os_signpost_interval_begin((SIGNPOST_EMITTER).getLogger(), \
63-
(SIGNPOST_EMITTER).getSignpostForObject(O), \
64-
"LLVM Timers", __VA_ARGS__); \
65-
} while (0)
66-
6739
/// End a signposted interval for a given object.
68-
void endInterval(const void *O);
40+
void endInterval(const void *O, StringRef Name);
6941
};
7042

7143
} // end namespace llvm

llvm/lib/Support/Signposts.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@
1010
#include "llvm/Support/Signposts.h"
1111
#include "llvm/Support/Timer.h"
1212

13+
#include "llvm/Config/config.h"
1314
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
1415
#include "llvm/ADT/DenseMap.h"
1516
#include "llvm/Support/Mutex.h"
17+
#include <Availability.h>
18+
#include <os/signpost.h>
1619
#endif // if LLVM_SUPPORT_XCODE_SIGNPOSTS
1720

1821
using namespace llvm;
1922

2023
#if LLVM_SUPPORT_XCODE_SIGNPOSTS
24+
#define SIGNPOSTS_AVAILABLE() \
25+
__builtin_available(macos 10.14, iOS 12, tvOS 12, watchOS 5, *)
2126
namespace {
2227
os_log_t *LogCreator() {
2328
os_log_t *X = new os_log_t;
@@ -35,13 +40,13 @@ struct LogDeleter {
3540
namespace llvm {
3641
class SignpostEmitterImpl {
3742
using LogPtrTy = std::unique_ptr<os_log_t, LogDeleter>;
43+
using LogTy = LogPtrTy::element_type;
3844

3945
LogPtrTy SignpostLog;
4046
DenseMap<const void *, os_signpost_id_t> Signposts;
4147
sys::SmartMutex<true> Mutex;
4248

43-
public:
44-
os_log_t &getLogger() const { return *SignpostLog; }
49+
LogTy &getLogger() const { return *SignpostLog; }
4550
os_signpost_id_t getSignpostForObject(const void *O) {
4651
sys::SmartScopedLock<true> Lock(Mutex);
4752
const auto &I = Signposts.find(O);
@@ -55,6 +60,7 @@ class SignpostEmitterImpl {
5560
return Inserted.first->second;
5661
}
5762

63+
public:
5864
SignpostEmitterImpl() : SignpostLog(LogCreator()) {}
5965

6066
bool isEnabled() const {
@@ -73,7 +79,7 @@ class SignpostEmitterImpl {
7379
}
7480
}
7581

76-
void endInterval(const void *O) {
82+
void endInterval(const void *O, llvm::StringRef Name) {
7783
if (isEnabled()) {
7884
if (SIGNPOSTS_AVAILABLE()) {
7985
// Both strings used here are required to be constant literal strings.
@@ -119,17 +125,10 @@ void SignpostEmitter::startInterval(const void *O, StringRef Name) {
119125
#endif // if !HAVE_ANY_SIGNPOST_IMPL
120126
}
121127

122-
#if HAVE_ANY_SIGNPOST_IMPL
123-
os_log_t &SignpostEmitter::getLogger() const { return Impl->getLogger(); }
124-
os_signpost_id_t SignpostEmitter::getSignpostForObject(const void *O) {
125-
return Impl->getSignpostForObject(O);
126-
}
127-
#endif
128-
129-
void SignpostEmitter::endInterval(const void *O) {
128+
void SignpostEmitter::endInterval(const void *O, StringRef Name) {
130129
#if HAVE_ANY_SIGNPOST_IMPL
131130
if (Impl == nullptr)
132131
return;
133-
Impl->endInterval(O);
132+
Impl->endInterval(O, Name);
134133
#endif // if !HAVE_ANY_SIGNPOST_IMPL
135134
}

llvm/lib/Support/Timer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void Timer::stopTimer() {
174174
Running = false;
175175
Time += TimeRecord::getCurrentTime(false);
176176
Time -= StartTime;
177-
Signposts->endInterval(this);
177+
Signposts->endInterval(this, getName());
178178
}
179179

180180
void Timer::clear() {

0 commit comments

Comments
 (0)