Skip to content

Commit

Permalink
WIP: added nicely formatted output for elapsed time.
Browse files Browse the repository at this point in the history
  • Loading branch information
danielt3 committed Jun 21, 2018
1 parent 107132f commit d41f6f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions header.h
Expand Up @@ -96,6 +96,9 @@ BOOL IsAnOutputConsoleDevice(HANDLE h);
DWORD GetParentProcessId(VOID);
HANDLE GetPipedProcessHandle(VOID);

int FormatElapsedTime( LARGE_INTEGER* elapsedTime, PCHAR outBuf,
const int outBufSize );

// perr.cpp
DWORD Perror(DWORD dwErrNum);
VOID Verbose(LPCTSTR szMsg);
Expand Down
23 changes: 23 additions & 0 deletions helpers.cpp
@@ -1,4 +1,5 @@
#include "header.h"
#include <stdio.h>

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// CreateFullPathW creates the directory structure pointed to by szPath
Expand Down Expand Up @@ -230,3 +231,25 @@ HANDLE GetPipedProcessHandle(VOID)
}
return hPipedProcess;
}

int FormatElapsedTime( LARGE_INTEGER* elapsedTime, PCHAR outBuf,
const int outBufSize )
{
int h = 0;
int m = 0;
int len = 0;

float s = float(elapsedTime->QuadPart / 1000000);
m = (int)(s / 60.0);
s = s - 60*m;

h = (int)((float)m/60.0);
m = m - 60*h;

len = snprintf( outBuf, outBufSize, "Elapsed time: %02dh%02dm%06.3fs", h, m, s);

return len;
}



4 changes: 2 additions & 2 deletions main.cpp
Expand Up @@ -371,8 +371,8 @@ int main(VOID)
elapsedTime.QuadPart *= 1000000L;
elapsedTime.QuadPart /= frequency.QuadPart;

strLen = snprintf( strElapsedTime, sizeof(strElapsedTime),
"Elapsed Time: %I64d us", elapsedTime.QuadPart );
strLen = FormatElapsedTime( &elapsedTime, strElapsedTime,
sizeof(strElapsedTime) );
WriteBufferToConsoleAndFilesA(&args, strElapsedTime, strLen, FALSE,
FALSE);
}
Expand Down

0 comments on commit d41f6f4

Please sign in to comment.