Search the site

Vugen: Measure transaction timings in milliseconds

Let's say you are testing a web application and the service level agreement of response times for each web page is 1.5 seconds or below. You might want to automatically fail any transaction that comes back in a longer amount of time. You will need to measure the number of milliseconds in the transaction, and see exceeds this amount. You might need to set something like this up for any transaction where timing for milliseconds is crucial. Just because the business process passes, does not mean the transaction should pass, especially when there is a service level agreement in place.


/*

This function will get the current time in milliseconds.
First, setup 3 parameters in LoadRunner called milliseconds, hours, and minutes with the following formats:

1. milliseconds %s.000 will return seconds.milliseconds of the current time
2. hours %H will return the hour portion of the current time in military formatrmat
3. minutes %M will return the minutes portion of the time set them to update on each occurrence

*/

long int get_time()

{
int milliseconds, seconds, minutes, hours;
long int totalMilliseconds;

//these chars are set 1 byte bigger to account for the null zero
char temp[7], tempSecs[3], tempMilliseconds[4];

//temp = SS.MMM, tempSecs = SS, tempMilliseconds = MMM

sprintf(temp, "%s", lr_eval_string("{milliseconds}"));
memset(tempSecs, sizeof(tempSecs), '\0');
strncpy(tempSecs, temp, 2);

//copy 2 characters from tempSecs to temp
seconds = atoi(tempSecs);

//add 3 to temp and get millisecond portion
memset(tempMilliseconds, sizeof(tempMilliseconds), 0);
strncpy(tempMilliseconds, temp+3, 3);
milliseconds = atoi(tempMilliseconds);

//Get current hours
hours = atoi(lr_eval_string("{hours}"));

//Get current minutes
minutes = atoi(lr_eval_string("{minutes}"));

lr_output_message("This is the current time %02d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds);

//Compute milliseconds
totalMilliseconds = (hours * 3600000) + (minutes * 60000) + (seconds * 1000) + milliseconds;

lr_output_message("This is the current time in milliseconds {%ld}", totalMilliseconds);

return (totalMilliseconds);

}

/*
Here is how you would use the script in LoadRunner:

You will need to set up two integer variables in your main action file at the top. For this example I am going to set up one called startTime and one called CurrentTime:

*/

int startTime, currentTime;

//Get the current time and save into the variable startTime:

startTime = get_time();

// now start a transaction:

lr_start_transaction("MainPage");

// then put all the statements that should be within that
// transaction. Here we are only going to have one web_url():

web_url("somewebpage", "URL=http://www.web.com", "RecContentType=text/html", LAST);

// before you end the transaction, get the current time with
// get_time() again and store into currentTime

currtentTime = get_time();

// set up an "if" statement to determine if you should manually
//fail the transaction or let it pass

if (currentTime - startTime > 1500)
{
lr_end_transaction("MainPage", LR_FAIL);
}
else
{
lr_end_transaction("MainPage", LR_PASS);
}
Subscribe to Our Podcasts
Our Clients Include…
  • Deloitte Services
  • Coventry Healthcare
  • CSX
  • Fifth Third Bank
  • HealthStream
  • Kroger
  • Max Technical Training
  • MPS Group
  • Sarasota Memorial Hospital
  • Take Charge America
  • Streamline Health Inc.
Our Contributors
Click Name for Full Profile