Share this page

# Example: lr_get_trans_instance_duration

In the following example, the lr_get_trans_instance_duration function checks the durations of parent and child transaction instances, and sends them to the Output window.

    #include "as_web.h"
    Action() {
        long parent_trans_handle;
        long child_handle;
        double trans_time;
        int rc;

        /* Start the main transaction instance.
            Passing 0 as the parent handle indicates that the
            transaction has no parent.
            The function return value is the handle used in other
            transaction instance functions.     */

        parent_trans_handle = lr_start_transaction_instance("ParentTransaction",0);

        /*Perform the business process, represented here with a single web_url call. */
        web_url("web_url", "URL=http://www.ABC.com",LAST );
        rc = lr_get_trans_instance_status(parent_trans_handle);
        if (rc == LR_FAIL) {
         /* web_url has failed the transaction. No point in continuing, because
            future calls will probably also fail. */
         lr_end_transaction_instance(parent_trans_handle, LR_FAIL);
         return;
        }

        /* Start the child transaction instance. Passing the handle returned from another
            lr_start_transaction_instance call as the
            handle argument makes this transaction a child instance.     */

        child_handle = lr_start_transaction_instance("ChildTransInstance",parent_trans_handle);
        // Perform the business process
        web_url("web_url","URL=http://ABC.com",LAST );

        /* Get the child transaction instance durations. Pass the instance handle. The duration in seconds is the return value. */

        trans_time = lr_get_trans_instance_duration(child_handle);
        lr_output_message("First child instance time is %lf seconds.", trans_time);

        //Think time
        trans_time = lr_get_trans_instance_think_time(child_handle);
        lr_output_message("First child instance think time is %lf seconds.", trans_time);

        //Wasted time
        trans_time = lr_get_trans_instance_wasted_time (child_handle);
        lr_output_message("First child instance waste time is %lf seconds.", trans_time);

        // End the child transaction instance

        lr_end_transaction_instance(child_handle, LR_PASS);

        /* Get the Parent transaction instance duration, which includes the child transaction duration. */
        trans_time = lr_get_trans_instance_duration(parent_trans_handle);
        lr_output_message("Parent Transaction duration is %lf seconds.", trans_time );

        //End the parent transaction instance
        lr_end_transaction_instance(parent_trans_handle, LR_PASS);
        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: