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, May 10, 2005 2:51:58 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [3] - Trackback

Tuesday, January 20, 2009 7:01:11 AM (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, January 20, 2009 7:14:08 AM (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, January 20, 2009 9:11:17 AM (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
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)  

Enter the code shown (prevents robots):

Live Comment Preview