From 6fd3960066f1f04b4e35a232e91efd11774f4f59 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 27 Aug 2019 15:51:19 +0000 Subject: [PATCH] [JITLink] Add timers and -show-times option to llvm-jitlink. The timers track time spent loading objects, linking, and (if applicable) running JIT-link'd code. llvm-svn: 370075 --- llvm/tools/llvm-jitlink/llvm-jitlink.cpp | 38 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp index 1e449153ad84..96c4d671b839 100644 --- a/llvm/tools/llvm-jitlink/llvm-jitlink.cpp +++ b/llvm/tools/llvm-jitlink/llvm-jitlink.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/Timer.h" #include #include @@ -94,6 +95,10 @@ static cl::opt ShowSizes( cl::desc("Show sizes pre- and post-dead stripping, and allocations"), cl::init(false)); +static cl::opt ShowTimes("show-times", + cl::desc("Show times for llvm-jitlink phases"), + cl::init(false)); + static cl::opt ShowRelocatedSectionContents( "show-relocated-section-contents", cl::desc("show section contents after fixups have been applied"), @@ -622,9 +627,25 @@ int main(int argc, char *argv[]) { ExitOnErr(loadProcessSymbols(S)); ExitOnErr(loadDylibs()); - ExitOnErr(loadObjects(S)); + TimerGroup JITLinkTimers; + // ("llvm-jitlink timers", + // "timers for llvm-jitlink phases"); - auto EntryPoint = ExitOnErr(getMainEntryPoint(S)); + { + Timer LoadObjectsTimer( + "load", "time to load/add object files to llvm-jitlink", JITLinkTimers); + LoadObjectsTimer.startTimer(); + ExitOnErr(loadObjects(S)); + LoadObjectsTimer.stopTimer(); + } + + JITEvaluatedSymbol EntryPoint = 0; + { + Timer LinkTimer("link", "time to link object files", JITLinkTimers); + LinkTimer.startTimer(); + EntryPoint = ExitOnErr(getMainEntryPoint(S)); + LinkTimer.stopTimer(); + } if (ShowAddrs) S.dumpSessionInfo(outs()); @@ -636,5 +657,16 @@ int main(int argc, char *argv[]) { if (NoExec) return 0; - return ExitOnErr(runEntryPoint(S, EntryPoint)); + int Result = 0; + { + Timer RunTimer("run", "time to execute jitlink'd code", JITLinkTimers); + RunTimer.startTimer(); + Result = ExitOnErr(runEntryPoint(S, EntryPoint)); + RunTimer.stopTimer(); + } + + if (ShowTimes) + JITLinkTimers.print(dbgs()); + + return Result; }