Transactions
- Any step in an application/website that performs a desired task can be treated as a transaction. In Load runner scripts, transactions are used to measure the response time. For example, to measure the time that a user takes to login to an application, the associated events can be put in a transaction.
- To indicate a transaction to be analyzed, use the lr_start_transaction and lr_end_transaction functions. These functions are inserted immediately before and after the transaction.
To start a transaction use
lr_start_transaction( const char *transaction_name );
To end a transaction use
lr_end_transaction( const char *transaction_name, int status ) ;
- Transactions can be nested, but each lr_start_transaction statement must be associated with an lr_end_transaction statement or it will be interpreted as an illegal command and a message “Vuser started transaction "transaction_name", but did not reached a corresponding end transaction statement. The transaction ended automatically with status 'fail'.”
- Likewise, every lr_end_transaction should have an associated start transaction before it. Else we get a message “Failed to end Transaction "_t1" (by name). Please check that you made a call to start transaction operation.”
- Use of period(.) should be avoided in transaction names. In analysis, a transaction name with a period will be interpreted as two transactions.
- lr_end_transaction takes two arguments, transaction name and transaction status. The transaction status decides whether the transaction should be ended with status Pass, Fail, Stop. The status argument takes integers 0, 1, 2, 3 or constants LR_PASS, LR_FAIL, LR_AUTO, LR_STOP respectively.
- You can manually set the status of the transaction or you can allow the script to detect it automatically. To manually set the status, you perform a manual check within the code of your script evaluating the return code of a function. For the "succeed" return code, set the status to LR_PASS. For a "fail" return code, set the status to LR_FAIL. For an "aborted" return code, set the status to LR_STOP.
- When the transaction ends, the duration between the start and the end of the transaction is calculated. To explicitly get the transaction duration lr_
- If status is LR_AUTO, then the value of status is automatically assigned. By default, this value is LR_PASS signifying a successful transaction. However, if prior to lr_end_transaction, you change the default value using lr_set_transaction_status, lr_set_transaction_status_by_name, lr_set_transaction_instance_status or lr_fail_trans_with_error, then this is the value which is passed as status in lr_end_transaction.
- If you make a series of calls to functions that modify the LR_AUTO status, then it is the last call before lr_end_transaction which effectively changes the status.
- To get the duration of a transaction use the function lr_get_transaction_duration.
- To get the status of the transaction use lr_get_transaction_status.
- To get the think time in a transaction use lr_get_transaction_think_time.
- To get the wasted time in a transaction use lr_get_transaction_wasted_time.
Setting dynamic transaction names to capture host/LG name
Code:
sprintf(buf,“%s_Login”, lr_get_host_name());
lr_start_transaction(buf);
// requests
lr_end_transaction(buf);
Explanation:
The sprintf function is used to write a formatted output to a string. Here it appends the host/LG name to a string buf and then uses the string to name the transaction.