JavaScript Functions > Alphabetical Listing of Utility Functions (lr) > lr.getTransactionWastedTime

lr.getTransactionWastedTime

Returns the wasted time of a transaction by its name.

Example: Transactions Transaction Functions

Syntax

lr.getTransactionWastedTime( transaction );

Arguments

Argument Comments
transaction The name of the transaction.

The lr.getTransactionWastedTime function returns the Wasted Time in seconds of the specified transaction to this point.

The lr.getTransactionWastedTime function returns values greater than zero only for open transactions.

To determine other transaction statistics, such as think time and wasted time, use the appropriate Transaction Functions.

Return Values

On success, returns the transaction wasted time in seconds. On failure, returns a negative number. If the transaction already ended or if data is not available for the specified transaction, returns 0.

Parameterization

You cannot use standard parameterization for any arguments in this function.

Example

function Action(){
    var i, baseIter = 1000;
    var dude;
    var wasteTime, actualElapsedTime; 
    var MasterT, timer;

    // Examine the total elapsed time of the action
    MasterT = lr.startTimer();

    //Start transaction
    lr.startTransaction("Demo");

    // Create some elapsed time for the transaction
    for (i=0; i< (10 * baseIter); ++i)
            dude = "This is the way we create elapsed time artificially = "+ i;            

    // Add some think time
    lr.thinkTime(0.5);
    // Create some wasted time and record it with timer
    timer = lr.startTimer();

    for (i=0; i< (5 * baseIter); ++i)
            dude = "This is the way we waste time in a script = " + i;

    wasteTime = lr.endTimer(timer);
    lr.outputMessage("User created waste time = " + wasteTime);
    lr.outputMessage("Before lr_waste_time: Duration = "+lr.getTransactionDuration("Demo")+" - Waste = " + lr.getTransactionWastedTime("Demo")
);
    /* Convert Timer in seconds to wasted time in milliseconds and add to internally generated waste time */
    wasteTime *= 1000;
    lr.wastedTime(wasteTime);
    lr.outputMessage("After lr_waste_time: Duration = "+lr.getTransactionDuration("Demo"),+" - Waste = " + lr.getTransactionWastedTime("Demo"));

    lr.outputMessage("Think time = " + lr.getTransactionThinkTime("Demo"));

    lr.endTransaction("Demo", lr.AUTO);
    actualElapsedTime = lr.endTimer(MasterT);
    lr.outputMessage("Total Elapsed time for Action = " + actualElapsedT
    return 0;
}