LR耗时统计函数例子

上一篇 / 下一篇  2012-05-30 16:22:23 / 个人分类:LoadRunner


/*********************************
说明:LoadRunner中每一步都是需要消耗时间的。
所谓耗时(Wasted Time)解释如下:
Wasted time is time spent on activities whose purpose is to support test analysis, but would never be performed by a browser user, for example, time spent keeping transaction statistics for later reporting. Wasted time is calculated internally by LoadRunner. Your script. can also add wasted time with lr_wasted_time.

Sometimes, you may enter activities in a script. that your do not want reported as part of the transaction statistics. Generally, these are activities related to record keeping, logging, or custom analysis. If you enhance the script. with steps whose durations should not be included in the test statistics, you can track the time used by these steps with lr_start_timer and lr_end_timer. Then, the function lr_wasted_time is used for adding this user-determined time to the internally generated wasted time.

You can retrieve the total wasted time (both that generated by LoadRunner automatically and that added with lr_wasted_time) with the function lr_get_transaction_wasted_time, or with lr_get_trans_instance_wasted_time, as appropriate. *///*******************************

Action()
{
    int i, baseIter = 1000;
    char dude[1000];
    double wasteTime, actualElapsedTime;
    merc_timer_handle_t MasterT, timer;

    // Examine the total elapsed time of the action
 // MasterT以秒为单位并以此为开始计算时长起点(秒)
    MasterT = lr_start_timer();
 
    lr_start_transaction("Demo"); //Start transaction

    // Create some elapsed time for the transaction
    for (i=0; i< (10 * baseIter); ++i)
            sprintf(dude,
                "This is the way we create elapsed time artificially = %d", i);       

 // Add some think time
    lr_think_time(0.5);

    // Create some wasted time and record it with timer
    timer = lr_start_timer(); ////timer以秒为单位并以此为计算时长起点(秒)。
    for (i=0; i< (5 * baseIter); ++i)
            sprintf(dude,
                "This is the way we waste time in a script. = %d", i);

    wasteTime = lr_end_timer(timer); //停止timer计时器,并返回消耗的时长(秒)。
    lr_output_message("User created waste time = %lf", wasteTime);
    lr_output_message("Before lr_waste_time: Duration = %lf - Waste = %lf",        
        lr_get_transaction_duration("Demo"),
        lr_get_transaction_wasted_time("Demo"));

    /* Convert Timer in seconds to wasted time in milliseconds
     and add to internally generated waste time */
    wasteTime *= 1000;
    lr_wasted_time(wasteTime);

    lr_output_message("After lr_waste_time: Duration = %lf - Waste = %lf",
            lr_get_transaction_duration("Demo"),
            lr_get_transaction_wasted_time("Demo"));

    lr_output_message("Think time = %lf",
        lr_get_transaction_think_time("Demo"));

    lr_end_transaction("Demo", LR_AUTO);
    actualElapsedTime = lr_end_timer(MasterT); //统计总耗时(秒)。
    lr_output_message("Total Elapsed time for Action = %lf", actualElapsedTime);

    return 0;

}


 


TAG:

 

评分:0

我来说两句

Open Toolbar