20 #ifndef _Y_TRANSACTION_C_ 21 #define _Y_TRANSACTION_C_ 120 #define Y_TRANS_STATUS_NONE 0 121 #define Y_TRANS_STATUS_STARTED 1 123 #define Y_TRANS_STATUS_AUTO_STARTED 2 161 lr_start_transaction(
"y_workaround_transaction_to_prevent_null_dereference");
162 lr_end_transaction(
"y_workaround_transaction_to_prevent_null_dereference", LR_AUTO);
175 return lr_eval_string(
"{y_current_transaction}");
185 lr_save_string(lr_eval_string(trans_name),
"y_current_transaction");
197 return lr_eval_string(
"{y_current_sub_transaction}");
208 lr_save_string(lr_eval_string(trans_name),
"y_current_sub_transaction");
227 #define y_set_action_prefix 0_y_set_action_prefix_no_longer_exists_please_use_action_prefix 228 #define y_get_action_prefix 0_y_get_action_prefix_no_longer_exists_please_use_y_get_transaction_prefix 241 lr_save_string(transaction_prefix,
"y_transaction_prefix");
262 return lr_eval_string(
"{y_transaction_prefix}");
332 #define y_set_transaction_nr 0y_set_transaction_nr_no_longer_exists_please_use_y_set_next_transaction_nr 333 #define y_get_transaction_nr 0y_get_transaction_nr_no_longer_exists_please_use_y_get_next_transaction_nr 334 #define y_get_and_increment_transaction_nr 0y_get_and_increment_transaction_nr_no_longer_exists_please_use_y_increment_transaction_nr 335 #define y_get_sub_transaction_nr 0y_get_sub_transaction_nr_no_longer_exists_please_use_y_get_next_sub_transaction_nr 336 #define y_get_and_increment_sub_transaction_nr 0y_get_and_increment_sub_transaction_nr_no_longer_exists_please_use_y_increment_sub_transaction_nr 337 #define y_set_sub_transaction_nr 0y_set_sub_transaction_nr_no_longer_exists_please_use_y_set_next_sub_transaction_nr 475 int actual_status = lr_get_transaction_status(transaction_name);
477 if( actual_status == LR_PASS )
480 lr_set_transaction_status(status);
485 status = actual_status;
488 if( actual_status == -16863 )
491 lr_log_message(
"Warning: Possible attempt to close a transaction that has not been opened!");
493 lr_save_int(status, saveparam);
527 lr_log_message(
"Starting transaction block %s", transaction_prefix);
549 lr_error_message(
"Attempt to pause transaction block when none has been started!");
552 lr_save_int(
y_get_next_transaction_nr(), lr_eval_string(
"y_paused_transaction_block_{y_transaction_prefix}_trans_nr") );
560 lr_log_message(
"Resuming transaction block %s", transaction_prefix);
562 lr_save_string(transaction_prefix,
"y_resumed_transaction_block");
563 storage_param = lr_eval_string(
"y_paused_transaction_block_{y_resumed_transaction_block}_trans_nr");
567 lr_error_message(
"Attempt to resume transaction block %s but no such block has been paused.", transaction_prefix);
592 #define y_calculate_actual_action_prefix 0_y_calculate_actual_action_prefix_no_longer_exists_please_use_y_calculate_actual_transaction_prefix 610 const char seperator[] =
"_";
611 const int seperator_len =
sizeof seperator - 1;
613 int prefix_len =
strlen(transaction_prefix);
628 prefix_len += seperator_len;
632 group_len += seperator_len;
636 buffer_size = group_len + prefix_len + 1;
649 snprintf(buffer + len, buffer_size-len,
"%s%s", transaction_prefix, seperator);
670 const int trans_nr_len = 2;
672 int prefix_len =
strlen(actual_prefix);
673 int trans_name_size = prefix_len + trans_nr_len +1 +
strlen(transaction_name) +1;
674 char *actual_trans_name =
y_mem_alloc( trans_name_size );
676 if( transaction_nr >= 100 )
678 y_log_error(
"Transaction count too high (100+). Are you using y_start_action_block()?");
679 lr_exit(LR_EXIT_VUSER, LR_FAIL);
682 snprintf(actual_trans_name, trans_name_size,
"%s%02d_%s", actual_prefix, transaction_nr, transaction_name);
685 free(actual_trans_name);
699 const int transaction_nr,
const int sub_transaction_nr)
701 const int trans_nr_len = 2;
703 int prefix_len =
strlen(actual_prefix);
704 int trans_name_size = prefix_len + (2 * (trans_nr_len +1)) +
strlen(transaction_name) +1;
705 char *actual_trans_name =
y_mem_alloc( trans_name_size );
707 if( transaction_nr >= 100 )
709 y_log_error(
"Transaction count too high (100+). Are you using y_start_action_block()?");
710 lr_exit(LR_EXIT_VUSER, LR_FAIL);
713 snprintf(actual_trans_name, trans_name_size,
"%s%02d_%02d_%s", actual_prefix, transaction_nr, sub_transaction_nr, transaction_name);
716 free(actual_trans_name);
773 char *trans_name = lr_eval_string(
"{y_current_transaction}");
781 if( status == LR_PASS && trigger_result != LR_PASS )
783 lr_error_message(
"Transaction end trigger did not return LR_PASS");
784 status = trigger_result;
793 lr_user_data_point( lr_eval_string(
"wasted_{y_current_transaction}"), lr_get_transaction_wasted_time(trans_name));
835 return lr_start_sub_transaction(
836 lr_eval_string(
"{y_current_sub_transaction}"),
837 lr_eval_string(
"{y_current_transaction}"));
850 char *trans_name = lr_eval_string(
"{y_current_sub_transaction}");
854 if( status == LR_PASS && trigger_result != LR_PASS )
856 status = trigger_result;
864 lr_user_data_point( lr_eval_string(
"wasted_{y_current_sub_transaction}"), lr_get_transaction_wasted_time(trans_name));
867 status = lr_end_sub_transaction(trans_name, status);
883 if( last_trans_status_string == NULL )
889 return atoi(last_trans_status_string);
901 lr_save_string(session_name,
"y_session_name");
909 #define Y_FORCE_PAUSE 1 914 double measured_duration;
918 lr_error_message(
"Error: y_session_timer_end() called without matching call to y_session_timer_end()!");
919 lr_set_transaction(
"__y_sesssion_timer_end_call_without_y_session_timer_end_call", 0, LR_FAIL);
926 int remaining_time = required_session_duration - measured_duration;
931 lr_user_data_point( lr_eval_string(
"y_session_duration_{y_session_name}"), measured_duration);
932 if ( remaining_time > 0 )
936 lr_force_think_time(remaining_time);
941 lr_error_message( lr_eval_string(
"WARNING!: Measured duration of session {y_session_name} (%f) exceeded specified maximum of %d seconds!"), measured_duration, required_session_duration);
942 lr_set_transaction( lr_eval_string(
"_{y_session_name}_session_duration_overrun"), measured_duration, LR_FAIL);
964 char *link = lr_eval_string(linkname);
970 lr_error_message(
"Zero-length link name - correlation error?");
971 lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_AUTO);
977 snprintf(tmp, size,
"Text=%s", link);
979 trans = lr_eval_string(transaction);
981 web_link(link, tmp, LAST);
1000 #define Y_TRANS_WEB_LINK( TRANSACTION, LINKNAME ) \ 1002 char *link = lr_eval_string(LINKNAME); \ 1003 char *tmp, *trans; \ 1006 if( !(strlen(link) > 0) ) \ 1008 lr_error_message("Zero-length link name - correlation error?"); \ 1009 lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_AUTO); \ 1013 size = strlen(link) + strlen("Text=") +1; \ 1014 tmp = y_mem_alloc(size); \ 1015 snprintf(tmp, size, "Text=%s", link); \ 1017 trans = lr_eval_string(TRANSACTION); \ 1018 y_start_transaction(trans); \ 1019 web_link(link, tmp, LAST); \ 1020 y_end_transaction(trans, LR_AUTO); \ 1053 char *step = lr_eval_string(
"{step}");
1054 char *stepchance = lr_eval_string(
"{stepchance}");
1055 char *head =
"step_chance_";
1058 while ( step && (
strcmp(step,
"END") != 0) )
1063 snprintf(tmp, size,
"%s%s", head, step);
1065 lr_save_string(stepchance, tmp);
1069 step = lr_eval_string(
"{step}");
1070 stepchance = lr_eval_string(
"{stepchance}");
1082 char *head =
"step_chance_";
1087 int rnum = (
y_rand() % 100);
1089 lr_log_message(
"Weighted stop chance evaluation for %s", stepname);
1091 snprintf( paramname, size,
"%s%s%s%s",
"{", head, stepname,
"}" );
1092 chancestr = lr_eval_string(paramname);
1094 if( (
strlen(chancestr) > 0) && (
strcmp(chancestr, paramname) != 0) )
1096 chance =
atoi(chancestr);
1102 if( rnum >= chance )
1104 lr_log_message(
"Stop!");
1105 lr_exit(LR_EXIT_ACTION_AND_CONTINUE, LR_AUTO);
1108 lr_log_message(
"No stop!");
1113 #endif // _Y_TRANSACTION_C_ void y_set_transaction_prefix(char *transaction_prefix)
Y-lib string function library.
int y_run_transaction_start_trigger()
void y_setup()
Ylib setup - determines and stores the identity of the virtual user.
void y_set_current_sub_transaction_name(char *trans_name)
void y_session_timer_end(int required_session_duration, int force_pause)
y_trans_end_impl_func * _y_trans_end_impl
End transaction implementation pointer. Default lr_end_transaction().
int( y_trigger_func)()
Transaction trigger support typedef.
y_trans_start_impl_func * _y_trans_start_impl
Start transaction implementation pointer. Default lr_start_transaction().
int _y_wasted_time_graph
INTERNAL: Whether to create a graph detailing wasted time. Debugging option.
y_trigger_func * _y_trigger_start_sub_trans
Standard C function headers.
int y_start_sub_transaction_with_number(char *transaction_name, int transaction_number)
int y_end_transaction(char *transaction_name, int status)
int y_increment_transaction_nr()
void y_waterfall_random_weighted_continue(char *stepname)
char * y_calculate_actual_transaction_prefix(const char *transaction_prefix)
Transaction name factory helper.
int( y_trans_start_impl_func)(char *trans_name)
void y_set_next_transaction_nr(int trans_nr)
void y_session_transaction_count_report(char *session_name)
void y_create_new_transaction_name(const char *transaction_name, const char *transaction_prefix, int transaction_nr)
merc_timer_handle_t y_session_timer
Session timer variable for session timer support.
void y_create_new_sub_transaction_name(const char *transaction_name, const char *transaction_prefix, const int transaction_nr, const int sub_transaction_nr)
void y_save_transaction_end_status(char *transaction_name, const char *saveparam, int status)
char * y_mem_alloc(size_t size)
Ylib wrapper for malloc()
int y_start_transaction(char *transaction_name)
int y_run_sub_transaction_end_trigger()
int( y_trans_end_impl_func)(char *trans_name, int status)
int y_session_transaction_count_increment()
void y_set_add_group_to_transaction(int add_group_to_trans)
y_trans_end_impl_func * y_get_transaction_end_implementation()
void y_set_current_transaction_name(char *trans_name)
int y_post_increment_transaction_nr()
int atoi(const char *string)
Documented at http://www.cplusplus.com/reference/cstdlib/atoi/.
int strcmp(const char *string1, const char *string2)
Documented at http://www.cplusplus.com/reference/cstring/strcmp/.
void y_log_error(char *message)
Log an error message, with a timestamp, if extra logging is enabled.
void y_resume_transaction_block(char *transaction_prefix)
y_trans_start_impl_func * y_get_transaction_start_implementation()
void y_create_next_sub_transaction_name(const char *transaction_name)
void y_set_transaction_start_implementation(y_trans_start_impl_func *trans_start_func)
void y_session_transaction_count_reset()
void y_start_action_block(char *transaction_prefix)
int _y_add_group_to_trans
INTERNAL: Whether to add the name of the vuser group to the transaction names. 1 = on...
void __y_do_not_call_this_is_a_workaround_that_only_exists_to_prevent_a_null_dereference_error_in_vugen_when_running()
Workaround for a bug in LR 11.
int y_get_next_transaction_nr()
char * y_get_transaction_prefix()
int y_get_next_sub_transaction_nr()
#define Y_TRANS_STATUS_NONE
Transaction status tracking.
int y_end_sub_transaction(char *transaction_name, int status)
int _y_transaction_nr
INTERNAL: Transaction counting for transaction blocks:
void y_session_timer_start(char *session_name)
void y_start_transaction_block(char *transaction_prefix)
void y_trans_web_link(char *transaction, char *linkname)
char * y_get_current_sub_transaction_name()
int y_run_sub_transaction_start_trigger()
void y_set_sub_transaction_start_trigger(y_trigger_func *trigger_function)
void y_set_transaction_end_implementation(y_trans_end_impl_func *trans_end_func)
void y_set_next_sub_transaction_nr(int trans_nr)
void y_end_action_block()
size_t strlen(const char *string)
Documented at http://www.cplusplus.com/reference/cstring/strlen/.
int y_is_empty_parameter(const char *param_name)
Test if the given parameter is empty or not yet set. (These are two different things..) It would be nice if loadrunner had a builtin for this.
Collection of miscellaneous support functions.
void y_set_sub_transaction_end_trigger(y_trigger_func *trigger_function)
int y_post_increment_sub_transaction_nr()
Logging-related y-lib functions.
char * y_get_current_transaction_name()
y_trigger_func * _y_trigger_end_sub_trans
int _y_sub_transaction_nr
INTERNAL: Transaction counting for sub transactions:
void y_set_transaction_start_trigger(y_trigger_func *trigger_function)
void y_setup_step_waterfall()
int snprintf(char *buffer, size_t n, const char *format_string,...)
Documented at http://www.cplusplus.com/reference/cstdio/snprintf/. This function was introduced by t...
int _y_trans_status
INTERNAL: Transaction status tracking.
long y_rand(void)
Generate a random (integer) number between 0 and Y_RAND_MAX (30 bit maxint).
char * y_virtual_user_group
The virtual user group, as reported by lr_whoami().
char * y_get_parameter(const char *param_name)
Get the content of a parameter and return it as a char *.
void y_set_transaction_end_trigger(y_trigger_func *trigger_function)
y_trigger_func * _y_trigger_start_trans
#define Y_TRANS_STATUS_AUTO_STARTED
Transaction status tracking.
char * y_get_parameter_or_null(const char *param_name)
Get the content of a parameter and return it as a char *, or return NULL if it wasn't set...
int y_get_transaction_running()
int y_start_transaction_with_number(char *transaction_name, int transaction_number)
#define Y_TRANS_STATUS_STARTED
Transaction status tracking.
void y_create_next_transaction_name(const char *transaction_name)
void y_pause_transaction_block()
void y_end_transaction_block()
int y_run_transaction_end_trigger()
y_trigger_func * _y_trigger_end_trans
int y_increment_sub_transaction_nr()
void free(void *mem_address)
Documented at http://www.cplusplus.com/reference/cstdlib/free/.
int y_get_last_transaction_status()
int y_session_transaction_count
Transaction counting support for sessions.
int y_start_sub_transaction(char *transaction_name)