diff --git a/clang/test/Driver/check-time-trace.cpp b/clang/test/Driver/check-time-trace.cpp index 3c6a002ae8ab9c..bff2c1984daa90 100644 --- a/clang/test/Driver/check-time-trace.cpp +++ b/clang/test/Driver/check-time-trace.cpp @@ -12,7 +12,7 @@ // CHECK-NEXT: "pid": // CHECK-NEXT: "tid": // CHECK-NEXT: "ts": -// CHECK: "name": "clang" +// CHECK: "name": "clang{{.*}}" // CHECK: "name": "process_name" template diff --git a/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 9e4f32da884fe7..efafed10639108 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/tools/driver/cc1_main.cpp @@ -218,7 +218,7 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { if (Clang->getFrontendOpts().TimeTrace) { llvm::timeTraceProfilerInitialize( - Clang->getFrontendOpts().TimeTraceGranularity); + Clang->getFrontendOpts().TimeTraceGranularity, Argv0); } // --print-supported-cpus takes priority over the actual compilation. if (Clang->getFrontendOpts().PrintSupportedCPUs) diff --git a/llvm/include/llvm/Support/TimeProfiler.h b/llvm/include/llvm/Support/TimeProfiler.h index 8cc430d0bc7276..2b51bba0e7f869 100644 --- a/llvm/include/llvm/Support/TimeProfiler.h +++ b/llvm/include/llvm/Support/TimeProfiler.h @@ -19,7 +19,8 @@ extern TimeTraceProfiler *TimeTraceProfilerInstance; /// Initialize the time trace profiler. /// This sets up the global \p TimeTraceProfilerInstance /// variable to be the profiler instance. -void timeTraceProfilerInitialize(unsigned TimeTraceGranularity); +void timeTraceProfilerInitialize(unsigned TimeTraceGranularity, + StringRef ProcName); /// Cleanup the time trace profiler, if it was initialized. void timeTraceProfilerCleanup(); diff --git a/llvm/lib/Support/TimeProfiler.cpp b/llvm/lib/Support/TimeProfiler.cpp index fc9ad1626992c5..6c993387e59d83 100644 --- a/llvm/lib/Support/TimeProfiler.cpp +++ b/llvm/lib/Support/TimeProfiler.cpp @@ -14,6 +14,7 @@ #include "llvm/ADT/StringMap.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/JSON.h" +#include "llvm/Support/Path.h" #include #include #include @@ -58,8 +59,8 @@ struct Entry { }; struct TimeTraceProfiler { - TimeTraceProfiler(unsigned TimeTraceGranularity = 0) - : StartTime(steady_clock::now()), + TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "") + : StartTime(steady_clock::now()), ProcName(ProcName), TimeTraceGranularity(TimeTraceGranularity) {} void begin(std::string Name, llvm::function_ref Detail) { @@ -167,7 +168,7 @@ struct TimeTraceProfiler { J.attribute("ts", 0); J.attribute("ph", "M"); J.attribute("name", "process_name"); - J.attributeObject("args", [&] { J.attribute("name", "clang"); }); + J.attributeObject("args", [&] { J.attribute("name", ProcName); }); }); J.arrayEnd(); @@ -179,15 +180,18 @@ struct TimeTraceProfiler { SmallVector Entries; StringMap CountAndTotalPerName; const TimePointType StartTime; + const std::string ProcName; // Minimum time granularity (in microseconds) const unsigned TimeTraceGranularity; }; -void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) { +void timeTraceProfilerInitialize(unsigned TimeTraceGranularity, + StringRef ProcName) { assert(TimeTraceProfilerInstance == nullptr && "Profiler should not be initialized"); - TimeTraceProfilerInstance = new TimeTraceProfiler(TimeTraceGranularity); + TimeTraceProfilerInstance = new TimeTraceProfiler( + TimeTraceGranularity, llvm::sys::path::filename(ProcName)); } void timeTraceProfilerCleanup() {