lr.stopTransaction
Freezes reporting of transaction data.
Example: Transactions | Transaction Functions |
Syntax
lr.stopTransaction( transactionName );
Arguments
Argument | Comments |
---|---|
transactionName | The name of an open transaction. |
This function is retained for backward compatibility. For more general ways of reporting partial transaction durations, see lr.setTransaction.
After a call to lr.stopTransaction, statistics returned by the "get" Transaction Functions reflect only the data up to the call, until lr.resumeTransaction is called. The specified transaction must have been opened with lr.startTransaction.
Data collection, however, is not interrupted. After the call to lr.resumeTransaction, the "get" functions return all data since the start of the transaction. Furthermore, the final results when the test is analyzed will reflect the total values, including the periods in between the transaction stop and resume.
If lr.resumeTransaction is not called, the "get" functions and the final results reflect only the duration from the transaction start to the lr.stopTransaction call. Thus, lr.stopTransaction and lr.resumeTransaction can be used conditionally to collect information either about an entire transaction, or only the beginning. To accomplish this, call lr.resumeTransaction only if your condition is met.
Note: When data is collected this way, the data in analysis will reflect both the tests where the condition for lr.resumeTransaction is met, and the tests where it is not.
If the section you may wish to exclude ends before the end of the transaction, this technique does not apply. If you need to differentiate between occurrences where the lr.resumeTransaction condition is met and those where it is not in the analysis data, this technique does not apply.
Return Values
This function returns the duration of the current transaction in milliseconds, or a negative number on error.
Parameterization
All string arguments can be parameterized using standard parameterization.
Example
function Action(){ var i; var iteration = 100; var aStr =[]; lr.startTransaction("Stop&Start"); /* Do part of business process. Represented here by loop to ensure that some time passes. */ for (i=0; i < iteration; ++i) { lr.logMessage(i); } /* Output the duration to this point (0.343750 seconds) with transaction active. */ lr.outputMessage("First time = "+lr.getTransactionDuration("Stop&Start")); // Stop the transaction lr.stopTransaction("Stop&Start"); /* Output the duration to this point (0.359375 seconds) with transaction stopped. */ lr.outputMessage("Immediately after stop = "+lr.getTransactionDuration("Stop&Start")); // Ensure that some time passes for (i=0; i < iteration; ++i) { lr.logMessage(i); } /* Output the duration to this point (0.359375 seconds) with transaction still stopped but more time passed. Note that time is the same. The time spent in the loop while the transaction was stopped is not reported. */ lr.outputMessage("After stop and loop = "+lr.getTransactionDuration("Stop&Start")); // Resume the transaction lr.resumeTransaction("Stop&Start"); /* Note that with the transaction resumed, all the time passed since the start is reported (0.781250 seconds), including the time spent in the loop while the transaction was stopped. */ lr.outputMessage("After resume time = "+lr.getTransactionDuration("Stop&Start")); // Add time to duration for (i=0; i < iteration; ++i) { lr.logMessage(i); } /* Total time reported (1.140625 seconds) */ lr.outputMessage("After resume and loop = " + lr.getTransactionDuration("Stop&Start")); // End transaction lr.endTransaction("Stop&Start",lr.AUTO); return 0; }