How to convert a time in milli seconds to minutes in JMeter - jmeter

I am capturing elapsed time in simple variable in Jmeter and the value is saved in milliseconds, but I need to convert that value into minutes? Is there any way to do this in JMeter?

Given your variable name is elapsed you can convert milliseconds to minutes by dividing its value by 1000 (convert from ms to seconds) followed by dividing by 60 (convert seconds to minutes) via i.e. __jexl3() function which allows executing arbitrary JEXL expressions like:
${__jexl3(${elapsed} / 1000 / 60,elapsed)}
The above function will convert the value from ${elapsed} variable to minutes and write it back into ${elapsed} variable.
Functions can be used anywhere in the script
Use Function Helper Dialog to simplify function development process
See How to Use JMeter Functions posts series for more information on using JMeter Functions.

Instead, you could probably just use some simple math:
Convert Milliseconds To Hours, Minutes, And Seconds

Related

How can we get future / past datetime of Jmeter in seconds?

I would like to get future / past date in my Jmeter. I tried timeShift but it returns milliseconds by default, I would like to use it in seconds because my system does.
I have tried many ways but can not figure it out. Can you all show me how ? Or other methods ?
Image
Use __timeShift() and __jexl3() functions combination
with __timeShift() you will get the date in past/future in milliseconds since start of the Unix epoch
and with __jexl3() you can simply divide the resulting value by 1000 to get the value in seconds
Demo:
More information on JMeter Functions concept: Apache JMeter Functions - An Introduction
In your timeShift call, edit the 'time format' parameter to '/1000'. Something like ${__timeShift(/1000,,P2D,,)} (to get a shift of 2 days in seconds).

How to measure the start to endtime of a thread in JMeter

I have been trying to figure out how to measure the amount of time it takes a thread (virtual user) in JMeter to fully complete. I'm not necessarily concerned with response times at the moment. The API that I'm attempting to load test works in an async fashion. I make a request to start a job, I'm given a job id then I use that job id to check the status of said job until it's complete. I'm interested in knowing how long it takes for each job to complete i.e. when the job starts (thread is created) and when the job is completed (thread is done working).
I've seen several people suggest using the Transaction Controller in similar situations but that, unless I'm misunderstanding, gives me the total response time for all the requests in the "transaction" which doesn't help me.
This is what I have setup so far in JMeter:
Which actually works great, I make the initial request to submit the job and extract the job id. In a while loop I check the status of the job using the extracted id every 10 seconds (Constant Timer) until the job is complete.
This is what the aggregate report looks like for 5 concurrent users, I can also make the labels be the same so that it's compacted further but none of this information tells me how long a thread took. From the number of samples I can surmise that half the threads took roughly 10 seconds to complete and the others I can multiply by 10 seconds (sleep timer) and get a rough estimate how long it took to complete but that would be difficult to do (or at least time intensive) for a couple hundred threads. I was really hoping JMeter had something out of the box that would give me this information in a nice report format.
I've also seen suggestions that the only way to get this type of information is to parse logs, was just wondering if anyone has solved a similar problem.
Your question contains the answer, just measure it
Add JSR223 Sampler to the beginning of your Thread Group and put the following code into "Script" area:
SampleResult.setIgnore()
vars.putObject('startTime', System.currentTimeMillis())
the first line tells JMeter to not to store the JSR223 sampler result (as I believe you don't need this) and the second line saves current timestamp into ${startTime} JMeter Variable
Add another JSR223 Sampler to the end of your Thread Group and use the following code there:
SampleResult.setIgnore()
def end = System.currentTimeMillis()
def start = vars.getObject('startTime')
log.info('Thread ' + (ctx.getThreadNum() + 1) + ' elapsed time: ' + (end - start))
here we get the current timestamp after the job ended and subtract it from the previous timestamp store in the first JSR223 Sampler. The delta is printed to jmeter.log file however you might rather want to store it into another JMeter Variable and expose it to the results via Sample Variables property so it would be added to .jtl results file
Demo:
See Top 8 JMeter Java Classes You Should Be Using with Groovy to learn more about what these SampleResult, vars, and ctx shorthands mean

Take difference in time stamps to initiate logout in JMeter

In my jmeter script, I want to apply a logic where I take the time stamp of the first request and the second last request with the last request being logout. The difference in the time stamps when exceeds 3600 sec should trigger the logout transaction. I can take the time stamps using the jmeter _time function but not able to subtract it successfully. If I can get this done then I can put logout in an if controller and give the condition. Can anyone help please?
Check out __longSum() function which you can use to subtract 2 Unix timestamps
Define start as: ${__time(,start)} where required
Define end as: ${__time(,end)} where required
You can get the difference between end and start as ${__longSum(${start},-${end},)}
Demo:
More information: How to Use JMeter Functions

How in JMeter can you write a function that includes or can be used to generate random using time function with milliseconds

I need to create a random number using time function in JMeter that creates milliseconds too.
How in JMeter can you write a function that includes or can be used to generate random using time function with milliseconds?
Try the below:-
${__longSum(${__time()},${__Random(1,50)},MYVAR)}
Hope it help.

JMeter: how to stop the whole performance test after a defined time

I'd like to, independently of any other config regarding amount of threads, ramp up time or anything else, just stop the test if it has been running for more than, for example, 2 hours.
Currently you have in Thread Group Scheduler Checkbox, when you click it
You can define Duration in seconds,
In your case for 2 hours enter 7200 (60 *60 *2)
Another option is putting all requests in Runtime Controller with similar value.
You can also do scripting in While Controller with check time (similar to Dimtri T answer):
${__groovy(${__time(,)} - ${TESTSTART.MS} < 7200000,)}

Resources