Friday, November 12, 2010

My Load Test 1

My Load Test
Performance Testing with a LoadRunner focus
________________________________________
« Tips for Load Testing CORBA Applications with LoadRunner
WinRunner Coding Standards – Use Constants »
String Manipulation in LoadRunner
I think that the following question from the Mercury Support forum neatly illustrates one of the major problems with LoadRunner.
Hi all,
I have a financial application that submits the data in $ amounts. When I looked in the extended log the value is in number format like (43251) but during submission it is converted into dollar format $43,251.00.
How to convert the string into $ format? Is there any function?
Thanks in advance,
The majority of people using LoadRunner aren’t great programmers, and the ones who are aren’t necessarily great programmers in C. Fortunately, the level of skill required for most problems is not very high, and everyone muddles along as best they can.
Not surprisingly, the small proportion of problems that require more than basic knowledge of C are done poorly (or by someone else).
The most common problem that requires additional programming is basic string manipulation. Most LoadRunner scripts are written in C, and manipulating strings with C is like pulling teeth.
I would argue that Mercury’s choice to use C as LoadRunner’s main scripting language, while having the advantages of it being a solid standard, having a low performance overhead, and there being a large pool of people at least partially familiar with the language, has the unfortunate trade-off of it being…well…kind of hard for most people.
Here’s my solution to the above problem.
// This function converts a numeric string to a dollar value.
// eg. 123456 becomes $123,456.00
LPCSTR ConvertStringToDollars(char input[20]) {
int i;
// To account for the extra characters that will be added, the size of output
// should be 4 + strlen(input) + (strlen(input)/3)
char output[30];
strcpy(output,"$");
// insert a comma every third character, but not at the start.
for (i=0; i if ( ((strlen(input)-i)%3==0) && (i!=0) ) {
output[strlen(output)] = ',';
}
output[strlen(output)] = input[i];
}
strcat(output, ".00");
return output;
}
Action()
{
lr_output_message(ConvertStringToDollars("123456")); // Prints "$123,456.00"
return 0;
}
This illustrates my point perfectly. Even though the code performs a simple operation, it’s complicated, and requires knowledge of how C stores data in memory in order to implement. Possibly more importantly, implementing the solution in C takes a lot longer than it might in another language. If there are any mistakes in my code, it just proves my point even more.
As computers increase in power and the performance advantage of writing performance test scripts in C shrinks even further compared to other languages, the relative disadvantages of C will grow in the minds of testers.

This entry was posted on Wednesday, June 15th, 2005 at 11:24 pm and is filed under LoadRunner. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
10 Responses to “String Manipulation in LoadRunner”
1. Anonymous Says:
June 19th, 2005 at 3:16 pm
It’s like some kind of brain teasing challenge…
You have the following functions sprintf, strcat, strchr, strcmp, strcpy,
strdup, stricmp, strlen, strlwr, strncat, strncmp, strncpy, strnicmp,
strrchr, strset, strspn, strstr, strtok, strupr, and as many native
language features as you like. Try not to leak or overwrite memory. Your time starts now…
2. Stuart Moncrieff Says:
July 31st, 2005 at 9:37 pm
Another recent Mercury Support Forum question (and my answer) demonstrates my point also…
How to find the absolute value of a double ?
Hi,
How to find the absolute value of a double variable ?
function “abs()” gives wrong result.
Thanks & Regards
R.K
How to find the absolute value of a double ?
Your problem is that the standard C library funtion abs() is expecting its argument to be an int rather than a double. As C is a weakly typed language, the function just treats the double value as if it was an int even though the two data types are stored differently in memory. Consequently you get garbage as output.
Cheers,
Stuart.
3. Stuart Moncrieff Says:
October 19th, 2005 at 10:24 pm
I’ve said it before. Everyone who uses LoadRunner professionally should know C.
Joel Spolsky agrees with me. He says that all programmers should get Back to Basics.
4. Sam Says:
March 6th, 2006 at 11:01 pm
for (i=0;i if ( ((strlen(input)-i)%3==0) && (i!=0) ){
I used this loop as given in the above page. LR is throwing errors. please find the Error.
ction.c (7): syntax error; found `if’ expecting `;’
Action.c (7): syntax error; found `if’ expecting `)’
Action.c (12): warning: missing return value
Action.c (13): expecting an identifier
Action.c (13): syntax error; found “.00? expecting `)’
Action.c (13): skipping “.00?
Action.c (13): extraneous old-style parameter list
Action.c (14): unrecognized declaration
Action.c (15): unrecognized declaration
LPCSTR ConvertStringToDollars(char input[20])
{
int i;
char output[30];
strcpy(output, “$”);
for (i=0;i if ( ((strlen(input)-i)%3==0) && (i!=0) ){
//for (i=0; i=if ( ((strlen(input)-i)%3==0) && (i!=0) ) {
output[strlen(output)]=’,';
}
output[strlen(output)] = input[i];
}
strcat(output,”.00?);
return output;
}
Action()
{
lr_output_message(ConvertStringToDollars(”123456?)); // Prints “$123,456.00?
return 0;
}
5. Stuart Moncrieff Says:
March 7th, 2006 at 5:30 pm
The code got mangled by the content managment system (must have happened in the last upgrade).
I have corrected all the errors that were introduced. Give it another go.
Cheers,
Stuart.
6. Sam Says:
March 7th, 2006 at 5:53 pm
thanks Stuart …its working
7. Angel Says:
April 13th, 2007 at 8:25 pm
How I can extract text from the last HTTP response received by the virtual user and later to manipulate the string in the script of Loadrunner
8. Linden Says:
November 30th, 2007 at 11:49 am
I believe your output string length can be 1 char larger than necessary. As the first set of 3 digits (when reading left to right) will never require a comma in front of it.
For a string with 20 characters, 6 commas are necessary and (strlen(input)/3) = 20/3 = 6 is correct. However, for a string with 21 values, 6 commas are necessary (still) yet (strlen(input)/3) = 21/3 = 7 is incorrect. So here’s a nasty way of fixing that:
int fix=0;
if(strlen(input)%3==0) fix=1;
// should be 4 + strlen(input) + (strlen(input)/3) – fix
9. Linden Says:
November 30th, 2007 at 1:18 pm
Worth noting that SaveLen and SaveOffset Attributes for web_reg_save_param can be used to effectively pull substrings into variables which can later be concatenated to suit formatting requirements.
10. Pallavi Says:
May 20th, 2008 at 4:07 pm
Hi,
I am using for loop to repeat first transaction & after completing for loop, second transaction should start. The script work well without parameterization on one variable, but when the parameterization is used, the for loop is using same (first value) value for the entire loop. My aim is to use the sequential value of the parameter from the file. How to achieve this?

• How-to verify file downloaded
TnT Admin 1:17 am on August 28, 2009 | 0 Permalink | Reply
Tags: functions (2), Scripting (15)
Often there is a need to verify the validity of the file being downloaded by the script. Under normal circumstances, if the file is a PDF or excel file, it will be returned/transmitted in binary (when you turned on replay log). In this way, unlike conventional functional tool, LoadRunner is unable to verify if the file downloaded is valid.
In order to circumvent that, we use web_get_int_property API to retrieve the file size. This file size will then be used to make comparison with the actual known file size on the server. For usage of web_get_int_property, you can refer to the Function Reference available in Vugen.
On a brief overview, place the web_get_int_property APT after the request (web_url, web_custom_request, etc.) made for the file (PDF/excel). I’ve extracted examples from LoadRunner Yahoo Groups and list them below for your convenience.
Example 1:
lr_message(”%ld”,web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE));
web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
Note, HTTP_INFO_DOWNLOAD_SIZE does not give the actual size of PDF file. This HTTP_INFO_DOWNLOAD_SIZE gets the body bytes, header bytes, and chunk bytes. Therefore, you may need to fine tune the script to determine a range value of the PDF file size due to the header and chunk bytes.
Example 2:
float fFileDownloadSize, fFileDownloadTime, fFileDownloadRate;
funcFileDownload()
{
fFileDownloadSize = (web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE)/1024.);
//in kilobytes
fFileDownloadTime = (web_get_int_property(HTTP_INFO_DOWNLOAD_TIME)/1000.);
//in seconds
fFileDownloadRate = fFileDownloadSize/fFileDownloadTime; //in KB/s
lr_output_message(”Size of download was %.0f kilobytes; Time of download was %.3f seconds”, FileDownloadSize, fFileDownloadTime);
lr_output_message(”Rate of download was %.2f KB/sec”, fFileDownloadRate);
return 0;
}
Example 3:
long DSize=0;
float DTime=0;
DSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
lr_output_message(”DSize is: %.2ld Bytes”, DSize);
lr_output_message(”File Download size is: %.2ld KB”, DSize /1024);
DTime = web_get_int_property(HTTP_INFO_DOWNLOAD_TIME);
lr_output_message(”File Download Time is:%.2f Seconds”, DTime / 1000);
Share and Enjoy:


Australia » Tech Tips » Changing Pacing time while a test is running
Changing Pacing time while a test is running
February 23rd, 2009 Posted by Stuart Moncrieff No Comments »
You might have noticed that once you have started your load test, it is possible to increase the number of transactions per hour by adding virtual users, but not by changing the pacing time.
The VuGen Pacing runtime setting is only read at the start of the test so, to change it, it is necessary to stop the test, then make the change and restart.
Fortunately (if you need to), you can write code to control the pacing of your virtual users instead of using the runtime settings. If you write code to pick up a pacing setting from a file, and check the file on each iteration, then you can cause your script to delay for the right amount of time to meet your desired transaction rate.

Obviously, if you are controlling the pacing yourself, you should have the Pacing runtime setting set to “start new iteration as soon as the previous iteration ends”. And if you are using think time for the pacing delay, you should have the Think Time runtime setting set to “replay think time” (or use think time that can’t be ignored).

2 comments: