lr.stop_transaction

Freezes reporting of transaction data.

JavaScript

function lr.stop_transaction(  transaction_name  )

VBScript

Function lr.stop_transaction(  transaction_name  )
Transaction Functions

Arguments

NameComments
transaction_nameThe name of an open transaction.

This function is retained for backward compatibility. For more general ways of reporting partial transaction durations, see lr.start_transaction and lr.set_transaction.

After a call to lr.stop_transaction, statistics returned by the "get" Transaction Functions reflect only the data up to the call, until lr.resume_transaction is called. The specified transaction must have been opened with lr.start_transaction.

Data collection, however, is not interrupted. After the call to lr.resume_transaction, the "get" functions return all data since the start of the transaction. Furthermore, the final results when the test is analyzed will reflect the total values, including the periods in between the transaction stop and resume.

If lr.resume_transaction is not called, the "get" functions and the final results reflect only the duration from the transaction start to the lr.stop_transaction call. Thus, lr.stop_transaction and lr.resume_transaction can be used conditionally to collect information either about an entire transaction, or only the beginning. To accomplish this, call lr.resume_transaction only if your condition is met.

Note: When data is collected this way, the data in analysis will reflect both the tests where the condition for lr.resume_transaction is met, and the tests where it is not.

If the section you may wish to exclude ends before the end of the transaction, this technique does not apply. If you need to differentiate between occurrences where the lr.resume_transaction condition is met and those where it is not in the analysis data, this technique does not apply.

Return Values

This function returns the duration of the current transaction in milliseconds, or a negative number on error.

Parameterization

All string input arguments can be passed using standard parameterization.

VBScript Example

The follow example shows the capture of transaction duration times based on whether a condition is fulfilled. At the point in the transaction where data will be important regardless of the condition, stop_transaction is called to freeze reporting. After the ticket and purchase information is submitted, YourAPICall checks whether the submit succeeded. (In this example, YourAPICall simply passes the first iteration and fails the second.)

If YourAPICall determines that the submit successfully caused the server-side action to take place, then resume_transaction is called to unfreeze reporting. All subsequent calls to transaction data retrieval functions return all the data from the transaction start until the get* call. get_transaction_duration retrieves the total duration, then set_transaction uses that value to create transaction "SuccessfulFlight".

If YourAPICall determines that the server-side action failed, then resume_transaction is not called. Subsequent calls to transaction data retrieval functions return only the data from the transaction start until the stop_transaction call. get_transaction_duration retrieves that duration, and lr.set_transaction uses the value to create transaction "FailedFlight".

As a result of this action, analysis data is produced for three transitions.

Transaction "Flight" records an overview of transaction durations for both successful and unsuccessful submit, excluding time spent on unsuccessful submit operations. Transaction "SuccessfulFlight" records the total end to end times of transactions where the server-side action succeeded. Transaction "FailedFlight" records the time it takes to get the itinerary when then later submit fails.

Note: This technique is only effective if the section to be excluded is at the end of the transaction. For a more flexible approach, see lr.get_transaction_duration.

Below the sample action is the log and the analysis data.

Public Function Action() As Long

Dim trans_time As Double
Dim total_trans_time as Double
Dim rc As Integer
Dim vData As Variant
Dim vOptions As Variant
Dim s_code as Integer

lr.start_transaction "Flight"

vOptions = "Resource=0, " _
    & "RecContentType=text/html, " _
    & "Referer=, " _
    & "Snapshot=t1.inf, " _
    & "Mode=HTML, " _
    & "LAST"

web.URL "flightnet", _
    "URL=http://lazarus/flightnet/" , _
    vOptions

vData = "Name=grpType, Value=radRoundtrip, ENDITEM, " _
    & "Name=lstDepartingCity, Value=Los Angeles, ENDITEM, " _
    & "Name=lstDestinationCity, Value=San Francisco, ENDITEM, " _
    & "Name=txtDepartureDate, Value=1/12/2004, ENDITEM, " _
    & "Name=txtReturnDate, Value=1/14/2004, ENDITEM, " _
    & "Name=txtQuantity, Value=1, ENDITEM, " _
    & "Name=radClass, Value=1, ENDITEM, " _
    & "Name=radSeat, Value=1, ENDITEM, " _
    & "Name=btnAvailableFlights, Value=Next >, ENDITEM, " _
    & "LAST "

web.submit_form "default.aspx" , _
    "Snapshot=t2.inf" , _
    vData

' Get transaction time in seconds
' for the first part of the transaction: itinerary

trans_time = lr.get_transaction_duration ("Flight")

' Freeze reporting of the transaction duration

lr.stop_transaction "Flight"
lr.think_time 3

' Start the second part of the transaction: 
' Choosing a flight and buying a ticket

vData = "Name=lstAvailableFlights, Value=AA6291 Depart 8:10AM, Arrive 11:30AM, $179.47, ENDITEM, " _
    & "Name=btnCustomerInfo, Value=Next >, ENDITEM, " _
    & "LAST "

web.submit_form "default.aspx_2", _
    "Snapshot=t3.inf", _
    vData

vData = "Name=txtCustomerName, Value=Edmund Bertram, ENDITEM, " _
    & "Name=txtAddress, Value=Mansfield Park,\r\n" _
    & "England, ENDITEM, " _
    & "Name=txtPhoneNumber, Value=None, ENDITEM, " _
    & "Name=lstCreditCard, Value=Discover, ENDITEM, " _
    & "Name=txtCardNumber, Value=123456789, ENDITEM, " _
    & "Name=txtExpirationDate, Value=1/1/181, ENDITEM, " _
    & "Name=btnOrderConfirmation, Value=Finish, ENDITEM, " _
    & "LAST"

web.submit_form "default.aspx_3" , _
    "Snapshot=t4.inf" , _
    vData

' Call the API of your application to see whether the purchase is registered. 

rc = YourApiCall (s_code, "EdmundBertam")

' If your API confirms success:

If rc = lr.PASS Then

    ' Use all of the transaction duration for the overall transaction.

    lr.resume_transaction "Flight"

    ' Get the transaction time

    total_trans_time = lr.get_transaction_duration ("Flight")

    ' Create a transaction for the successful business process

    lr.set_transaction "SuccessfulFlight", total_trans_time, lr.PASS
    lr.Message "API Call succeeded: Record complete duration"
Else

' If your API shows that the process failed:
    'By not calling lr.resume_transaction, all time since the stop_transaction
    ' is ignored. The get_transaction call returns only the
    ' time from the start_transaction to the stop_transaction
    
	total_trans_time = lr.get_transaction_duration ("Flight")

    ' Create a transaction for the failed business process.

    lr.set_transaction "FailedFlight", total_trans_time, lr.PASS
    lr.Message "API Call failed: Record duration only up to logon and itinerary"
End If

lr.end_transaction "Flight", lr.AUTO
lr.Message "Duration of logon and itinerary = " + CStr(trans_time)
lr.message "Return Code is " + lr.eval_string ("<ReturnCode>")
Action = lr.PASS
End Function
Example: Output:
Starting iteration 1.
Starting action Action.
Notify: Transaction Flight started.
web_url("flightnet") was successful, 30710 body bytes, 1982 header bytes     [MsgId: MMSG-26386]
web_submit_form("default.aspx") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
Notify: Transaction Flight stopped.
web_submit_form("default.aspx_2") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
web_submit_form("default.aspx_3") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
After call to YourAPICall, rc = 0
Notify: Transaction Flight resumed.
Notify: Transaction SuccessfulFlight set.
API Call succeeded: Record complete duration
Notify: Transaction Flight ended with Pass status (Duration: 3.3448 Think Time: 3.0043).
Duration of logon and itinerary = 0.170246
Return Code is PASS
Ending action Action.
Ending iteration 1.
Starting iteration 2.
Starting action Action.
Notify: Transaction Flight started.
web_url("flightnet") was successful, 30710 body bytes, 1982 header bytes     [MsgId: MMSG-26386]
web_submit_form("default.aspx") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
Notify: Transaction Flight stopped.
web_submit_form("default.aspx_2") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
web_submit_form("default.aspx_3") was successful, 11610 body bytes, 259 header bytes     [MsgId: MMSG-26386]
After call to YourAPICall, rc = 1
Notify: Transaction FailedFlight set.
API Call failed: Record duration only up to logon and itinerary
Notify: Transaction Flight ended with Pass status (Duration: 0.1402).
Duration of logon and itinerary = 0.130187
Return Code is FAIL
Ending action Action.
Ending iteration 2.
Ending Vuser...

Analysis

When analyzing the four iterations of the script, the following were the results: For two iterations, YourAPICall indicated success, and for two iterations it indicated failure.

Transaction NameMinimumAverageMaximumStd. Deviation90 PercentPass
FailedFlight2.5142.7893.0640.2753.0592
Flight8.1129.26310.3550.910.3554
SuccessfulFlight6.697.297.890.57.8892