[Support] Add ProcName to TimeTraceProfiler

This was hard-coded to "clang". This change allows it to to be used on
processes other than clang (such as lld).

This gets reported as clang-10 on Linux and clang.exe on Windows so
adapted test to accommodate this.

Differential Revision: https://reviews.llvm.org/D70950
This commit is contained in:
Russell Gallop 2019-12-02 13:10:44 +00:00
parent 7caa17caf8
commit aedeab7f85
4 changed files with 13 additions and 8 deletions

View File

@ -12,7 +12,7 @@
// CHECK-NEXT: "pid": // CHECK-NEXT: "pid":
// CHECK-NEXT: "tid": // CHECK-NEXT: "tid":
// CHECK-NEXT: "ts": // CHECK-NEXT: "ts":
// CHECK: "name": "clang" // CHECK: "name": "clang{{.*}}"
// CHECK: "name": "process_name" // CHECK: "name": "process_name"
template <typename T> template <typename T>

View File

@ -218,7 +218,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
if (Clang->getFrontendOpts().TimeTrace) { if (Clang->getFrontendOpts().TimeTrace) {
llvm::timeTraceProfilerInitialize( llvm::timeTraceProfilerInitialize(
Clang->getFrontendOpts().TimeTraceGranularity); Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
} }
// --print-supported-cpus takes priority over the actual compilation. // --print-supported-cpus takes priority over the actual compilation.
if (Clang->getFrontendOpts().PrintSupportedCPUs) if (Clang->getFrontendOpts().PrintSupportedCPUs)

View File

@ -19,7 +19,8 @@ extern TimeTraceProfiler *TimeTraceProfilerInstance;
/// Initialize the time trace profiler. /// Initialize the time trace profiler.
/// This sets up the global \p TimeTraceProfilerInstance /// This sets up the global \p TimeTraceProfilerInstance
/// variable to be the profiler instance. /// 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. /// Cleanup the time trace profiler, if it was initialized.
void timeTraceProfilerCleanup(); void timeTraceProfilerCleanup();

View File

@ -14,6 +14,7 @@
#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringMap.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/JSON.h" #include "llvm/Support/JSON.h"
#include "llvm/Support/Path.h"
#include <cassert> #include <cassert>
#include <chrono> #include <chrono>
#include <string> #include <string>
@ -58,8 +59,8 @@ struct Entry {
}; };
struct TimeTraceProfiler { struct TimeTraceProfiler {
TimeTraceProfiler(unsigned TimeTraceGranularity = 0) TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "")
: StartTime(steady_clock::now()), : StartTime(steady_clock::now()), ProcName(ProcName),
TimeTraceGranularity(TimeTraceGranularity) {} TimeTraceGranularity(TimeTraceGranularity) {}
void begin(std::string Name, llvm::function_ref<std::string()> Detail) { void begin(std::string Name, llvm::function_ref<std::string()> Detail) {
@ -167,7 +168,7 @@ struct TimeTraceProfiler {
J.attribute("ts", 0); J.attribute("ts", 0);
J.attribute("ph", "M"); J.attribute("ph", "M");
J.attribute("name", "process_name"); J.attribute("name", "process_name");
J.attributeObject("args", [&] { J.attribute("name", "clang"); }); J.attributeObject("args", [&] { J.attribute("name", ProcName); });
}); });
J.arrayEnd(); J.arrayEnd();
@ -179,15 +180,18 @@ struct TimeTraceProfiler {
SmallVector<Entry, 128> Entries; SmallVector<Entry, 128> Entries;
StringMap<CountAndDurationType> CountAndTotalPerName; StringMap<CountAndDurationType> CountAndTotalPerName;
const TimePointType StartTime; const TimePointType StartTime;
const std::string ProcName;
// Minimum time granularity (in microseconds) // Minimum time granularity (in microseconds)
const unsigned TimeTraceGranularity; const unsigned TimeTraceGranularity;
}; };
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) { void timeTraceProfilerInitialize(unsigned TimeTraceGranularity,
StringRef ProcName) {
assert(TimeTraceProfilerInstance == nullptr && assert(TimeTraceProfilerInstance == nullptr &&
"Profiler should not be initialized"); "Profiler should not be initialized");
TimeTraceProfilerInstance = new TimeTraceProfiler(TimeTraceGranularity); TimeTraceProfilerInstance = new TimeTraceProfiler(
TimeTraceGranularity, llvm::sys::path::filename(ProcName));
} }
void timeTraceProfilerCleanup() { void timeTraceProfilerCleanup() {