初識loadrunner wasted time

ora_erin發表於2014-05-15
關於時間的幾個函式:
lr_get_transaction_duration得到transaction執行到當前位置的duration,包含事務的響應時間和wasted time,單位是s;

著重理解下wasted time:
wasted time包括事務中函式自身執行所消耗的時間,這個時間是loadrunner自動會計的,計在lr_get_transaction_wasted_time裡面,還有比如C語言等外部介面進行處理的時間這個loadrunner不會自動計,但是我們可以通過lr_start_timer(單位是s)、lr_end_timer(單位是s)、lr_wasted_time(這個函式的形參中wasted time的單位是毫秒,所以通過timer計的時間需要乘上1000)等函式手動計入lr_get_transaction_wasted_time裡面

下面來驗證下:
Action()
{
    int i, baseIter = 200; 
    char dude[200]; 
    double wasteTime; 
    merc_timer_handle_t timer; 

    lr_start_transaction("baidu");

    web_add_cookie("BAIDUID=63CCB143FE1734437DBED1D457D18E3E:FG=1; DOMAIN=www.baidu.com");

    web_add_cookie("BAIDUID=63CCB143FE1734437DBED1D457D18E3E:FG=1; DOMAIN=passport.baidu.com");

    web_add_cookie("BAIDUID=63CCB143FE1734437DBED1D457D18E3E:FG=1; DOMAIN=suggestion.baidu.com");

web_url("www.baidu.com", 
"URL=http://www.baidu.com/", 
"Resource=0", 
"RecContentType=text/html", 
"Referer=", 
"Snapshot=t1.inf", 
"Mode=HTML", 
EXTRARES, 
"Url=http://s1.bdstatic.com/r/www/cache/static/global/img/icons_37d13939.png", ENDITEM, 
"Url=http://s1.bdstatic.com/r/www/cache/static/sug/js/bdsug_31b8d653.js", ENDITEM, 
"Url=/favicon.ico", "Referer=", ENDITEM, 
"Url=http://passport.baidu.com/passApi/js/uni_login_wrapper.js?cdnversion=1400118095796&_=1400118095656", ENDITEM, 
"Url=http://suggestion.baidu.com/su?
wd=&zxmode=1&json=1&p=3&sid=4948_6429_1450_5223_6505_4760_6017_6462_6428_6456_6454&cb=jQuery110208749060739643981_1400118095657&_=1400118095658", ENDITEM, LAST);

//在指令碼中間位置,記錄此時事務自身函式消耗的時間,這個是loadrunner自動計的
    lr_output_message("User created waste time to this point calculated by loadrunner = %lf", lr_get_transaction_wasted_time("baidu")); 

//使用一個測試語句手動記錄消耗的時間
    timer = lr_start_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);

    lr_output_message("User created waste time calculated by timer = %lf", wasteTime); 

    wasteTime *= 1000; 

//通過lr_wasted_time函式將wasteTime標記為wasted time
    lr_wasted_time(wasteTime); 

//通過lr_get_transaction_wasted_time函式會彙總手工記錄的消耗時間和loadrunner自動記錄的消耗時間
    lr_output_message("Total User created waste time = %lf", lr_get_transaction_wasted_time("baidu")); 

    lr_output_message("Transaction duration = %lf", lr_get_transaction_duration("baidu")); 

    lr_end_transaction("baidu", LR_AUTO);

    return 0;
}

執行日誌如下:
Virtual User Script started at : 2014-05-15 09:58:45
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31)   [MsgId: MMSG-27143]
Run Mode: HTML   [MsgId: MMSG-26000]
Run-Time Settings file: "F:\LR\baidu_open\\default.cfg"   [MsgId: MMSG-27141]
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(12): Notify: Transaction "baidu" started.
Action.c(14): web_add_cookie was successful   [MsgId: MMSG-26392]
Action.c(16): web_add_cookie was successful   [MsgId: MMSG-26392]
Action.c(18): web_add_cookie was successful   [MsgId: MMSG-26392]
Action.c(20): Downloading resource "http://s1.bdstatic.com/r/www/cache/static/global/img/icons_37d13939.png" (specified by argument number 9)   [MsgId: MMSG-26577]
Action.c(20): Downloading resource "http://s1.bdstatic.com/r/www/cache/static/sug/js/bdsug_31b8d653.js" (specified by argument number 11)  
[MsgId: MMSG-26577]
Action.c(20): Downloading resource "http://www.baidu.com/favicon.ico" (specified by argument number 13)   [MsgId: MMSG-26577]
Action.c(20): Downloading resource "http://passport.baidu.com/passApi/js/uni_login_wrapper.js?cdnversion=1400118095796&_=1400118095656" (specified by argument number 16)   [MsgId: MMSG-26577]
Action.c(20): Downloading resource "http://suggestion.baidu.com/su?wd=&zxmode=1&json=1&p=3&sid=4948_6429_1450_5223_6505_4760_6017_6462_6428_6456_6454&cb=jQuery110208749060739643981_1400118095657&_=1400118095658" (specified by argument number 18)   [MsgId: MMSG-26577]
Action.c(20): Found resource "http://www.baidu.com/img/baidu_jgylogo3.gif" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): Found resource "http://www.baidu.com/img/bdlogo.gif" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): Found resource "http://www.baidu.com/cache/global/img/gs-2.0.gif" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): Found resource "http://s1.bdstatic.com/r/www/cache/static/jquery/jquery-1.10.2.min_f2fb5194.js" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): Found resource "http://s1.bdstatic.com/r/www/cache/static/global/js/all_async_f712ea4c.js" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): Found resource "http://s1.bdstatic.com/r/www/cache/static/global/js/imsg_45172630.js" in HTML "http://www.baidu.com/"   [MsgId: MMSG-26659]
Action.c(20): web_url("www.baidu.com") was successful, 106231 body bytes, 4084 header bytes, 59 chunking overhead bytes   [MsgId: MMSG-26385]
Action.c(35): User created waste time to this point calculated by loadrunner = 0.758138
Action.c(45): User created waste time calculated by timer = 7.646098
Action.c(52): Total User created waste time = 8.404138
Action.c(53): Transaction duration = 8.745259
Action.c(55): Notify: Transaction "baidu" ended with "Pass" status (Duration: 8.7524 Wasted Time: 8.4041).
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
執行的結果也證明了我之前的理解

注:在最開始的時候,使用oracle兩層協議錄製指令碼,一直不能演示出自身函式消耗的時間,lr_get_transaction_wasted_time的值都為0,後來使用http協議可以演示出來

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26524307/viewspace-1162259/,如需轉載,請註明出處,否則將追究法律責任。