@ECHO off setlocal enabledelayedexpansion SET PROG_NAME=sync_test SET PROG_VERSION=2.0.1 :: WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING :: ----------------------------------------------------------------------------- :: Do NOT configure this script to use an existing workspace, and make sure :: it is safe to BLAST the root directory of the workspace, the WorkspaceRoot :: defined below, again and again and again. Be sure you understand what the :: script is doing before running it in your environment. :: ----------------------------------------------------------------------------- :: WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING :: ----------------------------------------------------------------------------- :: Overview :: :: This script is intended to be configured to repetitively sync a known quantity :: of data to get an indication of sync performance. It can be scheduled to :: be called several times per day over a period of a few days to get sufficient :: data to overcome unusual factors with any particular run. It can be :: configured to hit multiple servers, and/or can be called from different :: locations. It will use the same stream but a different workspace on each :: machine. If not using streams, see below. :: ----------------------------------------------------------------------------- :: Requirements :: :: Make sure p4.exe is in the PATH. :: The directory specified by WorkspaceRoot must be safe to blast (delete and :: recreate) each time this script is called. :: Start from a directory not in the WorkspaceRoot path. :: :: ----------------------------------------------------------------------------- :: Instructions :: :: After configuring (see below), operate using commands like these sample commands: :: :: CD /D D:\p4 :: sync_test.bat > sync_test.log 2>&1 :: This script will generate a file named sync_test_log.<timestamp>.txt with a new timestamp :: each time it is run. The sync_test.log file (without a timestamp) should be empty and can :: be ignored. The information is in the timestamped log files. :: ----------------------------------------------------------------------------- :: Configuration :: :: Configuration settings. Replace P4PORT, P4USER, Stream, and WorkspaceRoot as needed. :: Make sure the P4USER selected has a valid ticket. If this is run on a routine schedule, it :: may be best to run as a user with an long-duration (or unlimited) ticket. :: Choose a Stream that contains that contains an amount of data suitable for your sync test, :: e.g. 2G (or smaller, say 20M, if doing instrumented syncs). Use virtual streams if needed :: to get a stream with the right amount of data to test with. SET P4PORT=YourP4PORTGoesHere:1666 SET P4USER=bot_sync_user SET Stream=//YourStream/main SET WorkspaceRoot=D:\p4\sync_test SET DisplayLogWhenDone=1 :: Set SyncOptions if needed. If not specified, default parallelization as specified on :: the server is used. In any case, server parallelization configurables affect sync behavior :: Sample value: SET SyncOptions=--parallel=threads=4,batch=4,batchsize=2048 SET SyncOptions= SET DEBUG=0 SET ResultsOK=1 :: Choose standard sync or heavily instrumented sync. :: Set DoInstrumentedSync=1 to do the heavily instrumented diagnostic syncs. :: The heavily instrumented sync is intended for diagnostic purposes and will generate :: massive local log files. For performance benmarking, a standard timed sync is :: advised. The heavily instrumented sync is useful for diagnosing complex network :: or other problems. SET DoInstrumentedSync=0 :: Note: If you are not using streams at all, you can create a stream depot for this :: test. Create something like this: :: p4 depot -t stream -o sync_test | p4 depot -i :: p4 stream -t mainline -o //sync_test/main | p4 stream -i :: p4 populate "//some/dir/with/2G/of/files/..." //sync_test/main/test_data_2G/... :: Replace "//some/dir/with/2G/of/files/..." with a path containing about 2G of files. :: Use 'p4 sizes -sah "//some/dir/with/files/..."' to get a feel for the size :: of any given path. :: ----------------------------------------------------------------------------- :: END of Configuration :: :: DO NOT make changes below this point in this script. :: SET P4CLIENT=sync_test.%COMPUTERNAME% SET ORIG_DIR=%CD% SET CLIENT_SPEC_FILE=%TEMP%\sync_test.client.p4s :: Avoid interference from P4CONFIG SET P4CONFIG=FileThatDoesNotExist.txt :: Initialize logging. SET MyDate=%DATE:~10,4%-%DATE:~7,2%-%DATE:~4,2% SET MyTimeHH=%TIME:~0,2% SET MyTimeMM=%TIME:~3,2% SET MyTimeSS=%TIME:~6,2% :: Left-pad hours if needed IF %MyTimeHH% LSS 10 ( SET MyTimeHH=0%MyTimeHH:~1,1% ) SET MyTime=%MyTimeHH%%MyTimeMM%%MyTimeSS% :: Combine date and time SET "Timestamp=%MyDate%-%MyTime%" :: Create the log file name SET "LOG=%CD%\log_sync_test.%Timestamp%.txt" IF NOT EXIST %LOG% ( :: Initialize empty log file and display first line as output. ECHO Log is: %LOG% > %LOG% TYPE %LOG% ) ELSE ( ECHO ERROR: Aborting because the log file already exists unexpectedly: %LOG% EXIT /B 1 ) ECHO Running %PROG_NAME% v%PROG_VERSION%. >> %LOG% 2>&1 :: Test Prep -- do these things before we start timing. ECHO p4 -ztag -p %P4PORT% info >> %LOG% 2>&1 p4 -ztag -p %P4PORT% info >> %LOG% 2>&1 IF %ERRORLEVEL% NEQ 0 ( ECHO ERROR: Aborting because 'p4 info' was not happy. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO p4 -p %P4PORT% -u %P4USER% login -s >> %LOG% 2>&1 p4 -p %P4PORT% -u %P4USER% login -s >> %LOG% 2>&1 IF %ERRORLEVEL% NEQ 0 ( ECHO ERROR: Aborting because 'p4 login -s' was not happy. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO Running: RD /S/Q %WorkspaceRoot% >> %LOG% 2>&1 RD /S/Q %WorkspaceRoot% >> %LOG% 2>&1 IF %ERRORLEVEL% EQU 0 ( ECHO Workspace root removed. >> %LOG% 2>&1 ) ELSE ( ECHO ERROR: Aborting because 'RD /S/Q %WorkspaceRoot%' was not happy. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO Running: MKDIR %WorkspaceRoot% >> %LOG% 2>&1 MKDIR %WorkspaceRoot% >> %LOG% 2>&1 IF %ERRORLEVEL% EQU 0 ( ECHO Workspace Root recreated. >> %LOG% 2>&1 ) ELSE ( ECHO ERROR: Aborting because 'MKDIR %WorkspaceRoot%' was not happy. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) CD /D %WorkspaceRoot% >> %LOG% 2>&1 ECHO > NUL IF %ERRORLEVEL% EQU 0 ( ECHO Operating in %CD% >> %LOG% 2>&1 ) ELSE ( ECHO ERROR: Aborting because 'CD %WorkspaceRoot%' was not happy. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO > NUL :: Ensure that we have a valid client. ECHO Preparing test client %P4CLIENT% >> %LOG% 2>&1 ECHO > NUL ECHO Running: p4 -p %P4PORT% -u %P4USER% client -S %Stream% -o .GT. %CLIENT_SPEC_FIEL% >> %LOG% 2>&1 p4 -p %P4PORT% -u %P4USER% client -S %Stream% -o | FINDSTR /v ^# | FINDSTR /v ^Update | FINDSTR /v ^Access > %CLIENT_SPEC_FILE% ECHO Generated client spec is: >> %LOG% 2>&1 TYPE %CLIENT_SPEC_FILE% >> %LOG% 2>&1 ECHO Running: p4 -s -p %P4PORT% -u %P4USER% client -i .LT. %CLIENT_SPEC_FILE% >> %LOG% 2>&1 p4 -s -p %P4PORT% -u %P4USER% client -i < %CLIENT_SPEC_FILE% >> %LOG% 2>&1 IF %ERRORLEVEL% EQU 0 ( ECHO Sync Test Client prepared. >> %LOG% 2>&1 DEL /F /Q %CLIENT_SPEC_FILE% ) ELSE ( ECHO ERROR: Aborting because sync test client prepration failed. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO Flushing to clear db.have >> %LOG% 2>&1 ECHO Running: p4 -s -p %P4PORT% -u %P4USER% flush -q @0 >> %LOG% 2>&1 p4 -s -p %P4PORT% -u %P4USER% flush -q @0 >> %LOG% 2>&1 IF %ERRORLEVEL% EQU 0 ( ECHO Flush OK. >> %LOG% 2>&1 ) ELSE ( ECHO ERROR: Aborting because sync test client flush failed. >> %LOG% 2>&1 ECHO > NUL START NOTEPAD %LOG% EXIT /B 1 ) ECHO Starting Timer NOW. >> %LOG% 2>&1 :: Get the start time FOR /f "tokens=1-4 delims=:.," %%a in ("%time%") do ( SET StartHH=%%a SET StartMM=%%b SET StartSS=%%c SET StartMS=%%d IF %DEBUG% NEQ 0 ( ECHO DEBUG: A=%%a B=%%b C=%%c D=%%d >> %LOG% 2>&1 ) ) IF %DEBUG% NEQ 0 ( ECHO DEBUG: StartHH=%StartHH% >> %LOG% 2>&1 ECHO DEBUG: StartMM=%StartMM% >> %LOG% 2>&1 ECHO DEBUG: StartSS=%StartSS% >> %LOG% 2>&1 ECHO DEBUG: StartMS=%StartMS% >> %LOG% 2>&1 ) :: Run sync command here. IF %DoInstrumentedSync% EQU 1 ( SET SyncCommand=p4 -s -vrpc=5 -p %P4PORT% -u %P4USER% -c %P4CLIENT% sync -q %SyncOptions% ) ELSE ( SET SyncCommand=p4 -s -p %P4PORT% -u %P4USER% -c %P4CLIENT% sync -q %SyncOptions% ) ECHO Running timed sync command: %SyncCommand% >> %LOG% 2>&1 %SyncCommand% >> %LOG% 2>&1 :: Sleep to simulate longer sync time in debug mode so we can test :: with a very tiny data set. IF %DEBUG% NEQ 0 ( ECHO DEBUG: SLEEP.EXE 123 SLEEP.EXE 123 ) IF %ERRORLEVEL% EQU 0 ( ECHO Sync OK. >> %LOG% 2>&1 ) ELSE ( ECHO ERROR: The sync was not happy. Results may be unusuable. ResultsOK=0 ) :: Get the end time FOR /f "tokens=1-4 delims=:.," %%a in ("%time%") do ( IF %DEBUG% NEQ 0 ( ECHO DEBUG: A=%%a B=%%b C=%%c D=%%d >> %LOG% 2>&1 ) SET EndHH=%%a SET EndMM=%%b SET EndSS=%%c SET EndMS=%%d ) IF %DEBUG% NEQ 0 ( ECHO DEBUG: EndHH=%EndHH% >> %LOG% 2>&1 ECHO DEBUG: EndMM=%EndMM% >> %LOG% 2>&1 ECHO DEBUG: EndSS=%EndSS% >> %LOG% 2>&1 ECHO DEBUG: EndMS=%EndMS% >> %LOG% 2>&1 ) :: Calculate the elapsed time (in milliseconds) SET /A ElapsedMilliseconds=(EndHH*3600000 + EndMM*60000 + EndSS*1000 + EndMS) - (StartHH*3600000 + StartMM*60000 + StartSS*1000 + StartMS) :: Convert milliseconds to seconds, minutes, and hours if needed SET /A ElapsedSeconds=%ElapsedMilliseconds% / 1000 SET /A ElapsedMinutes=%ElapsedSeconds% / 60 SET /A ElapsedHours=%ElapsedMinutes% / 60 SET /A ElapsedSeconds=%ElapsedSeconds% %% 60 SET /A ElapsedMinutes=%ElapsedMinutes% %% 60 SET /A ElapsedMilliseconds=%ElapsedMilliseconds% %% 1000 ECHO Time: !ElapsedHours! hours, !ElapsedMinutes! minutes, !ElapsedSeconds! seconds, !ElapsedMilliseconds! milliseconds. >> %LOG% 2>&1 IF %ResultsOK% NEQ 1 ( ECHO Warning: Due to sync failure, results may not be usable. >> %LOG% 2>&1 ) :: CD back to where we started from. CD /D %ORIG_DIR% :: Display the resulting log IF %DisplayLogWhenDone% EQU 1 ( START NOTEPAD %LOG% ) endlocal
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 30584 | C. Thomas Tyler |
Updated major version to reflect big changes in prior version. More general refinements. Changed sample values to totally bogus values that require replacement. |
||
#11 | 30583 | C. Thomas Tyler | Much better sync test script. | ||
#10 | 30569 | C. Thomas Tyler | Rolled back to Rev #2 for now. | ||
#9 | 30568 | C. Thomas Tyler | Refined. | ||
#8 | 30567 | C. Thomas Tyler | Revised. | ||
#7 | 30566 | C. Thomas Tyler | Refined. | ||
#6 | 30565 | C. Thomas Tyler | Fixed bug, added version id. | ||
#5 | 30564 | C. Thomas Tyler | Work-in-progress version. | ||
#4 | 30563 | C. Thomas Tyler | Improved. | ||
#3 | 30548 | C. Thomas Tyler | Tweaked. | ||
#2 | 30547 | C. Thomas Tyler | Adjusted sync_test.bat | ||
#1 | 30441 | C. Thomas Tyler | Added sample timed sync test script. |