获取时间 jMeter 线程已经 运行

Get time jMeter thread has been running

也许我真的不擅长使用 JMeter API site.

但是假设我想知道一个线程 运行 持续了多长时间,在 If Controller 或 JSR223 采样器中我该怎么做? thread group 例如似乎没有我要找的东西

您可以在事务控制器下添加您的测试

然后在 Sampler 结果中您可以看到加载时间:2771 参见 Manual

Note: when the check box "Include duration of timer and pre-post processors in generated sample" is checked, the time includes all processing within the controller scope, not just the samples.

也许,研究 JMeterThread JavaDoc instead. If you use "Scheduler" option of the Thread Group you will be able to use JMeterThread.getStartTime() and JMeterThread.getEndTime() 方法。

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

  1. 将 JSR223 测试元素(哪一个并不重要)添加到线程组的最开头并将以下代码放入 "Script" 区域:

    ctx.getThread().setStartTime(System.currentTimeMillis())
    
  2. 将另一个 JSR223 测试元素添加到线程组的末尾,并使用以下代码获取当前线程持续时间:

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

演示:

ctx 是 shorthand 到 JMeterContextService class。

有关在 JMeter 测试中使用 Groovy 的更多详细信息,请参阅 Apache Groovy - Why and How You Should Use It 文章。