Skip to content

Commit aedeab7

Browse files
committed
[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
1 parent 7caa17c commit aedeab7

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

clang/test/Driver/check-time-trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// CHECK-NEXT: "pid":
1313
// CHECK-NEXT: "tid":
1414
// CHECK-NEXT: "ts":
15-
// CHECK: "name": "clang"
15+
// CHECK: "name": "clang{{.*}}"
1616
// CHECK: "name": "process_name"
1717

1818
template <typename T>

clang/tools/driver/cc1_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
218218

219219
if (Clang->getFrontendOpts().TimeTrace) {
220220
llvm::timeTraceProfilerInitialize(
221-
Clang->getFrontendOpts().TimeTraceGranularity);
221+
Clang->getFrontendOpts().TimeTraceGranularity, Argv0);
222222
}
223223
// --print-supported-cpus takes priority over the actual compilation.
224224
if (Clang->getFrontendOpts().PrintSupportedCPUs)

llvm/include/llvm/Support/TimeProfiler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern TimeTraceProfiler *TimeTraceProfilerInstance;
1919
/// Initialize the time trace profiler.
2020
/// This sets up the global \p TimeTraceProfilerInstance
2121
/// variable to be the profiler instance.
22-
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity);
22+
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity,
23+
StringRef ProcName);
2324

2425
/// Cleanup the time trace profiler, if it was initialized.
2526
void timeTraceProfilerCleanup();

llvm/lib/Support/TimeProfiler.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/StringMap.h"
1515
#include "llvm/Support/CommandLine.h"
1616
#include "llvm/Support/JSON.h"
17+
#include "llvm/Support/Path.h"
1718
#include <cassert>
1819
#include <chrono>
1920
#include <string>
@@ -58,8 +59,8 @@ struct Entry {
5859
};
5960

6061
struct TimeTraceProfiler {
61-
TimeTraceProfiler(unsigned TimeTraceGranularity = 0)
62-
: StartTime(steady_clock::now()),
62+
TimeTraceProfiler(unsigned TimeTraceGranularity = 0, StringRef ProcName = "")
63+
: StartTime(steady_clock::now()), ProcName(ProcName),
6364
TimeTraceGranularity(TimeTraceGranularity) {}
6465

6566
void begin(std::string Name, llvm::function_ref<std::string()> Detail) {
@@ -167,7 +168,7 @@ struct TimeTraceProfiler {
167168
J.attribute("ts", 0);
168169
J.attribute("ph", "M");
169170
J.attribute("name", "process_name");
170-
J.attributeObject("args", [&] { J.attribute("name", "clang"); });
171+
J.attributeObject("args", [&] { J.attribute("name", ProcName); });
171172
});
172173

173174
J.arrayEnd();
@@ -179,15 +180,18 @@ struct TimeTraceProfiler {
179180
SmallVector<Entry, 128> Entries;
180181
StringMap<CountAndDurationType> CountAndTotalPerName;
181182
const TimePointType StartTime;
183+
const std::string ProcName;
182184

183185
// Minimum time granularity (in microseconds)
184186
const unsigned TimeTraceGranularity;
185187
};
186188

187-
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity) {
189+
void timeTraceProfilerInitialize(unsigned TimeTraceGranularity,
190+
StringRef ProcName) {
188191
assert(TimeTraceProfilerInstance == nullptr &&
189192
"Profiler should not be initialized");
190-
TimeTraceProfilerInstance = new TimeTraceProfiler(TimeTraceGranularity);
193+
TimeTraceProfilerInstance = new TimeTraceProfiler(
194+
TimeTraceGranularity, llvm::sys::path::filename(ProcName));
191195
}
192196

193197
void timeTraceProfilerCleanup() {

0 commit comments

Comments
 (0)