[Support] Add TimeTraceScope constructor without detail arg

This simplifies code where no extra details are required
Also don't write out detail when it is empty.

Differential Revision: https://reviews.llvm.org/D71347
This commit is contained in:
Russell Gallop 2019-12-11 11:49:42 +00:00
parent ee21934588
commit df494f7512
8 changed files with 17 additions and 12 deletions

View File

@ -896,7 +896,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
{
PrettyStackTraceString CrashInfo("Per-function optimization");
llvm::TimeTraceScope TimeScope("PerFunctionPasses", StringRef(""));
llvm::TimeTraceScope TimeScope("PerFunctionPasses");
PerFunctionPasses.doInitialization();
for (Function &F : *TheModule)
@ -907,13 +907,13 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
{
PrettyStackTraceString CrashInfo("Per-module optimization passes");
llvm::TimeTraceScope TimeScope("PerModulePasses", StringRef(""));
llvm::TimeTraceScope TimeScope("PerModulePasses");
PerModulePasses.run(*TheModule);
}
{
PrettyStackTraceString CrashInfo("Code generation");
llvm::TimeTraceScope TimeScope("CodeGenPasses", StringRef(""));
llvm::TimeTraceScope TimeScope("CodeGenPasses");
CodeGenPasses.run(*TheModule);
}
@ -1499,7 +1499,7 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS) {
llvm::TimeTraceScope TimeScope("Backend", StringRef(""));
llvm::TimeTraceScope TimeScope("Backend");
std::unique_ptr<llvm::Module> EmptyModule;
if (!CGOpts.ThinLTOIndexFile.empty()) {

View File

@ -249,7 +249,7 @@ namespace clang {
void HandleTranslationUnit(ASTContext &C) override {
{
llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
llvm::TimeTraceScope TimeScope("Frontend");
PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
if (FrontendTimesIsEnabled) {
LLVMIRGenerationRefCount += 1;

View File

@ -151,7 +151,7 @@ void clang::ParseAST(Sema &S, bool PrintStats, bool SkipFunctionBodies) {
bool HaveLexer = S.getPreprocessor().getCurrentLexer();
if (HaveLexer) {
llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
llvm::TimeTraceScope TimeScope("Frontend");
P.Initialize();
Parser::DeclGroupPtrTy ADecl;
for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF;

View File

@ -924,8 +924,7 @@ void Sema::ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind) {
}
{
llvm::TimeTraceScope TimeScope("PerformPendingInstantiations",
StringRef(""));
llvm::TimeTraceScope TimeScope("PerformPendingInstantiations");
PerformPendingInstantiations();
}

View File

@ -134,7 +134,7 @@ GlobalModuleIndex::GlobalModuleIndex(std::unique_ptr<llvm::MemoryBuffer> Buffer,
"' failed: " + toString(std::move(Err)));
};
llvm::TimeTraceScope TimeScope("Module LoadIndex", StringRef(""));
llvm::TimeTraceScope TimeScope("Module LoadIndex");
// Read the global index.
bool InGlobalIndexBlock = false;
bool Done = false;
@ -770,7 +770,7 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) {
}
using namespace llvm;
llvm::TimeTraceScope TimeScope("Module WriteIndex", StringRef(""));
llvm::TimeTraceScope TimeScope("Module WriteIndex");
// Emit the file header.
Stream.Emit((unsigned)'B', 8);

View File

@ -246,7 +246,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
// Execute the frontend actions.
{
llvm::TimeTraceScope TimeScope("ExecuteCompiler", StringRef(""));
llvm::TimeTraceScope TimeScope("ExecuteCompiler");
Success = ExecuteCompilerInvocation(Clang.get());
}

View File

@ -58,6 +58,10 @@ struct TimeTraceScope {
TimeTraceScope(TimeTraceScope &&) = delete;
TimeTraceScope &operator=(TimeTraceScope &&) = delete;
TimeTraceScope(StringRef Name) {
if (TimeTraceProfilerInstance != nullptr)
timeTraceProfilerBegin(Name, StringRef(""));
}
TimeTraceScope(StringRef Name, StringRef Detail) {
if (TimeTraceProfilerInstance != nullptr)
timeTraceProfilerBegin(Name, Detail);

View File

@ -123,7 +123,9 @@ struct TimeTraceProfiler {
J.attribute("ts", StartUs);
J.attribute("dur", DurUs);
J.attribute("name", E.Name);
J.attributeObject("args", [&] { J.attribute("detail", E.Detail); });
if (!E.Detail.empty()) {
J.attributeObject("args", [&] { J.attribute("detail", E.Detail); });
}
});
}