Skip to content

Commit 67baa65

Browse files
committed
[Stats] Replace RecursiveSharedTimer with FrontendStatsTracer.
1 parent fd5597f commit 67baa65

File tree

7 files changed

+3
-111
lines changed

7 files changed

+3
-111
lines changed

include/swift/Basic/Statistic.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,6 @@ class UnifiedStatsReporter {
7878
#undef FRONTEND_STATISTIC
7979
};
8080

81-
struct AlwaysOnFrontendRecursiveSharedTimers {
82-
AlwaysOnFrontendRecursiveSharedTimers();
83-
#define FRONTEND_RECURSIVE_SHARED_TIMER(ID) RecursiveSharedTimer ID;
84-
#include "Statistics.def"
85-
#undef FRONTEND_RECURSIVE_SHARED_TIMER
86-
87-
int dummyInstanceVariableToGetConstructorToParse;
88-
};
89-
9081
// To trace an entity, you have to provide a TraceFormatter for it. This is a
9182
// separate type since we do not have retroactive conformances in C++, and it
9283
// is a type that takes void* arguments since we do not have existentials
@@ -133,8 +124,6 @@ class UnifiedStatsReporter {
133124
std::unique_ptr<AlwaysOnFrontendCounters> LastTracedFrontendCounters;
134125
std::vector<FrontendStatsEvent> FrontendStatsEvents;
135126
std::unique_ptr<RecursionSafeTimers> RecursiveTimers;
136-
std::unique_ptr<AlwaysOnFrontendRecursiveSharedTimers>
137-
FrontendRecursiveSharedTimers;
138127

139128
void publishAlwaysOnStatsToLLVM();
140129
void printAlwaysOnStatsAndTimers(llvm::raw_ostream &OS);
@@ -160,7 +149,6 @@ class UnifiedStatsReporter {
160149

161150
AlwaysOnDriverCounters &getDriverCounters();
162151
AlwaysOnFrontendCounters &getFrontendCounters();
163-
AlwaysOnFrontendRecursiveSharedTimers &getFrontendRecursiveSharedTimers();
164152
void noteCurrentProcessExitStatus(int);
165153
void saveAnyFrontendStatsEvents(FrontendStatsTracer const &T, bool IsEntry);
166154
};

include/swift/Basic/Statistics.def

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
// - Subsystem is a token to be stringified as a name prefix
2020
// - Id is an identifier suitable for use in C++
2121
//
22-
// FRONTEND_RECURSIVE_SHARED_TIMER(Id)
23-
// - Id is an identifier suitable for use in C++
24-
//
2522
//===----------------------------------------------------------------------===//
2623

2724
/// Driver statistics are collected for driver processes
@@ -219,13 +216,3 @@ FRONTEND_STATISTIC(IRModule, NumIRInsts)
219216
/// the .o file you find on disk after the frontend exits.
220217
FRONTEND_STATISTIC(LLVM, NumLLVMBytesOutput)
221218
#endif
222-
223-
/// Frontend timers for recursive routines
224-
#ifdef FRONTEND_RECURSIVE_SHARED_TIMER
225-
226-
/// Time spent in NominalTypeDecl::lookupDirect.
227-
FRONTEND_RECURSIVE_SHARED_TIMER(NominalTypeDecl__lookupDirect)
228-
229-
/// Time spent in ClangImporter::Implementation::loadAllMembers.
230-
FRONTEND_RECURSIVE_SHARED_TIMER(ClangImporter__Implementation__loadAllMembers)
231-
#endif

include/swift/Basic/Timer.h

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -45,66 +45,6 @@ namespace swift {
4545
CompilationTimersEnabled = State::Enabled;
4646
}
4747
};
48-
49-
/// A SharedTimer for recursive routines.
50-
/// void example() {
51-
/// RecursiveSharedTimer::Guard guard; // MUST BE AT TOP SCOPE of function to
52-
/// work right! if (auto s = getASTContext().Stats) {
53-
/// guard =
54-
/// ctx.Stats->getFrontendRecursiveSharedTimers().NominalTypeDecl__lookupDirect.getGuard();
55-
// }
56-
/// ...
57-
/// }
58-
59-
class RecursiveSharedTimer {
60-
private:
61-
int recursionCount = 0;
62-
const StringRef name;
63-
llvm::Optional<SharedTimer> timer;
64-
65-
void enterRecursiveFunction() {
66-
assert(recursionCount >= 0 && "too many exits");
67-
if (recursionCount++ == 0)
68-
timer.emplace(name);
69-
}
70-
void exitRecursiveFunction() {
71-
assert(recursionCount > 0 && "too many exits");
72-
if (--recursionCount == 0)
73-
timer.reset();
74-
}
75-
76-
public:
77-
RecursiveSharedTimer(StringRef name) : name(name) {}
78-
79-
struct Guard {
80-
RecursiveSharedTimer *recursiveTimerOrNull;
81-
82-
Guard(RecursiveSharedTimer *rst) : recursiveTimerOrNull(rst) {
83-
if (recursiveTimerOrNull)
84-
recursiveTimerOrNull->enterRecursiveFunction();
85-
}
86-
~Guard() {
87-
if (recursiveTimerOrNull)
88-
recursiveTimerOrNull->exitRecursiveFunction();
89-
}
90-
91-
// All this stuff is to do an RAII object that be moved.
92-
Guard() : recursiveTimerOrNull(nullptr) {}
93-
Guard(Guard &&other) {
94-
recursiveTimerOrNull = other.recursiveTimerOrNull;
95-
other.recursiveTimerOrNull = nullptr;
96-
}
97-
Guard &operator=(Guard &&other) {
98-
recursiveTimerOrNull = other.recursiveTimerOrNull;
99-
other.recursiveTimerOrNull = nullptr;
100-
return *this;
101-
}
102-
Guard(const Guard &) = delete;
103-
Guard &operator=(const Guard &) = delete;
104-
};
105-
106-
Guard getGuard() { return Guard(this); }
107-
};
10848
} // end namespace swift
10949

11050
#endif // SWIFT_BASIC_TIMER_H

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,12 +1352,10 @@ void NominalTypeDecl::makeMemberVisible(ValueDecl *member) {
13521352
TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
13531353
DeclName name,
13541354
bool ignoreNewExtensions) {
1355-
RecursiveSharedTimer::Guard guard;
13561355
ASTContext &ctx = getASTContext();
1356+
FrontendStatsTracer tracer(ctx.Stats, "lookup-direct", this);
13571357
if (auto s = ctx.Stats) {
13581358
++s->getFrontendCounters().NominalTypeLookupDirectCount;
1359-
guard = s->getFrontendRecursiveSharedTimers()
1360-
.NominalTypeDecl__lookupDirect.getGuard();
13611359
}
13621360

13631361
// We only use NamedLazyMemberLoading when a user opts-in and we have

lib/Basic/Statistic.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,6 @@ UnifiedStatsReporter::getFrontendCounters()
221221
return *FrontendCounters;
222222
}
223223

224-
UnifiedStatsReporter::AlwaysOnFrontendRecursiveSharedTimers &
225-
UnifiedStatsReporter::getFrontendRecursiveSharedTimers() {
226-
if (!FrontendRecursiveSharedTimers)
227-
FrontendRecursiveSharedTimers =
228-
make_unique<AlwaysOnFrontendRecursiveSharedTimers>();
229-
return *FrontendRecursiveSharedTimers;
230-
}
231-
232224
void
233225
UnifiedStatsReporter::noteCurrentProcessExitStatus(int status) {
234226
assert(!currentProcessExitStatusSet);
@@ -395,15 +387,6 @@ UnifiedStatsReporter::saveAnyFrontendStatsEvents(
395387
#undef FRONTEND_STATISTIC
396388
}
397389

398-
UnifiedStatsReporter::AlwaysOnFrontendRecursiveSharedTimers::
399-
AlwaysOnFrontendRecursiveSharedTimers()
400-
:
401-
#define FRONTEND_RECURSIVE_SHARED_TIMER(ID) ID(#ID),
402-
#include "swift/Basic/Statistics.def"
403-
#undef FRONTEND_RECURSIVE_SHARED_TIMER
404-
dummyInstanceVariableToGetConstructorToParse(0) {
405-
}
406-
407390
UnifiedStatsReporter::TraceFormatter::~TraceFormatter() {}
408391

409392
UnifiedStatsReporter::~UnifiedStatsReporter()

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8343,12 +8343,8 @@ createUnavailableDecl(Identifier name, DeclContext *dc, Type type,
83438343

83448344
void
83458345
ClangImporter::Implementation::loadAllMembers(Decl *D, uint64_t extra) {
8346-
RecursiveSharedTimer::Guard guard;
8347-
if (auto s = D->getASTContext().Stats) {
8348-
guard = s->getFrontendRecursiveSharedTimers()
8349-
.ClangImporter__Implementation__loadAllMembers.getGuard();
8350-
}
83518346

8347+
FrontendStatsTracer tracer(D->getASTContext().Stats, "load-all-members", D);
83528348
assert(D);
83538349

83548350
// Check whether we're importing an Objective-C container of some sort.

test/Misc/stats_dir_tracer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// RUN: %target-swiftc_driver -o %t/main -module-name main -stats-output-dir %t %s -trace-stats-events
33
// RUN: %FileCheck -input-file %t/*.csv %s
44

5-
// CHECK: {{[0-9]+,[0-9]+,"exit","check-conformance","Sema.NominalTypeLookupDirectCount",[0-9]+,[0-9]+,"<conformance Bar : Proto>","\[.*stats_dir_tracer.swift:21:1 - line:27:1\]"}}
5+
// CHECK: {{[0-9]+,[0-9]+,"exit","lookup-direct","Sema.NominalTypeLookupDirectCount",[0-9]+,[0-9]+,"Proto","\[.*stats_dir_tracer.swift:13:1 - line:15:1\]"}}
66
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-fn","Sema.NumTypesDeserialized",[0-9]+,[0-9]+,"foo\(\)","\[.*stats_dir_tracer.swift:9:8 - line:11:1\]"}}
77
// CHECK: {{[0-9]+,[0-9]+,"exit","typecheck-decl","Sema.NumConstraintScopes",[0-9]+,[0-9]+,"<pattern binding>","\[.*stats_dir_tracer.swift:23:5 - line:23:13\]"}}
88

0 commit comments

Comments
 (0)