mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Stats] Reduce layering violations in FrontendStatsTracer.
This commit is contained in:
@@ -5658,3 +5658,37 @@ void Decl::setClangNode(ClangNode Node) {
|
||||
}
|
||||
*(ptr - 1) = Node.getOpaqueValue();
|
||||
}
|
||||
|
||||
// See swift/Basic/Statistic.h for declaration: this enables tracing Decls, is
|
||||
// defined here to avoid too much layering violation / circular linkage
|
||||
// dependency.
|
||||
|
||||
struct DeclTraceFormatter : public UnifiedStatsReporter::TraceFormatter {
|
||||
void traceName(const void *Entity, raw_ostream &OS) const {
|
||||
if (!Entity)
|
||||
return;
|
||||
const Decl *D = static_cast<const Decl *>(Entity);
|
||||
if (auto const *VD = dyn_cast<const ValueDecl>(D)) {
|
||||
VD->getFullName().print(OS, false);
|
||||
}
|
||||
}
|
||||
void traceLoc(const void *Entity, SourceManager *SM,
|
||||
clang::SourceManager *CSM, raw_ostream &OS) const {
|
||||
if (!Entity)
|
||||
return;
|
||||
const Decl *D = static_cast<const Decl *>(Entity);
|
||||
D->getSourceRange().print(OS, *SM, false);
|
||||
}
|
||||
};
|
||||
|
||||
static DeclTraceFormatter TF;
|
||||
|
||||
UnifiedStatsReporter::FrontendStatsTracer
|
||||
UnifiedStatsReporter::getStatsTracer(StringRef EventName, const Decl *D) {
|
||||
if (LastTracedFrontendCounters)
|
||||
// Return live tracer object.
|
||||
return FrontendStatsTracer(EventName, D, &TF, this);
|
||||
else
|
||||
// Return inert tracer object.
|
||||
return FrontendStatsTracer();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user