jmeter长时间运行后未响应,获取时间jMeter线程一直在运行

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:

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

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:

a6a5e6a1be2f2a2f429685841c14a31b.png

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值