]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add "stats memory" command
authorAlan T. DeKok <aland@freeradius.org>
Tue, 9 Jun 2015 14:59:44 +0000 (10:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 9 Jun 2015 15:00:57 +0000 (11:00 -0400)
src/main/command.c

index 736d21a0a0ff94bb9de70c37733a468a7fedbc3b..e8f0ce91460da7c91f8f9367eecae96eae816041 100644 (file)
@@ -2176,6 +2176,38 @@ static int command_stats_queue(rad_listen_t *listener, UNUSED int argc, UNUSED c
 }
 #endif
 
+#ifndef NDEBUG
+static int command_stats_memory(rad_listen_t *listener, int argc, char *argv[])
+{
+
+       if (!main_config.debug_memory || !main_config.memory_report) {
+               cprintf(listener, "No memory debugging was enabled.\n");
+               return CMD_OK;
+       }
+
+       if (argc == 0) goto fail;
+
+       if (strcmp(argv[0], "total") == 0) {
+               cprintf(listener, "%zd\n", talloc_total_size(NULL));
+               return CMD_OK;
+       }
+
+       if (strcmp(argv[0], "blocks") == 0) {
+               cprintf(listener, "%zd\n", talloc_total_blocks(NULL));
+               return CMD_OK;
+       }
+
+       if (strcmp(argv[0], "full") == 0) {
+               cprintf(listener, "see stdout of the server for the full report.\n");
+               fr_log_talloc_report(NULL);
+               return CMD_OK;
+       }
+
+fail:
+       cprintf_error(listener, "Must use 'stats memory full' or 'stats memory total'\n");
+       return CMD_FAIL;
+}
+#endif
 
 #ifdef WITH_DETAIL
 static FR_NAME_NUMBER state_names[] = {
@@ -2540,6 +2572,12 @@ static fr_command_table_t command_table_stats[] = {
          "- show statistics for given socket",
          command_stats_socket, NULL },
 
+#ifndef NDEBUG
+       { "memory", FR_READ,
+         "stats memory - show statistics on used memory",
+         command_stats_memory, NULL },
+#endif
+
        { NULL, 0, NULL, NULL, NULL }
 };
 #endif