From f5f86be1d40f30b3183ec148f443afa73d0cbe15 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 31 Jan 2020 18:58:28 -0500 Subject: Add support for enabling the LLVM time-trace feature I found this helpful while investigating an LLVM performance issue. Passing `-Z llvm-time-trace` causes a `llvm_timings.json` file to be created. This file can be inspected in either the Chrome Profiler tools or with any other compatible tool like SpeedScope. More information on the LLVM feature: - https://aras-p.info/blog/2019/01/16/time-trace-timeline-flame-chart-profiler-for-Clang/ - https://reviews.llvm.org/rL357340 --- src/rustllvm/PassWrapper.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/rustllvm/PassWrapper.cpp') diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index fad70369807..4ac7e0e6e1f 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -26,6 +26,7 @@ #include "llvm/Transforms/Instrumentation.h" #if LLVM_VERSION_GE(9, 0) #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" +#include "llvm/Support/TimeProfiler.h" #endif #if LLVM_VERSION_GE(8, 0) #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" @@ -57,6 +58,23 @@ extern "C" void LLVMInitializePasses() { initializeTarget(Registry); } +extern "C" void LLVMTimeTraceProfilerInitialize() { +#if LLVM_VERSION_GE(9, 0) + timeTraceProfilerInitialize(); +#endif +} + +extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) { +#if LLVM_VERSION_GE(9, 0) + StringRef FN(FileName); + std::error_code EC; + raw_fd_ostream OS(FN, EC, sys::fs::CD_CreateAlways); + + timeTraceProfilerWrite(OS); + timeTraceProfilerCleanup(); +#endif +} + enum class LLVMRustPassKind { Other, Function, -- cgit 1.4.1-3-g733a5