Example: lr.user_data_point

In the following example, the state of the server is checked five times in the middle of a test and data points are recorded with the results for later analysis. The example assumes that site being tested has an API named getSessionsCount that returns the desired test data.

Note that the use of such an API, if the call is only for testing purposes and not part of the business process, may create an unreasonably long transaction if the normal start_transaction - end_transaction mechanism is used. In this example, the transaction is created with set_transaction using only the duration of the business process, without the duration of the API calls.

Dim i as Integer
Dim before_api as Double
Dim api_time as Double
Dim start_transaction as Double
Dim transaction_time as Double

' Mark the start of the transaction

start_transaction = Timer

' .... Business process

'In the middle of the process, use an API to
`    get information about the current state of the server.
`    First record the start time of the check

before_api = Timer

' The server state is dynamic, so take five samples at one second intervals

For i = 1 to 5
    ' Get the state with a call to your application's
    `    API, getSessionsCount, and
    `    create a data point for each sample

    lr.user_data_point "Sessions" , getSessionsCount() 
    lr.think_time 1
Next i

' Get the total time spent on the check

api_time = Timer - before_api

' .... Continue business process
' The time spent on the business process is the
' elapsed time minus the time spent getting the
' server state samples.

transaction_time = Timer - start_transaction - api_time
' Create the transaction

lr.set_transaction "StressServer", transaction_time, lr.PASS