Jay Harris is Cpt. LoadTest

a .net developers blog on improving user experience of humans and coders
Home | About | Speaking | Contact | Archives | RSS
 
Filed under: LoadRunner | Performance | Testing

For my needs, the biggest hole in Mercury LoadRunner is its lack of page size monitoring. LoadRunner can monitor anything else imaginable, including transaction counts, transaction times, errors, and all Windows Performance Monitor metrics. However, monitoring page size, download times, and HTTP Return codes are only available through programming.

The following function will monitor the page size of all responses, logging an error if it exceeds you specified limit, as well as track all values on the user-defined graphs.

si_page_size_limit(int PageLimit, char* PageName, char *PageURL, long TransactionID){
//
// Page Size Limit Monitor
// Author: Jay Harris, http://www.cptloadtest.com, (c) 2004 Jason Harris
// License: This work is licensed under a
//    Creative Commons Attribution 3.0 United States License.
//    http://creativecommons.org/licenses/by/3.0/us/
//
// Created: 10-Aug-2004
// Last Modified: 10-May-2005, Jay Harris
//
// Description:
// Logs an error to the log, pass or fail, including the applicable status, if logging is enabled.
// Plots page size datapoint to User Defined graph.
//
// Inputs:
// int PageLimit Maximum page size allowed, in bytes
// char* PageName Name of the page, such as the Title. For identification in logs.
// char* PageURL URL of the page. For reference in logs. FOr identification in logs.
// long TransactionID Transaction ID for the current request.
// Note: Transaction must be explicitly opened via lr_start_transaction_instance.
// Note: TransactionID is returned by lr_start_transaction_instance.
//
 
    int iPageSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
    char DataPointName[1024] = “Response Size [”;
    strcat(DataPointName, PageName);
    strcat(DataPointName, “]”);

    if (PageLimit < iPageSize) {
        lr_continue_on_error(1);
        lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
	    “Page Size Check FAILED - %s [%s] exceeds specified page size limit of %d (Total: %d)”,
	    PageName,PageURL,PageLimit,iPageSize);
        lr_continue_on_error(0);
    } else {
        lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
	    “Page Size Check PASSED - %s [%s] meets specified page size limit of %d (Total: %d)”,
	    PageName,PageURL,PageLimit,iPageSize);
    }
    if (lr_get_trans_instance_status(TransactionID) == LR_PASS) {
        lr_user_data_point_instance_ex(DataPointName,iPageSize,TransactionID,DP_FLAGS_EXTENDED_LOG);
    }
    return 0;
}
Tuesday, 10 May 2005 14:51:58 (Eastern Daylight Time, UTC-04:00)  #    Comments [6] - Trackback

Tuesday, 20 January 2009 07:01:11 (Eastern Standard Time, UTC-05:00)
Have tried this code. But it not worked. Giving several errors.

Here is the total code in a .usr file that I put.

==============================================================

#include "web_api.h"

Action()
{
int si_page_size_limit(int PageLimit, char* PageName, char *PageURL, long TransactionID);
{
int iPageSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
char DataPointName[1024] = "Response Size [";
strcat(DataPointName, PageName);
strcat(DataPointName, "]");

if (PageLimit < iPageSize)
{
lr_continue_on_error(1);
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
"Page Size Check FAILED - %s [%s] exceeds specified page size limit of %d (Total: %d)",
PageName,PageURL,PageLimit,iPageSize);
lr_continue_on_error(0);
}
else
{
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
"Page Size Check PASSED - %s [%s] meets specified page size limit of %d (Total: %d)",
PageName,PageURL,PageLimit,iPageSize);
}
if (lr_get_trans_instance_status(TransactionID) == LR_PASS)
{
lr_user_data_point_instance_ex(DataPointName,iPageSize,TransactionID,DP_FLAGS_EXTENDED_LOG);
}

return 0;
}
return 0;
}

============================================

On compiling It is generating errors like following.

===========================================

Action.c (6): illegal expression
Action.c (6): syntax error; found `PageLimit' expecting `)'
Action.c (6): syntax error; found `PageLimit' expecting `;'
Action.c (6): undeclared identifier `PageLimit'
Action.c (6): illegal expression
Action.c (6): undeclared identifier `PageName'
Action.c (6): illegal expression
Action.c (6): undeclared identifier `PageURL'
Action.c (6): illegal expression
Action.c (6): syntax error; found `TransactionID' expecting `;'
Action.c (6): undeclared identifier `TransactionID'
Action.c (6): syntax error; found `)' expecting `;'
Action.c (6): illegal statement termination
Action.c (6): skipping `)'
Action.c (48): warning: unreachable code

I have modified the script like the following.

=========================================
#include "web_api.h"

Action()
{
int si_page_size_limit();
{
int PageLimit = 500;
char* PageName = "Google";
char *PageURL = "http://google.co.in";
long TransactionID = 2;

int iPageSize = web_get_int_property(HTTP_INFO_DOWNLOAD_SIZE);
char DataPointName[1024] = "Response Size [";
strcat(DataPointName, PageName);
strcat(DataPointName, "]");

if (PageLimit < iPageSize)
{
lr_continue_on_error(1);
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
"Page Size Check FAILED - %s [%s] exceeds specified page size limit of %d (Total: %d)",
PageName,PageURL,PageLimit,iPageSize);
lr_continue_on_error(0);
}
else
{
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG,
"Page Size Check PASSED - %s [%s] meets specified page size limit of %d (Total: %d)",
PageName,PageURL,PageLimit,iPageSize);
}
if (lr_get_trans_instance_status(TransactionID) == LR_PASS)
{
lr_user_data_point_instance_ex(DataPointName,iPageSize,TransactionID,DP_FLAGS_EXTENDED_LOG);
}

return 0;
}
return 0;
}

=========================================================

This removed errors but I am still not getting proper results.


Samrat Mukherjee
Tuesday, 20 January 2009 07:14:08 (Eastern Standard Time, UTC-05:00)
In addtion to that can you please explain where will I gat the details about the page sizes?
Samrat Mukherjee
Tuesday, 20 January 2009 09:11:17 (Eastern Standard Time, UTC-05:00)
Samrat,

si_page_size_limit is a function, not a line of code. It cannot be nested inside of your Action function, or any other function, as functions cannot be nested in C programming. Aside from incorrectly locating it within your script, your code is also not an exact copy, such as how you have placed a semi-colon after the function signature. Also, note that removing the comment block constitutes violation of the license. Your compiler errors will be eliminated by pasting this code, exactly as written, into your script's code outside of another function.

This function must then be executed from somewhere else in your script, such as executing it immediately after a web_url request has been made. Please see the comment block within si_page_size_limit for details on inputs, such as passing in the maximum number of bytes allowed for that request, the title (for graphing & logging use), the URL (also for graphing & logging use), and the Transaction ID; the transaction can be retrieved from lr_start_transaction_instance (please see the LoadRunner documentation for more information on lr_start_transaction_instance).

Finally, when it is working properly, the data is displayed in the User Defined graphs within LoadRunner Controller.

-- JH
Friday, 14 October 2011 09:31:46 (Eastern Daylight Time, UTC-04:00)
Is this how you would set up your HTTP size monitoring? (sorry, I have not figured out how to make the code pretty)

//--------------------------------------------------------------------------------------------------
// The following should be in the vuser_init procedure
vuser_init()
{
return 0;
}

int txnHandle; // There should be one txnHandle int variable for each transaction in the LR script.
int MAX_PAGE_SIZE = 1048576; // 1MB, others may have different size limitations

si_page_size_limit(int PageLimit, char* PageName, char *PageURL, long TransactionID)
{
//
// Page Size Limit Monitor
// Author: Jay Harris, http://www.cptloadtest.com, (c) 2004 Jason Harris
// License: This work is licensed under a
// Creative Commons Attribution 3.0 United States License.
// http://creativecommons.org/licenses/by/3.0/us/
//
// Created: 10-Aug-2004
// Last Modified: 10-May-2005, Jay Harris

// Rest of si_page_size_limit omitted.
.
.
.
return 0;
}

//--------------------------------------------------------------------------------------------------

// The following is an example for running download size monitoring.
// This kind of code would be scattered throughout the Action procedures.

lr_start_transaction_instance("TransactionName", 0);
si_page_size_limit(
MAX_PAGE_SIZE,
"pageName",
"http://some.page.URL",
txnHandle);

// Code for actually interacting with the page.

lr_stop_transaction_instance(txnHandle);

// Other LR code, some of which may involve invoking the transaction again.

//--------------------------------------------------------------------------------------------------

// The following is an example vuser_end procedure
vuser_end()
{
// End each transaction
lr_end_transaction_instance(txnHandle,LR_PASS);

return 0;
}

//--------------------------------------------------------------------------------------------------
Mike McAngus
Friday, 14 October 2011 11:55:08 (Eastern Daylight Time, UTC-04:00)
The first code line in the "example for running download size monitoring" should read:
lr_start_transaction_instance("TransactionName", txnHandle);
Mike McAngus
Friday, 14 October 2011 12:17:33 (Eastern Daylight Time, UTC-04:00)
More duh! (Sorry I can't simply delete these comments and start over).

1. The txnHandle is supposed to be long.
2. The txnHandle should be initialized in vuser_init as:
{
txnHandle = lr_start_transaction_instance("TransactionName", 0);
lr_start_transaction_instance(txnHandle);
return 0;
}

So Jay, any comments on my obviously limited knowledge of LoadRunner and your function?
Mike McAngus
OpenID
Please login with either your OpenID above, or your details below.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

[Captcha]Enter the code shown (prevents robots):

Live Comment Preview