LoadRunner去除事物中的程序的执行时间
作者:网络转载 发布时间:[ 2015/5/21 14:04:55 ] 推荐标签:性能测试工具
以上代码,lr_get_transaction_wasted_time使用注意点:
1、要在lr_end_transaction之前使用,因为它只能对当前处于“运行状态”的事务返回>0的结果。
2、调用lr_get_transaction_wasted_time之前,要使用lr_wasted_time移除损耗时间。
关于时间的几个函数:
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:LRaidu_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协议可以演示出来
Action()
{
int i=0;
int j=0;
int l;
double time_elapsed, duration, waste;
merc_timer_handle_t timer;
for (l=1;l<=100;l++) {
lr_start_transaction("测试");
timer = lr_start_timer();
//lr_think_time(4);
time_elapsed = lr_end_timer(timer);
// Convert to millisecond.s
waste = time_elapsed * 1000;
if(waste>2)
{
lr_end_transaction("测试", LR_FAIL);
lr_output_message("时间= %f",waste);
i=i+1;
}
else
{
lr_end_transaction("测试", LR_PASS);
lr_output_message("时间= %f",waste);
j=j+1;
};
};
lr_output_message("成功次数为= %d",j);
lr_output_message("失败次数为= %d",i);
return 0;
}
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系SPASVO小编(021-61079698-8054),我们将立即处理,马上删除。
相关推荐
使用loadrunner进行压力测试遇到的问题总结LoadRunner检查点loadrunner11的移动端性能测试之脚本录制验证LoadRunner对Ajax内容的校验LoadRunner使用代理录制脚本LoadRunner运行乱码解决方法LoadRunner利用代理模式录制手机脚本loadrunner11中java vuser引用jar包使用LoadRunner监控Windows资源LoadRunner小技巧集锦LoadRunner提高篇:插入检查点与关联函数loadrunner怎么解决录制完成后脚本为空LoadRunner判断是否服务器连接池瓶颈LoadRunner中对Https证书的配置Loadrunner入门篇-Vuser发生器LoadRunner录制手机APP脚本
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11热门文章
常见的移动App Bug??崩溃的测试用例设计如何用Jmeter做压力测试QC使用说明APP压力测试入门教程移动app测试中的主要问题jenkins+testng+ant+webdriver持续集成测试使用JMeter进行HTTP负载测试Selenium 2.0 WebDriver 使用指南