Get time jMeter thread has been running

北战南征 提交于 2019-12-06 15:51:57

问题


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


回答1:


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.




回答2:


You can add your test under Transaction Controller

And then in Sampler result you can see Load time: 2771 see 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.



来源:https://stackoverflow.com/questions/44653976/get-time-jmeter-thread-has-been-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!