[JITLink] Fix the show-timers option on llvm-jitlink.

No longer constantly shows times (even when -show-times=false). When shown,
times are now correctly grouped.

llvm-svn: 370951
This commit is contained in:
Lang Hames 2019-09-04 18:38:29 +00:00
parent e4526330b3
commit 200415c6dc
1 changed files with 16 additions and 15 deletions

View File

@ -609,6 +609,15 @@ Expected<int> runEntryPoint(Session &S, JITEvaluatedSymbol EntryPoint) {
return EntryPointPtr(EntryPointArgs.size() - 1, EntryPointArgs.data());
}
struct JITLinkTimers {
TimerGroup JITLinkTimers{"llvm-jitlink timers",
"timers for llvm-jitlink phases"};
Timer LoadObjectsTimer{
"load", "time to load/add object files to llvm-jitlink", JITLinkTimers};
Timer LinkTimer{"link", "time to link object files", JITLinkTimers};
Timer RunTimer{"run", "time to execute jitlink'd code", JITLinkTimers};
};
int main(int argc, char *argv[]) {
InitLLVM X(argc, argv);
@ -619,6 +628,10 @@ int main(int argc, char *argv[]) {
cl::ParseCommandLineOptions(argc, argv, "llvm jitlink tool");
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
/// If timers are enabled, create a JITLinkTimers instance.
std::unique_ptr<JITLinkTimers> Timers =
ShowTimes ? std::make_unique<JITLinkTimers>() : nullptr;
Session S(getFirstFileTriple());
ExitOnErr(sanitizeArguments(S));
@ -627,23 +640,16 @@ int main(int argc, char *argv[]) {
ExitOnErr(loadProcessSymbols(S));
ExitOnErr(loadDylibs());
TimerGroup JITLinkTimers("llvm-jitlink timers",
"timers for llvm-jitlink phases");
{
Timer LoadObjectsTimer(
"load", "time to load/add object files to llvm-jitlink", JITLinkTimers);
LoadObjectsTimer.startTimer();
TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);
ExitOnErr(loadObjects(S));
LoadObjectsTimer.stopTimer();
}
JITEvaluatedSymbol EntryPoint = 0;
{
Timer LinkTimer("link", "time to link object files", JITLinkTimers);
LinkTimer.startTimer();
TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
EntryPoint = ExitOnErr(getMainEntryPoint(S));
LinkTimer.stopTimer();
}
if (ShowAddrs)
@ -658,14 +664,9 @@ int main(int argc, char *argv[]) {
int Result = 0;
{
Timer RunTimer("run", "time to execute jitlink'd code", JITLinkTimers);
RunTimer.startTimer();
TimeRegion TR(Timers ? &Timers->RunTimer : nullptr);
Result = ExitOnErr(runEntryPoint(S, EntryPoint));
RunTimer.stopTimer();
}
if (ShowTimes)
JITLinkTimers.print(dbgs());
return Result;
}