summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGeorge Joseph <gjoseph@digium.com>2017-05-08 15:11:19 -0600
committerGeorge Joseph <gjoseph@digium.com>2017-05-08 16:49:13 -0500
commit201346fb7dff373d73a0663d1b05d968685013c7 (patch)
tree002cae51072ab320208696a92857bd515270eecb /tests
parentd96f755682c16141962d0fc7914cd46263f8a961 (diff)
logger: Added logger_queue_limit to the configuration options.
All log messages go to a queue serviced by a single thread which does all the IO. This setting controls how big that queue can get (and therefore how much memory is allocated) before new messages are discarded. The default is 1000. Should something go bezerk and log tons of messages in a tight loop, this will prevent memory escalation. When the limit is reached, a WARNING is logged to that effect and messages are discarded until the queue is empty again. At that time another WARNING will be logged with the count of discarded messages. There's no "low water mark" for this queue because the logger thread empties the entire queue and processes it in 1 batch before going back and waiting on the queue again. Implementing a low water mark would mean additional locking as the thread processes each message and it's not worth it. A "test" was added to test_logger.c but since the outcome is non-deterministic, it's really just a cli command, not a unit test. Change-Id: Ib4520c95e1ca5325dbf584c7989ce391649836d1
Diffstat (limited to 'tests')
-rw-r--r--tests/test_logger.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/test_logger.c b/tests/test_logger.c
index 07a4c369b..59ee3e6c1 100644
--- a/tests/test_logger.c
+++ b/tests/test_logger.c
@@ -188,9 +188,76 @@ static char *handle_cli_performance_test(struct ast_cli_entry *e, int cmd, struc
return CLI_SUCCESS;
}
+static char *handle_cli_queue_test(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ unsigned int level;
+ int current_queue_limit;
+ unsigned int x;
+ struct timeval start, end;
+ int elapsed;
+ char tmppath[] = "/tmp/asterisk_logger_queue.XXXXXX";
+ int fd;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "logger test queue";
+ e->usage = ""
+ "Usage: logger test queue\n"
+ "";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ fd = mkstemp(tmppath);
+ if (fd < 0) {
+ ast_cli(a->fd, "Test: Failed, could not create temporary log file '%s'.\n", tmppath);
+ return CLI_SUCCESS;
+ }
+
+ level = ast_logger_register_level("queuetest");
+ if (level < 0) {
+ ast_cli(a->fd, "Test: Failed, could not register level 'queuetest'.\n");
+ return CLI_SUCCESS;
+ }
+ ast_cli(a->fd, "Test: got level %u for 'queuetest'.\n", level);
+
+ if (ast_logger_create_channel(tmppath, "queuetest") != AST_LOGGER_SUCCESS) {
+ ast_cli(a->fd, "Test: Unable to create logger channel '%s'\n", tmppath);
+ goto error;
+ }
+
+ current_queue_limit = ast_logger_get_queue_limit();
+ ast_cli(a->fd, "Test: Current queue limit: %d. Setting to 100 for test.\n", current_queue_limit);
+ ast_logger_set_queue_limit(100);
+
+ ast_cli(a->fd, "Test: You should see SOME 'exceeded' and 'resumed' messages after the test "
+ "is completed. How many is dependent on system resources.\n");
+
+ start = ast_tvnow();
+ for (x = 0; x < 10000; x++) {
+ ast_log_dynamic_level(level, "Performance test log message %2d\n", x);
+ }
+ end = ast_tvnow();
+ elapsed = ast_tvdiff_ms(end, start);
+ ast_cli(a->fd, "Test: 10,000 messages in %f seconds.\n", (float) elapsed / 1000);
+ ast_cli(a->fd, "Test: Completed. Resetting queue limit to %d.\n", current_queue_limit);
+ ast_logger_set_queue_limit(current_queue_limit);
+
+error:
+
+ ast_logger_remove_channel(tmppath);
+ ast_logger_unregister_level("queuetest");
+ close(fd);
+ unlink(tmppath);
+
+ return CLI_SUCCESS;
+}
+
static struct ast_cli_entry cli_logger[] = {
AST_CLI_DEFINE(handle_cli_dynamic_level_test, "Test the dynamic logger level implementation"),
AST_CLI_DEFINE(handle_cli_performance_test, "Test the logger performance"),
+ AST_CLI_DEFINE(handle_cli_queue_test, "Test the logger queue"),
};
static int unload_module(void)