Share this page

# Example: lr_stop_transaction_instance and lr_resume_instance

The following example shows the effect of lr_stop_transaction_instance and lr_resume_transaction_instance.

    StopResumeInstance() {
        long hdl;
        int i, baseIter = 100;
         char dude[200];
        double dur;
        hdl = lr_start_transaction_instance("Stop%Start", 0);

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

         for (i=0; i< (10 * baseIter); ++i)
                sprintf(dude, "Artificially add elapsed time = %d", i);

     //Add 1/2 second waste time
     lr_wasted_time(500);

     /* Output the duration to this point (0.343750 seconds) with transaction active. */

     lr_output_message("First time duration = %f, Waste = %f",
             lr_get_trans_instance_duration(hdl),
             lr_get_trans_instance_wasted_time(hdl));

     // Stop the transaction

     dur = lr_stop_transaction_instance(hdl);
     lr_output_message("Duration from stop call = %f", dur);

     //Add 1/2 second waste time

     lr_wasted_time(500);

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

     lr_output_message("Immediately after stop = %f, Waste = %f",
          lr_get_trans_instance_duration(hdl),
          lr_get_trans_instance_wasted_time(hdl));

     // Ensure that some time passes

     for (i=0; i< (10 * baseIter); ++i)
               sprintf(dude, "Artificially add elapsed time = %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, Waste = %f",
          lr_get_trans_instance_duration(hdl),
          lr_get_trans_instance_wasted_time(hdl));

     // Resume the transaction

    lr_resume_transaction_instance(hdl);

     /* 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, Waste = %f",
          lr_get_trans_instance_duration(hdl),
          lr_get_trans_instance_wasted_time(hdl));

     // Add time to duration

         for (i=0; i< (10 * baseIter); ++i)
                sprintf(dude, "Artificially add elapsed time = %d", i);

     /* Total time reported (1.140625 seconds) */

     lr_output_message("After resume and loop = %f, Waste = %f",
         lr_get_trans_instance_duration(hdl),
         lr_get_trans_instance_wasted_time(hdl));

     // End transaction

     lr_end_transaction_instance(hdl, LR_AUTO);
     return 0;
    }

    Example: Output:
    First time duration = 0.609375, Waste = 0.500000
    Notify: Transaction Stop%Start stopped.
    Duration from stop call = 0.625000
    Immediately after stop = 0.625000, Waste = 0.500000
    After stop and loop = 0.625000, Waste = 0.500000
    Notify: Transaction Stop%Start resumed.
    After resume time = 1.265625, Waste = 1.000000
    After resume and loop = 1.875000, Waste = 1.000000
     Notify: Transaction Stop%Start ended with Pass status (Duration: 1.8750 Wasted Time: 1.0000).

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: