@ECHO off
setlocal
:: Requirements
:: Make sure p4.exe is in the PATH.
:: The directory specified by WorkspaceRoot must be safe to blast (delete and recreate) each time.
:: Start from a directory not in the WorkspaceRoot path.
::
:: Operate like so:
:: sync_test.bat > sync_test.log 2>&1
:: TO DO: Each generated sync_test.log should be analyized or sent elsewhere for analysis.
:: Configuration settings. Replace as needed.
SET P4PORT=public.perforce.com:1666
SET P4USER=tom_tyler
SET Stream=//sdp/dev
SET P4CLIENT=sync_test.%COMPUTERNAME%
SET WorkspaceRoot=D:\p4\sync_test
SET ORIG_DIR=%CD%
:: Test Prep -- do these things before we start timing.
ECHO Running: RD /S/Q %WorkspaceRoot%
RD /S/Q %WorkspaceRoot%
ECHO Running: MKDIR %WorkspaceRoot%
MKDIR %WorkspaceRoot%
CD /D %WorkspaceRoot%
ECHO Operating in %CD%
:: Ensure that we have a valid client.
ECHO Preparing test client %P4CLIENT%
p4 client -S %Stream% -o | p4 client -i
ECHO Flushing (clearing db.have)
ECHO Running: p4 -s flush -q @0
p4 -s flush -q @0
ECHO Timer is starting NOW.
:: Get the start time
for /f "tokens=1-4 delims=:.," %%a in ("%time%") do (
set StartHH=%%a
set StartMM=%%b
set StartSS=%%c
set start_ms=%%d
)
:: Run sync command here
ECHO Running timed command: p4 -s sync -q
p4 -s sync -q
:: Get the end time
for /f "tokens=1-4 delims=:.," %%a in ("%time%") do (
set EndHH=%%a
set EndMM=%%b
set EndSS=%%c
set end_ms=%%d
)
:: Calculate elapsed time in seconds
SET /a StartTotalSeconds=StartHH*3600+StartMM*60+StartSS
SET /a EndTotalSeconds=EndHH*3600+EndMM*60+EndSS
if %EndTotalSeconds% lss %StartTotalSeconds% set /a EndTotalSeconds+=86400
SET /a ElapsedSeconds=EndTotalSeconds-StartTotalSeconds
:: Calculate hours, minutes, and seconds from elapsed time
SET /a ElapsedHH=ElapsedSeconds/3600
SET /a ElapsedMM=(ElapsedSeconds%%3600)/60
SET /a ElapsedSS=ElapsedSeconds%%60
:: Display the elapsed time
ECHO Elapsed time: %ElapsedHH% hours %ElapsedMM% minutes %ElapsedSS% seconds.
endlocal