39 int _y_extra_logging = 0;
46 unsigned int _y_log_level = LR_MSG_CLASS_DISABLE_LOG;
62 struct tm *resulttime;
63 static char YMDHMSm[24];
68 snprintf(YMDHMSm,
sizeof YMDHMSm,
"%04u-%02u-%02u %02u:%02u:%02u.%03u",
96 #define y_timestamp 0_y_timestamp_no_longer_exists_please_use_y_get_current_time 115 _y_extra_logging = 1;
130 char *logLine =
"%s: VUserId: %d, Host: %s, %s";
133 if( _y_extra_logging )
135 int log_level = lr_get_debug_message();
137 lr_set_debug_message(LR_MSG_CLASS_DISABLE_LOG | LR_MSG_CLASS_AUTO_LOG, LR_SWITCH_OFF);
138 lr_set_debug_message(
139 LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_RESULT_DATA | LR_MSG_CLASS_PARAMETERS | LR_MSG_CLASS_FULL_TRACE,
142 lr_set_debug_message(log_level, LR_SWITCH_ON);
155 char *msg = lr_eval_string(message);
158 lr_fail_trans_with_error(msg);
170 lr_save_string(lr_eval_string(message),
"_log_msg");
171 msg = lr_eval_string(
"Warning: {_log_msg}");
185 _y_log_level = lr_get_debug_message();
200 lr_set_debug_message(LR_MSG_CLASS_DISABLE_LOG, LR_SWITCH_ON);
203 lr_set_debug_message(LR_MSG_CLASS_AUTO_LOG, LR_SWITCH_OFF);
245 lr_set_debug_message(LR_MSG_CLASS_BRIEF_LOG, LR_SWITCH_ON);
260 lr_set_debug_message(
261 LR_MSG_CLASS_EXTENDED_LOG | LR_MSG_CLASS_RESULT_DATA | LR_MSG_CLASS_PARAMETERS | LR_MSG_CLASS_FULL_TRACE,
280 lr_set_debug_message(_y_log_level, LR_SWITCH_ON);
304 if(_y_log_level == LR_MSG_CLASS_DISABLE_LOG)
331 lr_log_message( message );
356 size_t string_length;
362 string_length =
strlen(content)
371 snprintf(log, string_length,
"%.15s,%s,%d,%d,%s",
372 lr_eval_string(
"{DATE_TIME_STRING}"),
404 static int disk_space_warning_given = 0;
405 double free_space_percentage;
406 char* log_folder = lr_get_attrib_string(
"out");
409 if( disk_space_warning_given )
419 hostname = lr_get_host_name();
420 lr_save_string(hostname,
"y_hostname_generator");
421 lr_user_data_point( lr_eval_string(
"disk_space_{y_hostname_generator}_free_percentage"), free_space_percentage);
423 if( free_space_percentage < max_free_percentage )
426 lr_set_transaction(lr_eval_string(
"---DISK SPACE LOW IN LOG FOLDER FOR {y_hostname_generator}---"), 0, LR_FAIL);
427 lr_error_message(
"Diskspace low on %s in folder %s. %.2lf%% remaining, exceeding the limit of %.21f%% Logging turned off for user id %d for the remainder of the test!",
428 hostname, log_folder, free_space_percentage, max_free_percentage,
y_virtual_user_id);
429 disk_space_warning_given = 1;
459 char* log_folder = lr_get_attrib_string(
"out");
460 double free_mebibytes;
461 static double max_free_mebibytes = -1;
462 double mebibytes_used;
463 static int disk_space_warning_given = 0;
466 if( disk_space_warning_given )
474 lr_log_message(
"y_disk_space_usage_guard: current free: %f MB, max free: %f MB, limit: %f MB used in folder: %s",
475 free_mebibytes, max_free_mebibytes, limit_mebibytes_used, log_folder);
477 if(max_free_mebibytes < 0)
479 lr_log_message(
"Storing free space as detected maximum");
480 max_free_mebibytes = free_mebibytes;
483 else if(max_free_mebibytes < free_mebibytes)
485 lr_output_message(
"Warning: Free disk space increased from %f to %f, test disk space usage measurements may have become unreliable.", max_free_mebibytes, free_mebibytes);
486 max_free_mebibytes = free_mebibytes;
491 mebibytes_used = max_free_mebibytes - free_mebibytes;
494 hostname = lr_get_host_name();
495 lr_save_string(hostname,
"y_hostname_generator");
496 lr_user_data_point( lr_eval_string(
"disk_space_{y_hostname_generator}_free_mebibytes"), free_mebibytes);
497 lr_user_data_point( lr_eval_string(
"disk_space_{y_hostname_generator}_used_mebibytes"), mebibytes_used);
499 if( mebibytes_used >= limit_mebibytes_used )
502 lr_set_transaction(lr_eval_string(
"---DISKSPACE USAGE TOO HIGH IN LOG FOLDER FOR {y_hostname_generator}---"), 0, LR_FAIL);
503 lr_output_message(
"Disk space used on host %s in folder %s was %f mebibytes, reaching the limit of %f. Logging turned off for user id %d for the remainder of the test!",
505 disk_space_warning_given = 1;
510 #endif // _Y_LOGGING_C_ void ftime(struct _timeb *time)
Documented at http://www.qnx.com/developers/docs/6.5.0/topic/com.qnx.doc.neutrino_lib_ref/f/ftime.html .
void y_setup()
Ylib setup - determines and stores the identity of the virtual user.
void y_log_force_message(char *message)
Log a message forcefully, bypassing the current log settings.
int tm_min
minutes after the hour - [0,59]
void y_disk_space_usage_guard(double limit_mebibytes_used)
Detect excessive disk usage by the test and turn all further logging off if more than a specific limi...
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)
int tm_mday
day of the month - [1,31]
void y_log_restore()
Restore the loglevel to previous state. To be exact, it will restore it to the state it was in before...
void y_log_set_extended()
Set the log level to show all messages, including extended result data, parameters, and tracing information.
int y_write_to_file(char *filename, char *content)
Write a string to a file.
int tm_year
years since 1900
int y_write_to_log(char *filename, char *content)
Write a string prepended with date and time to the specified (log)file.
char * y_make_datetimestamp(time_t time, unsigned short millitm)
Convert a unixtime style timestamp to a date and time represented as YYYY-MM-DD HH:MM:SS.mmm.
int y_scid
The virtual user scid, as reported by lr_whoami().
char * y_mem_alloc(size_t size)
Ylib wrapper for malloc()
void y_log_save()
Save the loglevel for later restoration through y_log_restore().
Contains core ylib support functions needed for the functioning of the library.
void y_log_to_report(char *message)
If extra logging was enabled force a line to be logged to the logfile - even if regular logging was t...
struct tm * localtime(const time_t *timer)
Documented at http://www.cplusplus.com/reference/ctime/localtime/.
void y_log_error(char *message)
Log an error message, with a timestamp, if extra logging is enabled.
int y_virtual_user_id
The virtual user id, as reported by lr_whoami().
int tm_mon
months since January - [0,11]
void y_log_turn_off_permanently()
Turn all logging off and make sure it stays that way.
char * y_get_datetimestamp()
Returns the current time converted represented as YYYY-MM-DD HH:MM:SS.mmm.
int abs(int n)
Documented at http://www.cplusplus.com/reference/cstdlib/abs/.
long time_t
Type time_t can hold a Unix timestamp.
void y_datetime()
Saves the current date/time into a LR-parameter.
void y_setup_logging()
Turn on 'extra logging', when available.
void y_log_turn_off()
Save the current loglevel and turn off logging.
void y_log_turn_on()
Turn logging on.
Documented at http://www.cplusplus.com/reference/ctime/tm/. Values outside of valid ranges can be us...
size_t strlen(const char *string)
Documented at http://www.cplusplus.com/reference/cstring/strlen/.
Collection of miscellaneous support functions.
void y_disk_space_guard(double max_free_percentage)
Detect low disk space situations on the generator and turn all logging off if not enough space is lef...
unsigned short millitm
Milliseconds. Actual accuracy may be lower.
void y_log_set_brief()
Set the log level to "brief" messages only.
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...
void y_log_turn_off_without_saving()
Force all logging off unconditionally, without saving the old state.
char * y_virtual_user_group
The virtual user group, as reported by lr_whoami().
double log(double x)
Documented at http://www.cplusplus.com/reference/cmath/log/.
int tm_sec
seconds after the minute - [0,61] (or [0,59] when leap seconds are not supported) ...
void y_log_warning(char *message)
Log a warning, with a timestamp, if extra logging is enabled.
int tm_hour
hours since midnight - [0,23]
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.
time_t time(time_t *timeptr)
Documented at http://www.cplusplus.com/reference/ctime/time/.
void free(void *mem_address)
Documented at http://www.cplusplus.com/reference/cstdlib/free/.
time_t time
Time, in seconds, since the Unix Epoch, 1 January 1970 00:00:00 Coordinated Universal Time (UTC)...
Used by ftime. Defined as _timeb (instead of timeb) just as in the on-line Help.