Thursday, September 13, 2012

Loadrunner Charting Custom Metrics

In Loadrunner, you can chart your own custom metrics easily by using the function lr_user_data_point.  These could include calls to the server to collect system stats, application metrics based on responses, or anything at all.  The custom metrics are then available in Loadrunner Analysis.  The following provides an example:

Script


double getMyMetric();

Action()
{
double mymetric;
int i;
for (i=0;i<100;i++) {

mymetric = getMyMetric(); 
lr_user_data_point("mymetric", mymetric); 
lr_log_message( "--- Added custom metric value = %f", mymetric );

return 0;
}


double getMyMetric()
{
    int randomInt = (rand() % 100)+1;  // Get a random number 1 - 100
double mymetric = randomInt / 100.0; // Return a double between 0  and 1
return mymetric;
}



Console Output


Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(10): Notify: Data Point "mymetric" value = 0.4800.
--- Added custom metric value = 0.480000
Action.c(10): Notify: Data Point "mymetric" value = 0.7900.
--- Added custom metric value = 0.790000
...


Analysis Output

The custom metric is then available in analysis:


A chart can be generated showing the trend of the custom data points added during the test:




No comments:

Post a Comment