Share this page

# Example: lr.stop_transaction and lr.resume_transaction

In the following example, a transaction is stopped and resumed to show the effect on the reported duration.

    Action() {
        int i;
        int iteration = 100;
        char aStr[100];
        lr.start_transaction("Stop&Start");

     /* Do part of business process. Represented
            here by loop to ensure that some
            time passes. */

     for (i=0; i < iteration; ++i) {
            sprintf(aStr, "%d", i);
            lr.log_message("%d",i);
        }

        /* Output the duration to this point (0.343750 seconds)
            with transaction active. */
        lr.output_message("First time = %f",lr.get_transaction_duration("Stop&Start"));

        // Stop the transaction

        lr.stop_transaction("Stop&Start");

        /* Output the duration to this point (0.359375 seconds)
            with transaction stopped. */

        lr.output_message("Immediately after stop = %f", lr.get_transaction_duration("Stop&Start"));

        // Ensure that some time passes

        for (i=0; i < iteration; ++i) {
            sprintf(aStr, "%d", i);
            lr.log_message("%d",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.output_message("After stop and loop = %f", lr.get_transaction_duration("Stop&Start"));

        // Resume the transaction

        lr.resume_transaction("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.output_message("After resume time = %f", lr.get_transaction_duration("Stop&Start"));

        // Add time to duration

        for (i=0; i < iteration; ++i) {
            sprintf(aStr, "%d", i);
            lr.log_message("%d",i);
            }

        /* Total time reported (1.140625 seconds) */

        lr.output_message("After resume and loop = %f", lr.get_transaction_duration("Stop&Start"));

        // End transaction

        lr.end_transaction("Stop&Start", LR.AUTO);
        return 0;
    }

    Example: Output:
    Action.c(11): Notify: Transaction Stop&Start started.
    Action.c(23): First time = 0.343750
    Action.c(27): Notify: Transaction Stop&Start stopped.
    Action.c(31): Immediately after stop = 0.359375
    Action.c(45): After stop and loop = 0.359375
    Action.c(49): Notify: Transaction Stop&Start resumed.
    Action.c(55): After resume time = 0.781250
    Action.c(65): After resume and loop = 1.140625
    Action.c(70): Notify: Transaction Stop&Start ended with Pass status (Duration: 1.1406).

## lr.stopTransaction - Stop Transaction Example

The following example shows a transaction frozen in the middle of the process.

Syntax

    lr.stopTransaction( transactionName );

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;
    }

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: