Y-lib
Loadrunner libraries
Data Structures | Typedefs | Functions
y_flow_list.c File Reference

Business logic / clickflow support. More...

#include "y_core.c"

Go to the source code of this file.

Data Structures

struct  y_flow
 Descriptor for one single flow in a flow list. More...
 

Typedefs

typedef int( y_flow_func) ()
 Type definition of a function pointer to the flow to execute. More...
 

Functions

int y_calc_flow_weight_total (y_flow flow_list[], int flow_count)
 Calculate the total of the weights in a given flow list. More...
 
y_flow * y_choose_flow (y_flow flow_list[], int flow_count)
 Choose a flow from a list of flows. More...
 
int y_exec_flow (y_flow *chosen_flow)
 Execute a flow from a flow list. More...
 
y_flow * y_get_flow_by_name (char *flow_name, y_flow flow_list[], int flow_count)
 Fetch a specific item from a flow list, by name. More...
 

Detailed Description

Business logic / clickflow support.

This file implements flow lists. A flow list is is a lists of actions (clickflow) that the script will choose from at random, using a set of predetermined weights. An 'action' is defined as a function that takes no arguments and returns an int - such as an action block, or a function without a specifically defined return type.

Note
The weights can be percentages, hit counts, or whatever you like, as long as the total of the weights does not exceed Y_RAND_MAX.

Example:

int browse()
{
web_link("...", LAST);
y_end_transaction("", LR_AUTO);
}
buy()
{
web_link("...", LAST);
y_end_transaction("", LR_AUTO);
}
// Define other actions as required.
loadtest_flow()
{
// Define the weights
static y_flow flow_list[] = {
{ 0, "action block for browsing the site", browse, 3700 }, // 37.00%
{ 1, "action block for buying a product", buy, 2100 }, // 21.00%
{ 2, "action block for checking out", checkout, 200 }, // 2.00%
{ 3, "function for resetting the database", wipe_database, 2500 }, // 25.00%
{ 4, "end the script for no reason", lr_abort, 1500 } }; // 15.00%
const int flow_count = (sizeof flow_list / sizeof flow_list[0]);
// Choose a flow to execute
y_flow *chosen_flow = y_choose_flow(flow_list, flow_count);
// Change the next transaction number to make sure the numbering stays contiguous.
// (This is optional. You can use that number for whatever you want, this is just a common use for that field.)
// Execute the chosen flow.
y_exec_flow(chosen_flow);
}
See also
y_choose_flow, y_exec_flow, y_set_next_transaction_nr, y_get_next_transaction_nr.
Author
Floris Kraak

Definition in file y_flow_list.c.

Typedef Documentation

typedef int( y_flow_func) ()

Type definition of a function pointer to the flow to execute.

This matches the prototype for Action() blocks, so you can assign a action blocks to variables of this type.

Definition at line 83 of file y_flow_list.c.

Function Documentation

int y_calc_flow_weight_total ( y_flow  flow_list[],
int  flow_count 
)

Calculate the total of the weights in a given flow list.

Given a flowlist of a specified length, calculate the total weight of all flows in a flow list. This is used by other ylib functions. Calling it directly from a script should normally not be needed.

See also
y_flow_list.c, y_choose_flow()
Parameters
[in]flow_listAn array of y_flow structs, each describing a specific choice in a clickpath.
[in]flow_countThe number of flows in the list.
Author
Floris Kraak

Definition at line 125 of file y_flow_list.c.

y_flow* y_choose_flow ( y_flow  flow_list[],
int  flow_count 
)

Choose a flow from a list of flows.

Parameters
[in]flow_listAn array of y_flow structs, each describing a specific choice in a clickpath.
[in]flow_countThe number of flows in the list.
Returns
a pointer to a randomly chosen flow, or NULL if somehow the weights don't add up. (flow list corrupt, flow_count incorrect, etc.)
See also
y_flow_list.c, y_exec_flow()
Note
The flow_count argument should exactly match the number of flows in the array or the script might blow up with MEMORY_ACCESS_VIOLATION errors.
Author
Floris Kraak

Definition at line 147 of file y_flow_list.c.

int y_exec_flow ( y_flow *  chosen_flow)

Execute a flow from a flow list.

Usually this is a flow as determined by y_choose_flow().

See also
y_flow_list.c, y_choose_flow()
Parameters
[in]chosen_flowThe flow to execute.
Returns
the flow's function return value.
Author
Floris Kraak

Definition at line 178 of file y_flow_list.c.

y_flow* y_get_flow_by_name ( char *  flow_name,
y_flow  flow_list[],
int  flow_count 
)

Fetch a specific item from a flow list, by name.

Parameters
[in]flow_nameThe name of the flow to fetch.
[in]flow_listThe flow list in question.
[in]flow_countThe number of flows in the list.
Returns
A pointer to the requested flow.
See also
y_flow_list.c, y_choose_flow(), y_exec_flow()

Definition at line 207 of file y_flow_list.c.