loadrunner之用户自定义数据采集

     Loadrunner中lr_user_data_point、lr_user_data_point_instance两个函数可以用来记录一条自定义的Vuser运行数据,并将其输出到测试结果中,最后可以通过分析工具Analysis来分析数据采集情况。两者之间的区别是lr_user_data_point_instance函数可以用来记录指定事物实例的自定义数据。

函数语法:

int lr_user_data_point (const char *sample_name, double value);

long lr_user_data_point_instance (const char *sample_name, double value, long transaction_handle);

例一:

Action()
{


web_set_max_html_param_len(
"1024");

web_reg_save_param(
"JSESSIONID5",
"LB/IC=jsessionid=",
"RB/IC=\"",
"Ord=11",
"Search=body",
"RelFrameId=1",
LAST);

web_url(
"web",
"URL=http://172.19.201.188:7001/web/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=images/login/3.swf", ENDITEM,
LAST);

web_reg_find(
"Search=Body",
"SaveCount=times",
"Text={username}",
LAST);

web_submit_data(
"logon.do;jsessionid=schvTJJpR1BCBYYv9hhhn6k5zMwzZJ7JtTp5yPKvjBm6QpJv1DsN!-1783399523",
"Action=http://172.19.201.188:7001/web/pf/authentication/logon.do;jsessionid={JSESSIONID5}",
"Method=POST",
"TargetFrame=_parent",
"RecContentType=text/html",
"Referer=http://172.19.201.188:7001/web/",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=kind", "Value=1", ENDITEM,
"Name=clientIPAddr", "Value=", ENDITEM,
"Name=clientMacAddr", "Value=", ENDITEM,
"Name=clientMachineName", "Value=", ENDITEM,
"Name=username", "Value={username}", ENDITEM,
"Name=password", "Value=1", ENDITEM,
LAST);

//lr_output_message("count=%d",atoi(lr_eval_string ("{times}")));

if(atoi(lr_eval_string ("{times}"))>0) {

web_url(
"close.html",
"URL=http://172.19.201.188:7001/web/pf/close.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);

web_url(
"redirectURL.jsp",
"URL=http://172.19.201.188:7001/web/pf/redirectURL.jsp?redirect=true&kind=logon&U=1309938062295",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t4.inf",
"Mode=HTML",
LAST);

web_url(
"frameWork.jsp",
"URL=http://172.19.201.188:7001/web/pf/webdesk/frameWork.jsp",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
EXTRARES,
"Url=/web/styles/default/frame/images/lineBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/version.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-Table.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-info.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-login.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/images/logo_default.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/linemid.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/split.jsp", ENDITEM,
"Url=/web/styles/default/frame/images/button-help.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/ArrowLeft.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/split.jsp", ENDITEM,
"Url=/web/styles/default/images/popup_bg_menu.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/mainMessage.jsp?U=", ENDITEM,
"Url=/web/styles/default/frame/images/line1.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/tabBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/line.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/naviMenuselect.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/lineleft.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonOff.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon1.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon4.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon3.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon2.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonOn.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=system/webmessageshow.jar", "Referer=", ENDITEM,
LAST);

web_url(
"commonAction.do",
"URL=http://172.19.201.188:7001/web/cc/core/common/commonAction.do?action=ajaxRequest&ajaxRequestClass=epm.cc.core.web.common.action.AutoRefreshSessionAjaxRequest&ccuserNo=9001",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://172.19.201.188:7001/web/pf/webdesk/top/navimenu.jsp",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);

lr_user_data_point(
"username",
atoi(lr_eval_string(
"{username}")));
lr_end_transaction_instance(instance_id, LR_PASS);
}

else

lr_end_transaction_instance(instance_id, LR_FAIL);

return 0;

}

 例二:

Action()
{
long instance_id;

web_set_max_html_param_len(
"1024");

web_reg_save_param(
"JSESSIONID5",
"LB/IC=jsessionid=",
"RB/IC=\"",
"Ord=11",
"Search=body",
"RelFrameId=1",
LAST);

web_url(
"web",
"URL=http://172.19.201.188:7001/web/",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTML",
EXTRARES,
"Url=images/login/3.swf", ENDITEM,
LAST);

web_reg_find(
"Search=Body",
"SaveCount=times",
"Text={username}",
LAST);

web_submit_data(
"logon.do;jsessionid=schvTJJpR1BCBYYv9hhhn6k5zMwzZJ7JtTp5yPKvjBm6QpJv1DsN!-1783399523",
"Action=http://172.19.201.188:7001/web/pf/authentication/logon.do;jsessionid={JSESSIONID5}",
"Method=POST",
"TargetFrame=_parent",
"RecContentType=text/html",
"Referer=http://172.19.201.188:7001/web/",
"Snapshot=t2.inf",
"Mode=HTML",
ITEMDATA,
"Name=kind", "Value=1", ENDITEM,
"Name=clientIPAddr", "Value=", ENDITEM,
"Name=clientMacAddr", "Value=", ENDITEM,
"Name=clientMachineName", "Value=", ENDITEM,
"Name=username", "Value={username}", ENDITEM,
"Name=password", "Value=1", ENDITEM,
LAST);

//lr_output_message("count=%d",atoi(lr_eval_string ("{times}")));

if(atoi(lr_eval_string ("{times}"))>0) {

instance_id
= lr_start_transaction_instance("withresponse", 0);

web_url(
"close.html",
"URL=http://172.19.201.188:7001/web/pf/close.html",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t3.inf",
"Mode=HTML",
LAST);

web_url(
"redirectURL.jsp",
"URL=http://172.19.201.188:7001/web/pf/redirectURL.jsp?redirect=true&kind=logon&U=1309938062295",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t4.inf",
"Mode=HTML",
LAST);

web_url(
"frameWork.jsp",
"URL=http://172.19.201.188:7001/web/pf/webdesk/frameWork.jsp",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t5.inf",
"Mode=HTML",
EXTRARES,
"Url=/web/styles/default/frame/images/lineBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/version.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-Table.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-info.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/button-login.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/images/logo_default.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/linemid.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/split.jsp", ENDITEM,
"Url=/web/styles/default/frame/images/button-help.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getInfobar.do", ENDITEM,
"Url=/web/styles/default/frame/images/ArrowLeft.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/split.jsp", ENDITEM,
"Url=/web/styles/default/images/popup_bg_menu.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/mainMessage.jsp?U=", ENDITEM,
"Url=/web/styles/default/frame/images/line1.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/tabBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/line.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/naviMenuselect.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/top/getNaviMenu.do", ENDITEM,
"Url=/web/styles/default/frame/images/lineleft.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonOff.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon1.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon4.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon3.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=menu/images/item/big/icon2.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonOn.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=/web/styles/default/frame/images/buttonBg.gif", "Referer=http://172.19.201.188:7001/web/pf/webdesk/left/getMenuFromXml.do", ENDITEM,
"Url=system/webmessageshow.jar", "Referer=", ENDITEM,
LAST);

web_url(
"commonAction.do",
"URL=http://172.19.201.188:7001/web/cc/core/common/commonAction.do?action=ajaxRequest&ajaxRequestClass=epm.cc.core.web.common.action.AutoRefreshSessionAjaxRequest&ccuserNo=9001",
"TargetFrame=",
"Resource=0",
"RecContentType=text/html",
"Referer=http://172.19.201.188:7001/web/pf/webdesk/top/navimenu.jsp",
"Snapshot=t6.inf",
"Mode=HTML",
LAST);

lr_user_data_point_instance(
"username",
atoi(lr_eval_string(
"{username}")), instance_id);
lr_end_transaction_instance(instance_id, LR_PASS);
}

else

lr_end_transaction_instance(instance_id, LR_FAIL);

return 0;
}

     上面两脚本在Controller中执行完成后,就可以在Analysis中查看运行结果。启动分析工具后,点击Graph>>Add New Graph或者ctrl+a快捷键来打开新采集到得图表,可以看到User Ddfined Data Points下面有Ddfined Data(Sum)和Ddfined Data(Average)两类图表。双击对应的图表就会将用户自定义的数据分析结果添加到网页细分图里面。

     依次点击菜单Report>>Crystal Report>>Performance Report>>Data Point,就可以查看到各个Vuser运行时,用户自定义数据采集出来的具体信息了,如下图所示。对于自定义的一些相关业务交易信息之类的,在性能分析方面可以比较深入的分析出程序的瓶颈。

posted on 2011-07-06 20:04  dfine.sqa  阅读(4589)  评论(0编辑  收藏  举报

导航