获取jMeter线程已运行的时间 [英] Get time jMeter thread has been running

查看:1385
本文介绍了获取jMeter线程已运行的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我真的很难导航JMeter API 站点.

Maybe I am just really bad at navigating the JMeter API site.

但是可以说,我想找出一个线程已经运行了多长时间了,在If Controller或JSR223采样器中,我该怎么做?例如,线程组似乎没有我在寻找什么

But lets say I want to find out how long a thread has been running for, in a If Controller or a JSR223 sampler how could I do that? thread group for example doesn't seem to have what I am look for

推荐答案

也许,正在研究 JMeterThread JavaDoc .如果您使用线程组的计划程序"选项,您将能够使用 JMeterThread.getStartTime() JMeterThread.getEndTime()方法.

Maybe, looking into JMeterThread JavaDoc instead. If you use "Scheduler" option of the Thread Group you will be able to use JMeterThread.getStartTime() and JMeterThread.getEndTime() methods.

如果不使用调度程序,则可以使用以下方法:

If you don't use scheduler you could use the following approach:

  1. 在线程组的最开始添加JSR223测试元素(实际上无关紧要),并将以下代码放入脚本"区域:

  1. Add JSR223 Test Element (doesn't really matter which one) to the very beginning of your Thread Group and put the following code into "Script" area:

ctx.getThread().setStartTime(System.currentTimeMillis())

  • 在线程组的末尾添加另一个JSR223测试元素,并使用以下代码获取当前线程持续时间:

  • Add another JSR223 Test Element to the end of your Thread Group and use the following code to get current thread duration:

    long started = ctx.getThread().getStartTime()
    
    log.info('Thread duration: ' + (System.currentTimeMillis() - started))
    

  • 演示:

    ctx JMeterContextService 类.

    请参阅 Apache Groovy-为什么和如何使用它文章,在JMeter测试中使用Groovy的更多详细信息.

    See Apache Groovy - Why and How You Should Use It article for more details on using Groovy in JMeter tests.

    这篇关于获取jMeter线程已运行的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆