Y-lib
Loadrunner libraries
|
Collection of miscellaneous support functions. More...
Macros | |
#define | y_breadcrumb_reset() lr_save_string("", "breadcrumb") |
Resets the breadcrumb Use this macro to start a new breadcrumb or to reset an existing one. More... | |
#define | y_delay_once(delay_in_seconds) |
Delay for delay_in_seconds seconds, once. This macro will put the code to sleep for the specified amount of seconds, but only the first time the current position in the code is reached. If you use this in more than one place each of the calls will sleep exactly once. More... | |
Functions | |
static unsigned long | y_hash_sdbm (char *str) |
Create a hash of string input. More... | |
int | y_rand_in_sliding_window (int lowerbound, int upperbound, int rand_max) |
Generate random number and test if it lies between 2 given boundaries. More... | |
int | y_rand_between (int lowerbound, int upperbound) |
Create a random number between two boundaries. (the boundaries are included!) More... | |
int | y_save_attribute_to_parameter (char *attrib, char *param) |
Fetch attribute from vUser's command line and store it in a parameter. This will fetch an attribute from the vUser's command line (as set in the scenario or in runtime settings as additional attributes) and stores it in the given parameter. More... | |
int | y_save_attribute (char *param) |
Fetch attribute from vUser's command lin and store it in a parameter of the same name. This will fetch an attribute from the vUser's command line (as set in the scenario or in runtime settings (addition attributes)) and stores it in a parameter of the same name. This function is a shortcut to y_save_attribute_to_parameter() More... | |
void | y_log_rendezvous_result (int result) |
Process the result code of lr_rendezvous() call to log human readable errors. More... | |
void | y_breadcrumb (char *breadcrumb) |
Keep track of the steps in the script. More... | |
int | y_write_to_file (char *filename, char *content) |
Write a string to a file. More... | |
int | y_write_parameter_to_file (char *filename, char *content_parameter) |
Write the content of a parameter to a file. More... | |
void | y_datetime () |
Saves the current date/time into a LR-parameter. More... | |
int | y_workdays_from_today (int workdays) |
Calculate the difference in days between today and X workdays into the future. More... | |
void | y_get_disk_space (const char *folder_name, double *available, double *total) |
Get the free disk space on the target folder on the load generator. More... | |
double | y_get_free_disk_space_in_mebibytes (const char *folder_name) |
Get the amount of free disk space in the target folder in mebibytes (SI unit) More... | |
double | y_get_free_disk_space_percentage (const char *folder_name) |
Get the free disk space percentage on the target folder on the load generator. More... | |
int | y_read_file_into_parameter (char *filename, char *param) |
Read the contents of a file into a single parameter. More... | |
void | y_user_data_point (char *param) |
Create a user data point for a parameter. More... | |
double | y_get_current_time () |
Get the current time in seconds since 1970, as a double. More... | |
double | y_delay_until (double timestamp) |
Delay until a certain time. More... | |
double | y_think_time_for_rampup_ext (int rampup_period, double TPS_initial, double TPS_max, int virtual_users) |
Ramp up the load by using varying amounts of think time instead of virtual users. More... | |
double | y_think_time_for_rampup (const int rampup_period, double TPS_max) |
Ramp up the load by using varying amounts of think time instead of virtual users. For simulating situations with limited amounts of connections on the client side. More... | |
y_execute_shell_command (char *command, int debug) | |
Execute a windows shell command Implements proper error checking. More... | |
int | y_errorcheck (int ok) |
Errorflood guard. Also known as "the error check". More... | |
double | y_pace (double pacing_time_in_seconds) |
Improved implementation of loadrunner pacing. More... | |
double | y_pace_rnd (double min_pacing_time_in_seconds, double max_pacing_time_in_seconds) |
Improved implementation of loadrunner pacing - with semirandomized pacing. More... | |
Collection of miscellaneous support functions.
#define y_breadcrumb_reset | ( | ) | lr_save_string("", "breadcrumb") |
Resets the breadcrumb Use this macro to start a new breadcrumb or to reset an existing one.
Definition at line 307 of file y_loadrunner_utils.c.
#define y_delay_once | ( | delay_in_seconds | ) |
Delay for delay_in_seconds seconds, once. This macro will put the code to sleep for the specified amount of seconds, but only the first time the current position in the code is reached. If you use this in more than one place each of the calls will sleep exactly once.
The particular usecase this was made for is a case where users need to register themselves prior to the actual test run. We want to seperate this registration period from the actual rampup, so when each user finishes registering we want a delay. But, we only want it once, and we will only know that we're done registering when we hit the regular load path for the first time.
Hence: delay_once
This is a macro because a function call would make it impossible to use this more than once in a script - it would execute the delay the first time this function is called, independent of where it was called from. Which would be rather counterintuitive.
Definition at line 768 of file y_loadrunner_utils.c.
void y_breadcrumb | ( | char * | breadcrumb | ) |
Keep track of the steps in the script.
Adds (another) string (read: step) to the LR-parameter {breadcrumb} Use this to keep track of the steps taken by the script. Very useful if you have a script which does things in a random order and you want to know (in the end) which order it actually used. You can, of course, write this to a (log)file. Don't forget to use y_breadcrumb_reset() to clear the parameter at the start of the script. (else you end up with a very long breadcrumb (breadstick?).)
[in] | breadcrumb |
Definition at line 283 of file y_loadrunner_utils.c.
void y_datetime | ( | ) |
Saves the current date/time into a LR-parameter.
Stores the current date/time into LR-parameter {DATE_TIME_STRING} in this format:
YYYYMMDD,HHMMSS (yes, separated by a comma.)
Definition at line 442 of file y_loadrunner_utils.c.
double y_delay_until | ( | double | timestamp | ) |
Delay until a certain time.
Definition at line 739 of file y_loadrunner_utils.c.
int y_errorcheck | ( | int | ok | ) |
Errorflood guard. Also known as "the error check".
Prevent error floods by inserting forced thinktime at the start of the iteration if too many successive iterations fail.
Sometimes very long running tests suffer from disruptions halfway through, caused by silly things like backups. In such a situation all users will temporarily fail, causing a sudden flood of log messages on the generator. Keeping the load 'stable' at that stage may also prevent the back-end from coming back up normally after the original disruption has ended. Plus, if the system stays down keeping the full load on it will only cause the generator's log storage to overflow.
Hence this piece of guarding code that will detect such problems inside the virtual user and temporarily lower the load on the system under test until the situation returns to normal (or the test stops).
Usage:
Three virtual user command line attributes are used to control this functionality:
Use this in the command line setting in a test scenario. The 'Additional attributes' in the Run-Time settings allows you the set your own defaults in the script.
For example:
This will force an extra pacing of 5 minutes after 10 successive failed iterations and aborts after 20 successive failed iterations.
[in] | ok | Start/end iteration marker. Must be set to 0 at the start of the iteration, and 1 at the end of the iteration. |
Definition at line 1028 of file y_loadrunner_utils.c.
y_execute_shell_command | ( | char * | command, |
int | debug | ||
) |
Execute a windows shell command Implements proper error checking.
[in] | command | A windows shell command, as passed to CMD.exe |
[in] | debug | If zero, log the first line; Otherwise, log full command output. |
Definition at line 916 of file y_loadrunner_utils.c.
double y_get_current_time | ( | ) |
Get the current time in seconds since 1970, as a double.
Definition at line 726 of file y_loadrunner_utils.c.
void y_get_disk_space | ( | const char * | folder_name, |
double * | available, | ||
double * | total | ||
) |
Get the free disk space on the target folder on the load generator.
In order to prevent loadrunner logs from filling up disks on the generator beyond capacity we need to know how much free space the log file system has. This function retrieves information about the amount of space that is available on a disk volume, which is the total amount of space and the total amount of free space available to the vuser.
[in] | folder_name | The name of the folder to report on. If this parameter is NULL, the function uses the root of the current disk. |
[out] | available | The total number of free bytes on a disk that are available to the vuser |
[out] | total | The total number of bytes on a disk that are available to the vuser |
Both parameters available and total may by NULL when not required. If per-user quotas are being used, the value(s) may be less than the total number of (free) bytes on a disk. The value of 0 is returned on error (e.g. no access to disk).
Definition at line 542 of file y_loadrunner_utils.c.
double y_get_free_disk_space_in_mebibytes | ( | const char * | folder_name | ) |
Get the amount of free disk space in the target folder in mebibytes (SI unit)
[in] | folder_name | The name of the folder to report on. |
Definition at line 604 of file y_loadrunner_utils.c.
double y_get_free_disk_space_percentage | ( | const char * | folder_name | ) |
Get the free disk space percentage on the target folder on the load generator.
[in] | folder_name | The name of the folder to report on. |
Definition at line 623 of file y_loadrunner_utils.c.
|
static |
Create a hash of string input.
A fairly simple hash that can be used to compare long input texts with each other. This uses the sdbm algorithm, described at http://www.cse.yorku.ca/~oz/hash.html.
[in] | str | The string to create a hash from. |
Definition at line 57 of file y_loadrunner_utils.c.
void y_log_rendezvous_result | ( | int | result | ) |
Process the result code of lr_rendezvous() call to log human readable errors.
When calling lr_rendezvous() the result code indicates the end state of the rendezvous. This function will translate the codes into human readable errors which are then logged as normal.
[in] | result | code from lr_rendezvous() |
Definition at line 223 of file y_loadrunner_utils.c.
double y_pace | ( | double | pacing_time_in_seconds | ) |
Improved implementation of loadrunner pacing.
Normal loadrunner pacing (as set by runtime settings) does not really deal with situations in which increases in response time cause the iteration to exceed it's normal pacing settings. If you set a pacing of 60 seconds, and the script takes 180 seconds to execute one iteration, the next iteration will still be 60 seconds - meaning the script will have executed at best 2 iterations in 240 seconds - putting only half the load on the target system, quite probably not something that was intended.
In order to mitigate this we can do two things:
This function implements the latter method.
The way that this works is simple: First, it measures how much time passed since the first time it was called. Then it compares that to a running total of how much time should have passed since that time. If this more time should have passed than has actually passed, it will force a thinktime equal to the gap. Finally, it takes the pacing time argument that was passed in (in seconds, as a double, so fractions of a second are allowed) as an argument, and adds that to the running total of how much time should have passed - to be used the next time around.
Example:
[in] | pacing_time_in_seconds | - average pacing time. It is recommended this number is kept constant unless you know exactly what you're doing. |
Definition at line 1149 of file y_loadrunner_utils.c.
double y_pace_rnd | ( | double | min_pacing_time_in_seconds, |
double | max_pacing_time_in_seconds | ||
) |
Improved implementation of loadrunner pacing - with semirandomized pacing.
[in] | min_pacing_time_in_seconds | - minimum pacing time. |
[in] | max_pacing_time_in_seconds | - maximum pacing time. |
A random value between these minimum and maximum is chosen using y_drand() and used to call y_pace().
Definition at line 1189 of file y_loadrunner_utils.c.
int y_rand_between | ( | int | lowerbound, |
int | upperbound | ||
) |
Create a random number between two boundaries. (the boundaries are included!)
When the lower boundary equals the upper boundary, y_rand_between() simply returns the lower boundary.
[in] | lowerbound | Lower boundary of the generated number |
[in] | upperbound | Upper boundary of the generated number |
Example:
Definition at line 137 of file y_loadrunner_utils.c.
int y_rand_in_sliding_window | ( | int | lowerbound, |
int | upperbound, | ||
int | rand_max | ||
) |
Generate random number and test if it lies between 2 given boundaries.
This will generate a random number between (and including) 0 and rand_max, and tell us if that number lies between the lower and upper bounds or not. Boundaries are included!
This is useful for pathing decisions: Say that at point P in a script a choice has to be made between continuing with actions A, B, and C. The decision is made based on a percentage: A = 10% chance, B = 50% chance, C = 40% chance. This function was written to support the code that would make this decision.
[in] | lowerbound | Minumum value |
[in] | upperbound | Maximum value |
[in] | rand_max | Upper boundary of the random number |
Definition at line 99 of file y_loadrunner_utils.c.
int y_read_file_into_parameter | ( | char * | filename, |
char * | param | ||
) |
Read the contents of a file into a single parameter.
[in] | filename | The name of the file to read (relative to script root, or full path) |
[in] | param | The name of the parameter to store the file contents in. |
This can be used in various situations; For example, situations where you have a template file that you wish to use for various requests. For instance, when all communications are based on a simple XML submit with slightly different (parameterised) contents.
Example:
Definition at line 670 of file y_loadrunner_utils.c.
int y_save_attribute | ( | char * | param | ) |
Fetch attribute from vUser's command lin and store it in a parameter of the same name. This will fetch an attribute from the vUser's command line (as set in the scenario or in runtime settings (addition attributes)) and stores it in a parameter of the same name. This function is a shortcut to y_save_attribute_to_parameter()
[in] | param | argument name of both the attribute and the parameter the value should be stored in. |
Example:
Definition at line 194 of file y_loadrunner_utils.c.
int y_save_attribute_to_parameter | ( | char * | attrib, |
char * | param | ||
) |
Fetch attribute from vUser's command line and store it in a parameter. This will fetch an attribute from the vUser's command line (as set in the scenario or in runtime settings as additional attributes) and stores it in the given parameter.
[in] | attrib | Attribute name. |
[out] | param | LR parameter name in which the argument value is stored. |
Example:
Definition at line 163 of file y_loadrunner_utils.c.
double y_think_time_for_rampup | ( | const int | rampup_period, |
double | TPS_max | ||
) |
Ramp up the load by using varying amounts of think time instead of virtual users. For simulating situations with limited amounts of connections on the client side.
As y_think_time_for_rampup_ext(), assuming 1 virtual user and an initial target load of 0.1 TPS (the defaults.
[in] | rampup_period | How long the rampup should take, in seconds. Default 1800 seconds. |
[in] | TPS_max | End rampup with this many transactions / sec in total per virtual user. Default 10. This cannot go higher than 1/average response time - when think time reaches zero. |
Definition at line 897 of file y_loadrunner_utils.c.
double y_think_time_for_rampup_ext | ( | int | rampup_period, |
double | TPS_initial, | ||
double | TPS_max, | ||
int | virtual_users | ||
) |
Ramp up the load by using varying amounts of think time instead of virtual users.
This can be used for simulating situations with limited amounts of connections on the client side. In such a case we cannot use regular vuser based rampups, so instead we have to gradually lower the thinktime to get a similar effect. This implements a "think time" function that will use responsetime calculations and a TPS target to simulate such a ramp up.
Base formula: TT = threads/TPS(target) - response time
This will be increasing TPS linearly until rampup_period has passed, unless either think time reaches zero or TPS_max is reached. Note that "response time" is actually "time passed since the previous call to this function". This includes wasted time.
For best effect, call this once in vuser_init and once for each transaction. The recommended practice is to overload lr_think_time() with your own version that calls this (or y_think_time_for_rampup()) every time, like so:
Example:
[in] | rampup_period | How long the rampup should take, in seconds. Default 1800 seconds. |
[in] | TPS_initial | Start rampup with this many transactions / sec for this transaction, across all virtual users. Default 0,1 TPS. |
[in] | TPS_max | End rampup with this many transactions / sec in total per virtual user. Default 10. This cannot go higher than 1/average response time - when think time reaches zero. |
[in] | virtual_users | How many virtual users the script is using. If you use "1", you can just use TPS / virtual user for the initial target TPS. Default 1. |
Definition at line 820 of file y_loadrunner_utils.c.
void y_user_data_point | ( | char * | param | ) |
Create a user data point for a parameter.
[in] | param | The name of a parameter containing an integer or floating point number. |
The name of the parameter will be the name of the datapoint that was created.
Example
Definition at line 717 of file y_loadrunner_utils.c.
int y_workdays_from_today | ( | int | workdays | ) |
Calculate the difference in days between today and X workdays into the future.
Calculate the difference in days between today and a date X workdays into the future.
Example:
Definition at line 466 of file y_loadrunner_utils.c.
int y_write_parameter_to_file | ( | char * | filename, |
char * | content_parameter | ||
) |
Write the content of a parameter to a file.
Write the content of a parameter to a file. Creates the file if it doesn't exist. Appends to an existing file.
[in] | filename | Name of the file in which the content is saved. |
[in] | content_parameter | The name of the parameter to be saved. No checking is done - if this doesn't exist, it will just write {content_parameter} or something to your file! |
Definition at line 374 of file y_loadrunner_utils.c.
int y_write_to_file | ( | char * | filename, |
char * | content | ||
) |
Write a string to a file.
Write a string to a file. Creates the file if it doesn't exist. Appends to an existing file.
[in] | filename | Name of the file in which the content is saved. |
[in] | content | String which is saved into the file |
Definition at line 330 of file y_loadrunner_utils.c.