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;

}