From cafd08ca053c115874296335e3d234c0553bad0f Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 16 Jan 2019 12:51:10 +0100 Subject: [PATCH] show runnable module compilation duration and imrpove duration accuracy close #377 --- src/u_common.pas | 17 +++++++++++++++++ src/u_main.pas | 20 +++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/u_common.pas b/src/u_common.pas index fc20e828..b67ba637 100644 --- a/src/u_common.pas +++ b/src/u_common.pas @@ -325,6 +325,9 @@ type // Converts all leading whites to tabs. Fails if width doesn't fivide number of spaces. function leadingSpacesToTabs(const value: string; width: integer): string; + // Converts the delta between two calls to GetTickCount64 to a string indicating a duration. + function formatTicksAsDuration(ticks: UInt64): string; + var // additional directories to find background tools additionalPath: string; @@ -1106,6 +1109,20 @@ begin end; end; +function formatTicksAsDuration(ticks: UInt64): string; +var + ms: Uint64; + sc: Uint64; + mn: Uint64; +begin + mn := ticks div 60000; + ticks -= mn * 60000; + sc := ticks div 1000; + ticks -= sc * 1000; + ms := ticks; + result := format('%d minutes, %d seconds and %d msecs', [mn, sc, ms]); +end; + //TODO-cfeature: make it working with relative paths function commonFolder(const files: TStringList): string; var diff --git a/src/u_main.pas b/src/u_main.pas index 3917feaa..76f0b7b1 100644 --- a/src/u_main.pas +++ b/src/u_main.pas @@ -428,7 +428,7 @@ type fDfmtWidg: TDfmtWidget; fProfWidg: TProfileViewerWidget; - fCompStart: TDateTime; + fCompStart: UInt64; fRunProjAfterCompArg: boolean; fRunProjAfterCompile: boolean; @@ -2478,7 +2478,7 @@ procedure TMainForm.projCompiling(project: ICommonProject); begin fProjActionsLock := true; if fAppliOpts.showBuildDuration and not fIsCompilingGroup then - fCompStart := Time(); + fCompStart := GetTickCount64; end; procedure TMainForm.projCompiled(project: ICommonProject; success: boolean); @@ -2493,7 +2493,8 @@ begin begin if fAppliOpts.showBuildDuration then begin - fMsgs.message('Build duration: ' + TimeToStr(Time - fCompStart), project, amcProj, amkInf); + fMsgs.message('Build duration: ' + formatTicksAsDuration(GetTickCount64 - fCompStart), + project, amcProj, amkInf); end; if fRunProjAfterCompile and assigned(fProject) then begin @@ -2527,7 +2528,8 @@ begin fMsgs.message('the project group is successfully compiled', nil, amcAll, amkInf); if fAppliOpts.showBuildDuration then begin - fMsgs.message('Group build duration: ' + TimeToStr(Time - fCompStart), nil, amcAll, amkInf); + fMsgs.message('Group build duration: ' + formatTicksAsDuration(GetTickCount64 - fCompStart), + nil, amcAll, amkInf); end; if assigned(fProjBeforeGroup) then fProjBeforeGroup.activate; @@ -3021,6 +3023,9 @@ var rng: TStringRange = (ptr:nil; pos:0; len: 0); begin + if fAppliOpts.showBuildDuration then + fCompStart := GetTickCount64; + result := false; fMsgs.clearByData(fDoc); FreeRunnableProc; @@ -3163,6 +3168,11 @@ begin fMsgs.message(shortenPath(fDoc.fileName, 25) + ' has not been compiled', fDoc, amcEdit, amkErr); end; + if fAppliOpts.showBuildDuration then + begin + fMsgs.message('Runnable build duration: ' + formatTicksAsDuration(GetTickCount64 - fCompStart), + nil, amcAll, amkInf); + end; finally dmdproc.Free; @@ -4274,7 +4284,7 @@ begin fIsCompilingGroup := true; fMsgs.message('start compiling a project group...', nil, amcAll, amkInf); if fAppliOpts.showBuildDuration then - fCompStart := Time; + fCompStart := GetTickCount64; for i:= 0 to fProjectGroup.projectCount-1 do begin fProjectGroup.getProject(i).activate;