lr_start_timer:

函数的功能:

为了计算时间更加精确,可以用这个函数去掉LR自身的检查点所浪费的时间。如text check and image time

Action()
{
double time_elapsed;
merc_timer_handle_t timer; web_url("487989.html",
"URL=http://www.cnblogs.com/tester2test/archive/2006/08/28/487989.html",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t2.inf",
"Mode=HTML",
LAST); lr_start_transaction("download"); timer = lr_start_timer(); Download("http://files.cnblogs.com/tester2test/xncssj.pdf", "http://www.cnblogs.com/tester2test/archive/2006/08/28/487989.html", "c:\\test.pdf", "wb"); time_elapsed = lr_end_timer(timer); lr_wasted_time(time_elapsed * ); lr_end_transaction("download", LR_AUTO); return ;
}
double time_elapsed, duration, waste;

merc_timer_handle_t timer;

        lr_start_transaction("sampleTrans");

        web_url("index.htm",

               "URL=http://localhost/index.htm",

               "TargetFrame=",

               "Resource=0",

               "RecContentType=text/html",

               "Referer=",

               "Snapshot=t1.inf",

               "Mode=HTML",

               LAST);

        timer = lr_start_timer();

/* Do some checks the duration of which

is not to be included in the transaction. */

        web_image_check("ImgCheck1",

               "src=index_files/image002.jpg",

               LAST);

        web_image_check("ImgCheck2",

               "src=index_files/planets.gif",

               LAST);

// How long did the tests take in seconds.

        time_elapsed = lr_end_timer(timer);

// Convert to millisecond.s

        waste = time_elapsed * ;

/* Remove the time the checks took from

        the transaction. */

        lr_wasted_time(waste);

         lr_end_transaction("sampleTrans", LR_AUTO);

lr_get_transaction_duration:返回事件执行到此处所用的时间

C 语言:

double lr_get_transaction_duration(const char *transaction);

Example:

Action()

{

      double Connect_trans_time;  // 接收函数返回值

      double Move_trans_time;

      lr_start_transaction("Connect_trans");

      lr_create_socket("socket0","TCP","RemoteHost = localhost:1111",LrsLastArg);  // IP和端口仅供参考

      //......(others)

      // 调用 lr_get_transaction_duration() 函数

      Connect_trans_time = lr_get_transaction_duration("Connect_trans");

      lr_end_transaction("Connect_trans",LR_AUTO);

      lr_start_transaction("Move_trans");

      //......(others)

      Move_trans_time = lr_get_transaction_duration("Move"); // 获取 Move_trans 事件执行到此处所用时间

      lr_end_transaction("Move_trans",LR_AUTO);

      lr_output_message("The duration up to the <Connect_trans_time> is %f seconds",Connect_trans_time);

      lr_output_message("The duration up to the <Move_trans_time> is %f seconds",Move_trans_time);

      return ;

}

Action.c(): Notify: Transaction "Connect_trans" ended with "Pass" status (Duration:1.1164)

Action.c(): Notify: Transaction "Move_trans" ended with "Pass" status (Duration: 0.4036)

Action.c(): The duration up to the <Connec_trans_time> is 1.116110 seconds

Action.c(): The duration up to the <Move_trans_time> is 0.403350 seconds

根据业务操作分离出脚本中的两个事件,Connect(连接DB)操作和Move(拖屏)操作,Contro中运行结果显示“拖屏”消耗时间远大于“连接”消耗时间,这同程序设计与实现的实际情况不符。

所以调用了【lr_get_transaction_duration();】函数来验证事件的运行时间,进一步分析性能问题原因所在。

验证结果已证明拖屏操作消耗时间的确小于连接操作消耗时间。

lr_get_transaction_wasted_time:函数用于返回指定事物当前的损耗时间(wasted time)。

函数统计的是事物开始到此函数位置,lr自身的浪费时间(如:执行关联、检查点等函数的时间)。
 
损耗时间通常是指脚本消耗在为了支持测试分析而做的操作时间。这些操作不会被实际用户所执行。
 
例如一些循环赋值操作或插入检查点操作。消耗的时间有lr_wasted_time函数在

lr_get_transaction_wasted_time函数之前移除了,移除后才得到对应的结果。

函数语法结果

double lr_get_transaction_wasted_time (const char * transaction);

参数 transaction 为事物名称

使用lr_get_transaction_wansted_time
函数必须注意,

一它只能对当前运行状态的事物才能返回大于等于0的结果,否则返回小于0的结果。

二是他使用之前应调用lr_wansted_time 函数移除过损耗时间
wasted time,否则lr_get_transaction_wansted_time将返回0。

附代码如下:
timer=lr_start_timer();
web_find("web_find",
"what=9000000022",
LAST);
time_elapsed=lr_end_timer(timer); lr_output_message("find时间为:%f",time_elapsed);
lr_output_message("事务当前的损耗时间为:%f",lr_get_transaction_wasted_time("登陆")); //先算出从事务开始到现在lr自身的浪费时间。因为无损耗,所以,lr_get_transaction_wasted_time= 0s 。 //使用lr_wasted_time()函数为事物添加浪费时间
lr_wasted_time(time_elapsed*); //Wasted Time=lr自身的浪费时间(0s)+第三方时间的开销(time_elapsed*1000s))
lr_output_message("find时间为:%f,事务当前的损耗时间为:%f",time_elapsed,lr_get_transaction_wasted_time("登陆"));
Action()
{
int i, baseIter = ; char dude[]; double wasteTime, actualElapsedTime; merc_timer_handle_t MasterT, timer; // Examine the total elapsed time of the action MasterT = lr_start_timer(); //Start transaction lr_start_transaction("Demo"); // Create some elapsed time for the transaction for (i=; i< ( * baseIter); ++i)
sprintf(dude, "This is the way we create elapsed time artificially = %d", i); // Add some think time lr_think_time(0.5); // Create some wasted time and record it with timer timer = lr_start_timer(); for (i=; i< ( * 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 = %lf", wasteTime); lr_output_message("Before lr_waste_time: Duration = %lf - Waste = %lf", lr_get_transaction_duration("Demo"), lr_get_transaction_wasted_time("Demo")); /* Convert Timer in seconds to wasted time in milliseconds and add to internally generated waste time */ wasteTime *= ; lr_wasted_time(wasteTime); lr_output_message("After lr_waste_time: Duration = %lf - Waste = %lf", lr_get_transaction_duration("Demo"), lr_get_transaction_wasted_time("Demo")); lr_output_message("Think time = %lf", lr_get_transaction_think_time("Demo")); lr_end_transaction("Demo", LR_AUTO); actualElapsedTime = lr_end_timer(MasterT); lr_output_message("Total Elapsed time for Action = %lf", actualElapsedTime); return ;
} 结果:
Starting iteration .
Starting action Action.
Action.c(): Notify: Transaction "Demo" started.
Action.c(): User created waste time = 15.768059
Action.c(): Before lr_waste_time: Duration = 65.147478 - Waste = 0.000000
Action.c(): After lr_waste_time: Duration = 65.153110 - Waste = 15.768000
Action.c(): Think time = 0.000000
Action.c(): Notify: Transaction "Demo" ended with "Pass" status (Duration: 65.1589 Wasted Time: 15.7680).
Action.c(): Total Elapsed time for Action = 65.170579
Ending action Action.
Ending iteration .

lr_get_transaction_wasted_time函数用于返回指定事物当前的损耗时间(wasted time)。     损耗时间通常是指脚本消耗在为了支持测试分析而做的操作时间。这些操作不会被实际用户所执行。     例如一些循环赋值操作或插入检查点操作。消耗的时间有lr_wasted_time函数在
  lr_get_transaction_wasted_time函数之前移除了,移除后才得到对应的结果。
  函数语法结果
  double lr_get_transaction_wasted_time (const char * transaction);
  参数 transaction 为事物名称
  使用lr_get_transaction_wansted_time 函数必须注意,一它只能对当前运行状态的事物才能返回大于等于0的结果,否则返回小于0的结果。二是他使用之前应调用lr_wansted_time 函数移除过损耗时间 wasted time,否则lr_get_transaction_wansted_time将返回0。

帮助例子程序:

WasteTime()

{

int i, baseIter = 1000;

char dude[1000];

double wasteTime, actualElapsedTime;

merc_timer_handle_t MasterT, timer;

// Examine the total elapsed time of the action

MasterT = lr_start_timer();

//Start transaction

lr_start_transaction("Demo");

// Create some elapsed time for the transaction

for (i=0; i< (10 * baseIter); ++i)

sprintf(dude,

"This is the way we create elapsed  time artificially = %d", i);

// Add some think time

lr_think_time(0.5);

// Create some wasted time and record it with timer

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 = %lf",  wasteTime);

lr_output_message("Before lr_waste_time: Duration = %lf  - Waste = %lf",

lr_get_transaction_duration("Demo"),

lr_get_transaction_wasted_time("Demo"));

/* Convert Timer in seconds to wasted time in  milliseconds

and add to internally generated waste time */

wasteTime *= 1000;

lr_wasted_time(wasteTime);

lr_output_message("After lr_waste_time: Duration = %lf  - Waste = %lf",

lr_get_transaction_duration("Demo"),

lr_get_transaction_wasted_time("Demo"));

lr_output_message("Think time = %lf",

lr_get_transaction_think_time("Demo"));

lr_end_transaction("Demo", LR_AUTO);

actualElapsedTime = lr_end_timer(MasterT);

lr_output_message("Total Elapsed time for Action =  %lf",

actualElapsedTime);

return 0;

}

Vuser Output log file 输出日志

Note there is no difference between the transaction duration  before and after the call to lr_waste_time

WasteTime.c(28): User created waste time = 0.031250

WasteTime.c(32): Before lr_waste_time: Duration = 0.609375 -  Waste = 0.000000

WasteTime.c(40): After lr_waste_time: Duration = 0.625000 -  Waste = 0.031000

WasteTime.c(44): Think time = 0.500000

WasteTime.c(47): Notify: Transaction Demo ended with Pass  status (Duration: 0.6406 Think Time: 0.5000 Wasted Time: 0.0310).

WasteTime.c(50): Total Elapsed time for Action = 0.640625

Analysis: Average Response Time Raw Data

Note that the Transaction Response Time for "Demo" is 0.61.  This is the Duration from the Vuser log (0.6406) minus the Wasted Time (  0.0310).

 
Transaction End Status
Transaction Father Tree path
Scenario Elapsed Time
Transaction Response Time
Transaction Name
Pass
NONE
4.843
0
vuser_init_Transaction
Pass
WasteTime_Transaction
5.514
0.61
Demo
Pass
NONE
5.53
0.625
WasteTime_Transaction
Pass
NONE
5.53
0
vuser_end_Transaction
 

lr_start_timer,lr_get_transaction_duration,lr_get_transaction_wasted_time函数使用总结的更多相关文章

  1. lr_get_transaction_duration 函数介绍

    lr_get_transaction_duration 用于获取事务所消耗的时间. 实例: Action() { double trans_time; //定义变量 web_url("www ...

  2. LoadRunner 函数大全之中文解释

    LoadRunner 函数大全之中文解释 // sapgui_table_set_column_selected 模拟用户 // 单击表中的列标题. int sapgui_table_set_colu ...

  3. LoadRunner中的Web 函数列表

    LoadRunner中的Web 函数列表 web test LoadRunner fuction_list D:\Program Files (x86)\Mercury Interactive\Mer ...

  4. LoadRunner脚本编写之三(事务函数)

    LoadRunner脚本编写之三(事务函数) 关于脚本的这块,前两篇都在讲C语言,其实,要整理点实用的东西挺难,在应用中多对录制的脚本分析,但对于新手学脚本确实无从下手. 先贴一个脚本: 完整代码: ...

  5. loadrunner 脚本优化-事务时间简介

    脚本优化-事务时间简介 by:授客 QQ:1033553122 事务概念 事务是指用户在客户端做一种或多种业务所需要的操作集(actions),通过事务开始和结束函数可以标记完成该业务所需要的操作内容 ...

  6. LoadRunner去除事物中的程序的执行时间

    大家在性能测试过程中,经常会用到程序处理或组织数据,以达到一定的测试目的,但是程序本身执行会消耗一些时间,这部分消耗的时间是包含在响应时间里面,此时,响应时间=正常响应时间+程序执行消耗时间.那么如何 ...

  7. Loadrunder之脚本篇——事务时间简介

    事务概念 事务是指用户在客户端做一种或多种业务所需要的操作集(actions),通过事务开始和结束函数可以标记完成该业务所需要的操作内容(脚本section).定义事务来衡量服务器的性能,例如,你可以 ...

  8. LoadRunner脚本编写(转)

    性能测试工程师要懂代码么?答案是必须的.好多测试员认为在loadrunner中编写脚本很难很牛X ,主要是大多测试人员并未做过开发工作,大学的那点程序基础也忘记的差不多了.还有非计算机专业出身的测试员 ...

  9. LoadRunner中响应时间与事物时间详解

    1. 响应时间 事务是指用户在客户端做一种或多种业务所需要的操作集,通过事务函数可以标记完成该业务所需要的操作内容:另一方面事务可以用来统计用户操作的响应时间,事务响应时间是通过记录用户请求的开始时间 ...

随机推荐

  1. IO多路复用之epoll(一)讲解

    网络通信中socket有自己的内核发送缓冲区和内核接受缓冲区,好比是一个水池, 当用户发送数据的时候会从用户缓冲区拷贝到socket的内核发送缓冲区,然后从 socket发送缓冲区发出去, 当用户要读 ...

  2. poj 3764 字典树

    The xor-longest Path Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7332   Accepted: 1 ...

  3. [Java多线程]-Thread和Runable源码解析之基本方法的运用实例

    前面的文章:多线程爬坑之路-学习多线程需要来了解哪些东西?(concurrent并发包的数据结构和线程池,Locks锁,Atomic原子类) 多线程爬坑之路-Thread和Runable源码解析 前面 ...

  4. [DeeplearningAI笔记]序列模型2.8 GloVe词向量

    5.2自然语言处理 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.8 GloVe word vectors GloVe词向量 Pennington J, Socher R, Mannin ...

  5. 0UE3 材质概要

    材质概要 概述 参数 当创建材质时如何考虑颜色 材质表达式 Abs(求绝对值) 添加 AntialiasedTextureMask AppendVector(向量合并) BumpOffset(凸凹偏移 ...

  6. Asp.Net MVC +EF CodeFirst+多层程序设计

    1.概述 这是一个基于个人博客的一个项目,虽然博客根本没必要做这么复杂的设计.但是公司有需求,所以先自己弄个项目练练手.项目需要满足下列需求 1.层与层之间需要解耦,在后期上线更新维护时不需要覆盖,只 ...

  7. 有向图博弈+出度的结合 Codeforces Round #406 (Div. 2) C

    http://codeforces.com/contest/787/problem/C 题目大意:有一个长度为n的环,第1个位置是黑洞,其他都是星球.已知在星球上(不含第一个黑洞)有一位神.有两个人, ...

  8. JAVA多线程提高一:传统线程技术&传统定时器Timer

    前面我们已经对多线程的基础知识有了一定的了解,那么接下来我们将要对多线程进一步深入的学习:但在学习之前我们还是要对传统的技术进行一次回顾,本章我们回顾的则是:传统线程技术和传统的定时器实现. 一.传统 ...

  9. 【POJ】2774 Long Long Message

    [题意]给定两个字符串S和T,求最长公共子串.len<=10^5. [算法]后缀自动机 [题解]对字符串S建SAM,然后令串T在S上跑匹配. 这是自动机最原本的功能——匹配,就是串T在SAM(S ...

  10. webpack4 未设置mode会自动压缩

    最近想用LayaBox做个小游戏,然而Laya本身不自带构建工具.然后觉得写模块化的东西还是用webpack好使,用es6的语法也比较清晰. 于是就装了webpack,只用babel-loader来编 ...