Wednesday, November 7, 2012

Loadrunner Logging Options

There are a number of different functions provided by Loadrunner for logging, including:

  • lr_message
  • lr_output_message
  • lr_error_message
  • lr_log_message
  • lr_debug_message
  • lr_vuser_status_message
This post provides a script illustrating each of these logging methods, and a description of the differences.

lr_message
The limitation of lr_message is that no source file (such as Action.c) or line number is provided.

lr_output_message
lr_output_message includes source file and line number information which is useful for debugging issues.

lr_error_message
lr_error_message flags the message as an error rather than informational.

lr_log_message
lr_log_message can reduce some network traffic during load tests by not sending messages to the load test output window.

lr_debug_message
lr_debug_message can write message conditionally on certain logging settings being enabled

lr_vuser_status_message
lr_vuser_status_message updates the vuser status field during load tests


The following script illustrates the various logging methods.

Script


Action()
{
// setup test message data
int msgLevel;
char *message = "This is a test message.";
        // save string to a parameter
        lr_save_string(message, "messageParam");

// lr_message test
lr_message("---------------------- lr_message --------------------------");
lr_message("--- lr_message does not show the source file and line number");
lr_message("--- lr_message: %s", message);
lr_message("----------------- end lr_message ---------------------");

// lr_output_message test
lr_message("------------------- lr_output_message -----------------------");
lr_message("--- lr_output_message does show the source file and line number");
lr_output_message("--- lr_output_message: %s", message);
lr_message("----------------- end lr_output_message ---------------------");

        // lr_error_message test
lr_message("------------------- lr_error_message -----------------------");
lr_message("--- lr_error_message writes a message with an Error log level");
lr_error_message("--- lr_error_message: %s", message);
lr_message("----------------- end lr_error_message ---------------------");

// lr_log_message test
lr_message("------------------- lr_log_message ------------------------");
lr_message("--- lr_log_message does not send messages to the output window and could therefore reduce network traffic between agent and load generator in some situations");
lr_log_message("--- lr_log_message: %s", message);
lr_message("----------------- end lr_log_message ---------------------");

// lr_debug_message test
lr_message("------------------- lr_debug_message -----------------------");
lr_message("--- lr_debug_message writes a message if the specified log settings are set");
    msgLevel=lr_get_debug_message();
if (msgLevel & LR_MSG_CLASS_BRIEF_LOG  ) {
lr_message("standard log is enabled");
} else if (msgLevel & LR_MSG_CLASS_EXTENDED_LOG  ) {
lr_message("extended log is enabled");
} else if (msgLevel & LR_MSG_CLASS_DISABLE_LOG  ) {
lr_message("log is disabled");


// log message if brief or extended log are enabled
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG, "--- lr_debug_message: %s", "This is written if brief or extended log is enabled");

// disable  brief and extended log
        lr_set_debug_message(LR_MSG_CLASS_BRIEF_LOG, LR_SWITCH_OFF); 
        lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG, LR_SWITCH_OFF);

// now the debug message should not be written
lr_debug_message(LR_MSG_CLASS_BRIEF_LOG | LR_MSG_CLASS_EXTENDED_LOG, "This should not be written to log because brief and extended log are both disabled");

// re-enable extended log
        lr_set_debug_message(LR_MSG_CLASS_EXTENDED_LOG, LR_SWITCH_ON);

lr_message("----------------- end lr_debug_message ---------------------");

// lr_vuser_status_message
// lr_log_message test
lr_message("------------------- lr_vuser_status_message ------------------------");
lr_message("--- lr_vuser_status_message updates the status field of the vuser status area.  It does not write to the log");
lr_vuser_status_message("--- lr_vuser_status_message: %s", message);
lr_message("----------------- end lr_vuser_status_message ---------------------");

return 0;
}



Output

Running Vuser...
Starting iteration 1.
Starting action Action.
---------------------- lr_message --------------------------
--- lr_message does not show the source file and line number
--- lr_message: This is a test message.
----------------- end lr_message ---------------------
------------------- lr_output_message -----------------------
--- lr_output_message does show the source file and line number
Action.c(19): --- lr_output_message: This is a test message.
----------------- end lr_output_message ---------------------
------------------- lr_error_message -----------------------
--- lr_error_message writes a message with an Error log level
Action.c(25): Error: --- lr_error_message: This is a test message.
----------------- end lr_error_message ---------------------
------------------- lr_log_message ------------------------
--- lr_log_message does not send messages to the output window and could therefore reduce network traffic between agent and load generator in some situations
--- lr_log_message: This is a test message.
----------------- end lr_log_message ---------------------
------------------- lr_debug_message -----------------------
--- lr_debug_message writes a message if the specified log settings are set
extended log is enabled
--- lr_debug_message: This is written if brief or extended log is enabled
----------------- end lr_debug_message ---------------------
------------------- lr_vuser_status_message ------------------------
--- lr_vuser_status_message updates the status field of the vuser status area.  It does not write to the log
----------------- end lr_vuser_status_message ---------------------
Ending action Action.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.

No comments:

Post a Comment