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

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

问题描述

也许我真的不擅长浏览 JMeter API

ctxJMeterContextService 类.

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

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

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

解决方案

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. 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())
    

  2. 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))
    

Demo:

ctx is a shorthand to JMeterContextService class.

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

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

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