我正在尝试在LoadRunner脚本中创建一个循环,该循环将一直运行直到起搏时间等于零。下面是硬编码脚本。
在这里,我需要对运行时间设置中定义的起搏时间进行硬编码。我们有什么功能可以将运行时设置中定义的起搏时间获取到变量。
int pacingtime = 600;
starttime = time();
<Web Requests>
endtime = time();
diff = endtime - starttime;
waittime = pacingtime - diff;
label1:
s1 = time();
<Web Custom Requests>
s2 = time();
s3 = s2 - s1
count = waittime - s3;
waittime = waittime - s3;
if (count < 0)
goto label1;
else
goto label2;
label2:
return 0;
谢谢!
答案 0 :(得分:0)
考虑此代码及其对您问题的影响。在运行时设置中,将迭代次数设置为100,且不设置步调。在其他属性中,为“起搏”添加一个值为2的值。执行并查看日志。
long pacing;
vuser_init()
{
pacing=lr_get_attrib_long("pacing");
lr_message("pacing: %d",pacing);
if (pacing==0){
lr_message("Illegal value");
}
return 0;
}
Action()
{ double how_long;
merc_timer_handle_t timer=lr_start_timer();
sleep(rand()%(pacing*1000)+1000);
how_long=lr_end_timer(timer);
if ( how_long >= pacing )
{
lr_message("delayed %lf seconds, longer than %d seconds\r\nEnding Iterations",
how_long,
pacing);
return -1;
}
else
{
lr_message("delayed %lf seconds, less than %d seconds\r\nSleeping %lf seconds",
how_long,
pacing,
((double)pacing-how_long));
}
return 0;
}
vuser_end()
{
return 0;
}