Improve ftime-trace implementation. (#3797)

* Improve ftime-trace implementation.
- Rewrite ftime-trace to our own implementatation instead of using LLVM's time trace code. The disadvantage is that this removes LLVM's work from the trace (optimization), but has the large benefit of being able to tailor the tracing output to our needs.
- Add memory tracing to ftime-trace (not possible with LLVM's implementation)
- Do not output the sum for each "category"/named string. This causes the LLVM output to be _very_ long, because we put more information in each time segment name. Tooling that processes the time trace output can do this summing itself (i.e. Tracy), and makes the time trace much more pleasant to view in trace viewers.
- Use MonoTime, move timescale calculation to output stage, 'measurement' stage uses ticks as unit
- Fix crash on `ldc2 -ftime-trace` without files passed.
This commit is contained in:
Johan Engelen 2021-08-14 14:11:22 +02:00 committed by GitHub
parent faea8aa585
commit c517ce9d12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 496 additions and 215 deletions

View file

@ -1002,13 +1002,16 @@ void emulateWeakAnyLinkageForMSVC(LLFunction *func, LINK linkage) {
} // anonymous namespace
void DtoDefineFunction(FuncDeclaration *fd, bool linkageAvailableExternally) {
TimeTraceScope timeScope(
("Codegen func " + llvm::SmallString<40>(fd->toChars())).str(), [fd]() {
std::string detail = fd->toPrettyChars();
detail += ", loc: ";
detail += fd->loc.toChars();
return detail;
});
TimeTraceScope timeScope([fd]() {
std::string name("Codegen func ");
name += fd->toChars();
return name;
},
[fd]() {
std::string detail = fd->toPrettyChars();
return detail;
},
fd->loc);
IF_LOG Logger::println("DtoDefineFunction(%s): %s", fd->toPrettyChars(),
fd->loc.toChars());