[asterisk-commits] rmudgett: branch 12 r397809 - /branches/12/main/astmm.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 27 13:50:02 CDT 2013


Author: rmudgett
Date: Tue Aug 27 13:49:58 2013
New Revision: 397809

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397809
Log:
Made MALLOC_DEBUG less CPU intensive by default.

Storing a backtrace for each allocation in anticipation of a memory
management problem is very CPU intensive.

* Added the CLI "memory backtrace {on|off}" command to request that the
backtrace be gathered only on request.  The backtrace is off by default.

(issue ASTERISK-22221)
Reported by: Matt Jordan

Modified:
    branches/12/main/astmm.c

Modified: branches/12/main/astmm.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/astmm.c?view=diff&rev=397809&r1=397808&r2=397809
==============================================================================
--- branches/12/main/astmm.c (original)
+++ branches/12/main/astmm.c Tue Aug 27 13:49:58 2013
@@ -142,6 +142,8 @@
 static enum summary_opts atexit_summary;
 /*! Nonzero if the unfreed regions are listed at exit. */
 static int atexit_list;
+/*! Nonzero if the memory allocation backtrace is enabled. */
+static int backtrace_enabled;
 
 #define HASH(a)		(((unsigned long)(a)) % ARRAY_LEN(regions))
 
@@ -235,7 +237,7 @@
 	reg->cache = cache;
 	reg->lineno = lineno;
 	reg->which = which;
-	reg->bt = ast_bt_create();
+	reg->bt = backtrace_enabled ? ast_bt_create() : NULL;
 	ast_copy_string(reg->file, file, sizeof(reg->file));
 	ast_copy_string(reg->func, func, sizeof(reg->func));
 
@@ -975,11 +977,49 @@
 	return CLI_SUCCESS;
 }
 
+static char *handle_memory_backtrace(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	switch (cmd) {
+	case CLI_INIT:
+		e->command = "memory backtrace";
+		e->usage =
+			"Usage: memory backtrace {on|off}\n"
+			"       Enable dumping an allocation backtrace with memory diagnostics.\n"
+			"       Note that saving the backtrace data for each allocation\n"
+			"       can be CPU intensive.\n";
+		return NULL;
+	case CLI_GENERATE:
+		if (a->pos == 2) {
+			const char * const options[] = { "off", "on", NULL };
+
+			return ast_cli_complete(a->word, options, a->n);
+		}
+		return NULL;
+	}
+
+	if (a->argc != 3) {
+		return CLI_SHOWUSAGE;
+	}
+
+	if (ast_true(a->argv[2])) {
+		backtrace_enabled = 1;
+	} else if (ast_false(a->argv[2])) {
+		backtrace_enabled = 0;
+	} else {
+		return CLI_SHOWUSAGE;
+	}
+
+	ast_cli(a->fd, "The memory backtrace is: %s\n", backtrace_enabled ? "On" : "Off");
+
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cli_memory[] = {
 	AST_CLI_DEFINE(handle_memory_atexit_list, "Enable memory allocations not freed at exit list."),
 	AST_CLI_DEFINE(handle_memory_atexit_summary, "Enable memory allocations not freed at exit summary."),
 	AST_CLI_DEFINE(handle_memory_show_allocations, "Display outstanding memory allocations"),
 	AST_CLI_DEFINE(handle_memory_show_summary, "Summarize outstanding memory allocations"),
+	AST_CLI_DEFINE(handle_memory_backtrace, "Enable dumping an allocation backtrace with memory diagnostics."),
 };
 
 AST_LIST_HEAD_NOLOCK(region_list, ast_region);




More information about the asterisk-commits mailing list