Share this page

# Example: lr_start_sub_transaction

## Example 1

In the following example, lr_start_sub_transaction begins a transaction that performs purchases of six electrical items. The parent transaction is purchases and the sub-transaction is electrical_purchases.

     /* Notify that a transaction is starting */
    lr_start_transaction("purchases");
     /* Breakdown the transaction into a smaller transaction */
    lr_start_sub_transaction("electrical_purchases", "purchases");
    status = purchase_electrical_items(6); /* call to Server API */
    /* End transaction with operation result - pass or fail */

    if (status == 0)
        lr_end_sub_transaction("electrical_purchases", LR_PASS);
    else
        lr_end_sub_transaction("electrical_purchases", LR_FAIL);

## Example 2

This example shows how the durations of nested sub-transactions are reported.

    SubTransactions() {
        int i, baseIter = 1000;
        char dude[1000];
    //Start Parent
        lr_start_transaction("Master");
    //Start first sub transaction
        lr_start_sub_transaction("FirstT", "Master");
    //Start nested child of first sub transaction
        lr_start_sub_transaction("FirstT_Child1", "FirstT");
     // Artificially create some elapsed time
            for (i=0; i<(20 * baseIter); ++i)
                sprintf(dude,
                    "This is the way we kill time in a script = %d", i);

        lr_end_sub_transaction("FirstT_Child1",LR_AUTO);

    // Start second nested child
        lr_start_sub_transaction("FirstT_Child2", "FirstT");
    // Artificially create some elapsed time

            for (i=0; i<(20 * baseIter); ++i)
                sprintf(dude,
                    "This is the way we kill time in a script = %d", i);
    	lr_end_sub_transaction("FirstT_Child2",LR_AUTO);
        lr_end_sub_transaction("FirstT",LR_AUTO);
        //Start a second sub transaction
        lr_start_sub_transaction("SecondT", "Master");
            for (i=0; i< (20 * baseIter); ++i)
                sprintf(dude,
                    "This is the way we kill time in a script = %d", i);
        lr_end_sub_transaction("SecondT",LR_AUTO);
        lr_end_transaction("Master", LR_AUTO);
        return 0;
    }

    Example: Output:
    Note that FirstT duration is the sum of its nested sub transactions: FirstT_Child1 and FirstT_Child2.
    Master duration is the sum of its nested sub transactions: FirstT and SecondT.
    Notify: Transaction FirstT_Child1 ended with Pass status (Duration: 0.1250).
    Notify: Transaction FirstT_Child2 ended with Pass status (Duration: 0.1250).
    Notify: Transaction FirstT ended with Pass status (Duration: 0.2656).
    Notify: Transaction SecondT ended with Pass status (Duration: 0.1406).
    Notify: Transaction Master ended with Pass status (Duration: 0.4063).

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: