Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new thread variable __jmv_THREAD_START_TIME_ITERATION contains the currentTimeMillis when the thread iteration start. #6356

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ private static void setLastSampleOk(JMeterVariables variables, boolean value) {
*/
private IterationListener initRun(JMeterContext threadContext) {
threadVars.putObject(JMeterVariables.VAR_IS_SAME_USER_KEY, isSameUserOnNextIteration);
threadVars.putObject(JMeterVariables.VAR_THREAD_START_TIME_ITERATION, threadVars.getStartThreadTimeIteration());

threadContext.setVariables(threadVars);
threadContext.setThreadNum(getThreadNum());
setLastSampleOk(threadVars, true);
Expand Down Expand Up @@ -1029,6 +1031,8 @@ private void delay(List<? extends Timer> timers) {

void notifyTestListeners() {
threadVars.incIteration();
threadVars.resetStartThreadTimeIteration();
threadVars.putObject(JMeterVariables.VAR_THREAD_START_TIME_ITERATION, threadVars.getStartThreadTimeIteration());
for (TestIterationListener listener : testIterationStartListeners) {
listener.testIterationStart(new LoopIterationEvent(threadGroupLoopController, threadVars.getIteration()));
if (listener instanceof TestElement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class JMeterVariables {
private final Map<String, Object> variables = new HashMap<>();

private int iteration = 0;
private long startTimeThreadIteration = System.currentTimeMillis();

// Property names to preload into JMeter variables:
private static final String [] PRE_LOAD = {
Expand All @@ -43,7 +44,7 @@ public class JMeterVariables {
};

static final String VAR_IS_SAME_USER_KEY = "__jmv_SAME_USER";

static final String VAR_THREAD_START_TIME_ITERATION ="__jmv_THREAD_START_TIME_ITERATION";
/**
* Constructor, that preloads the variables from the JMeter properties
*/
Expand Down Expand Up @@ -178,4 +179,12 @@ public Set<Map.Entry<String, Object>> entrySet(){
public boolean isSameUserOnNextIteration() {
return Boolean.TRUE.equals(variables.get(VAR_IS_SAME_USER_KEY));
}

public void resetStartThreadTimeIteration() {
startTimeThreadIteration = System.currentTimeMillis();
}

public long getStartThreadTimeIteration() {
return startTimeThreadIteration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public String get(String key) {
return variables.get(key);
}

@Override
public long getStartThreadTimeIteration() {
return variables.getStartThreadTimeIteration();
}

@Override
public void resetStartThreadTimeIteration() {
throw new UnsupportedOperationException();
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
Expand Down
2 changes: 2 additions & 0 deletions xdocs/usermanual/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,8 @@ However some variables are defined internally by JMeter. These are listed below.
<li><code>JMeterThread.last_sample_ok</code> - whether or not the last sample was OK - <code>true</code>/<code>false</code>.
Note: this is updated after PostProcessors and Assertions have been run.
</li>
<li><code>__jmv_SAME_USER</code> - is the same user for each iteration ? <code>true</code>/<code>false</code>. Mainly impacts clean cookie, cache data and new connection</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to fix some older code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to fix some older code?
Yes, when i search this variable "__jmv_SAME_USER" in the documentation, i don't see it.
So i add this line about the variable __jmv_SAME_USER.
And i add the new one variable "__jmv_THREAD_START_TIME_ITERATION"

<li><code>__jmv_THREAD_START_TIME_ITERATION</code> - contains the epoch unit milliseconds of the thread start iteration. Call System.currentTimeMillis()</li>
<li><code>START</code> variables (see next section)</li>
</ul>
</subsection>
Expand Down
Loading