Changing LoadRunner Agent to run as a process or service

During the installation of LoadRunner if you select “Allow virtual users to run on this machine without user login”, the LoadRunner agent will run as a Windows system service called “LoadRunner Agent Service”.

If you choose “Manually log in to the Load Generator “, the LoadRunner agent will be run as a process named magentproc.exe.  This means you need to start the LoadRunner agent manually each time you reboot the PC/server or you need to put the LoadRunner agent process into a windows startup group.

Some vUser types will only run if the agent is running as a service (GUI, SAP, Citrix etc.). This is because they need to run in a user context.

After installation, to switch from running the LoadRunner agent as a service to running as a process:
magentservice.exe -remove
Add this shortcut to the startup folder – “C:\Program Files (x86)\HP\LoadRunner\LAUNCH_SERVICE\bin\magentproc.exe”

After installation, to switch from running the LoadRunner agent as a process to running as a service:
Remove the LoadRunner Agent Process from the Startup folder
magentservice.exe -install

N.B. You need admin rights to do this. The magentservice.exe file is in the C:\Program Files (x86)\HP\LoadRunner\bin or C:\Program Files\HP\LoadRunner\bin folder.

Calculate epoch time for last midnight

I had a requirement to calculate the epoch time in milliseconds for midnight at the start of today.

This function calculates this value.

 


Action() {
// Epoch time on 1/1/2010 00:00:00 was 1262304000
// N.B, If running this in subsequent years, change the hard coded value on the next line. // Value obtained from http://www.epochconverter.com/
//Declare integer iEpochStartYear – use it to hold the Epoch time (in secs) on 1st January this year.
int iEpochStartYear = 1262304000;      
//Declare integer to hold calculated value of Epoch time last midnight.
int iEpochSecsLastMidnight;            
//Declare integer to hold the current day (i.e. num of days since 1st Jan 2010)
int iCurrentDay;                  
//Declare char to contain final output value (N.B in milliseconds, not seconds)
char sEpochMilliSecsLastMidnight[13];   
// Current day is number of days since start of 1st Jan 2010.
// Need to subtract one day since midnight is nominally the end of yesterday (rather than the start of today).
lr_save_datetime(“%j “, DATE_NOW – ONE_DAY, “sCurrentDay”);
//Convert the SCurrentDay string to an integer
iCurrentDay = atoi(lr_eval_string(“{sCurrentDay}”));               
//Calculate Epoch time (in seconds) for last midnight
iEpochSecsLastMidnight = iEpochStartYear + (iCurrentDay * 86400);     
//Write Epoch time (in milliseconds) for last midnight to a string
sprintf(sEpochMilliSecsLastMidnight, “%d000”, iEpochSecsLastMidnight);    
lr_output_message(sEpochMilliSecsLastMidnight);
return 0; }

Delete unwanted files and results folders from LoadRunner script folders

It’s a common complaint of IT chaps supporting performance test teams that their script folders are large (especially if you’ve been running scripts with logging enabled for debugging purposes). Lots of files can be deleted before you save or archive your scripts which saves disk space and generally keeps things tidier.

The batch file (tidyup.cmd) attached to this article can help you to tidy up your LoadRunner script folder. It deletes unwanted log files and output files. The following files are deleted.

mdrv.log
mdrv_cmd.txt
options.txt
pre_cci.c
.ci
combined_.c
output.txt
debug.inf
All files with .idx extension
All files with .bak extension
The Result1 folder and it’s contents

 

It is also possible to delete RecordingLog.txt file in the scriptdata folder. If you delete this file, it will not affect the script’s replay. However, you will not be able to see the information about what happened during recording.

 

Batch file – tidyup.cmd Description of action
IF EXIST %temp%blankfile.txt  del %temp%blankfile.txt /q
IF EXIST %temp%FilesDeleted.txt  del %temp%FilesDeleted.txt /q
IF EXIST %temp%FoldersDeleted.txt  del %temp%FoldersDeleted.txt /q
IF EXIST %temp%BadParms.txt  del %temp%BadParms.txt /qtype nul > %temp%blankfile.txt
type nul > %temp%FilesDeleted.txt
type nul > %temp%FoldersDeleted.txt
type nul > %temp%BadParms.txt

del *.idx /s >> %temp%FilesDeleted.txt
del mdrv*.log /s >> %temp%FilesDeleted.txt
del mdrv.txt /s >> %temp%FilesDeleted.txt
del options.txt /s >> %temp%FilesDeleted.txt
del *.ci /s >> %temp%FilesDeleted.txt
del combined_*.c /s >> %temp%FilesDeleted.txt
del output.txt /s >> %temp%FilesDeleted.txt
del debug.inf /s >> %temp%FilesDeleted.txt
del *.bak /s >> %temp%FilesDeleted.txt

for %%d in (h) do (
for /f “delims=” %%a in (‘dir/s/b/ad “%CD%result*”‘) do (
echo “deleted %%a” >> %temp%FoldersDeleted.txt
rd /s /q “%%a”
)
)

rd result1 /s /q

 

findstr /S “:\” *.prm > %temp%BadParms.txt

fc %temp%FilesDeleted.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%FilesDeleted.txt”

fc %temp%FoldersDeleted.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%FoldersDeleted.txt”

fc %temp%BadParameters.txt %temp%blankfile.txt > nul
if errorlevel 1 “Notepad.exe” “%temp%BadParms.txt”

IF EXIST %temp%blankfile.txt  del %temp%blankfile.txt /q
IF EXIST %temp%FilesDeleted.txt  del %temp%FilesDeleted.txt /q
IF EXIST %temp%BadParms.txt  del %temp%BadParms.txt /q

These lines delete any existing files from previous runs of this batch file.These lines create blank files for later file comparisons.These del functions delete the unwanted LoadRunner files and pipe any output into the %temp%FilesDeleted.txt file.

This “for loop” deletes any sub-folders called result1 and pipes any output into the %temp%FoldersDeleted.txt file.

This deletes the local result1 directory if it exists

This function looks for explicit file paths rather than relative file paths in the .PRM files and writes them to the %temp%BadParameters.txt file.

If FilesDeleted.txt exists, open it in Notepad.exe wo we can see the names of deleted files.

If FoldersDeleted.txt exists, open it in Notepad.exe wo we can see the names of deleted folders.

If BadParameters.txt exists, open it in Notepad.exe wo we can see the names of parameters that don’t use relative file paths (and are less portable).

Finally delete the superfluous temporary files.

 

This batch file can be run either from within a script folder, or from a top-level folder containing multiple LoadRunner scripts. If run in a top level folder it loops through all sub-folders deleting files and results folders as it goes. In both cases, the list of deleted files and folders is displayed using notepad.exe .

Some of my colleagues prefer to have a copy of the tidyup.cmd batch file in all their script folders and some prefer ro run it from the top level folder. If you want a copy of tidyup.cmd in all your sub-folders the copytidy.cmd file can be used to copy the batch file to multiple sub-folders.

Batch file – copytidy.cmd Description of action
for %%d in (h) do (
for /f “delims=” %%a in (‘dir /a:D /b’) do (
copy %%a tidyup.cmd
)
)
For each sub folder identified by the dir /a:D /b command.
Copy the tidyup.cmd command into the folder.