[asterisk-commits] russell: branch russell/frame_caching r38551 - /team/russell/frame_caching/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sun Jul 30 21:46:32 MST 2006


Author: russell
Date: Sun Jul 30 23:46:31 2006
New Revision: 38551

URL: http://svn.digium.com/view/asterisk?rev=38551&view=rev
Log:
Add some code that keeps track of the different combinations of malloc'd
frame elements that are passed to ast_frfree().

Modified:
    team/russell/frame_caching/frame.c

Modified: team/russell/frame_caching/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/frame.c?rev=38551&r1=38550&r2=38551&view=diff
==============================================================================
--- team/russell/frame_caching/frame.c (original)
+++ team/russell/frame_caching/frame.c Sun Jul 30 23:46:31 2006
@@ -47,6 +47,15 @@
 static struct ast_frame *headerlist = NULL;
 AST_MUTEX_DEFINE_STATIC(framelock);
 #endif
+
+static unsigned int mallocd_header_data_src = 0;
+static unsigned int mallocd_header_data = 0;
+static unsigned int mallocd_header_src = 0;
+static unsigned int mallocd_data_src = 0;
+static unsigned int mallocd_header = 0;
+static unsigned int mallocd_data = 0;
+static unsigned int mallocd_src = 0;
+static unsigned int mallocd_none = 0;
 
 #define SMOOTHER_SIZE 8000
 
@@ -274,6 +283,35 @@
  */
 void ast_frfree(struct ast_frame *fr)
 {
+	switch (fr->mallocd) {
+	case AST_MALLOCD_HDR | AST_MALLOCD_DATA | AST_MALLOCD_SRC:
+		ast_atomic_fetchadd_int((int *) &mallocd_header_data_src, 1);
+		break;
+	case AST_MALLOCD_HDR | AST_MALLOCD_DATA:
+		ast_atomic_fetchadd_int((int *) &mallocd_header_data, 1);
+		break;
+	case AST_MALLOCD_HDR | AST_MALLOCD_SRC:
+		ast_atomic_fetchadd_int((int *) &mallocd_header_src, 1);
+		break;
+	case AST_MALLOCD_DATA | AST_MALLOCD_SRC:
+		ast_atomic_fetchadd_int((int *) &mallocd_data_src, 1);
+		break;
+	case AST_MALLOCD_HDR:
+		ast_atomic_fetchadd_int((int *) &mallocd_header, 1);
+		break;
+	case AST_MALLOCD_DATA:
+		ast_atomic_fetchadd_int((int *) &mallocd_data, 1);
+		break;
+	case AST_MALLOCD_SRC:
+		ast_atomic_fetchadd_int((int *) &mallocd_src, 1);
+		break;
+	case 0:
+		ast_atomic_fetchadd_int((int *) &mallocd_none, 1);
+		break;
+	default:
+		ast_log(LOG_ERROR, "Totally bogus frame malloc'd value of '%d'!\n", fr->mallocd);
+	}
+
 	if (fr->mallocd & AST_MALLOCD_DATA) {
 		if (fr->data) 
 			free(fr->data - fr->offset);
@@ -877,6 +915,30 @@
 "       Displays debugging statistics from framer\n";
 #endif
 
+static int show_frfree_stats(int fd, int argc, char *argv[])
+{
+	if (argc != 3)
+		return RESULT_SHOWUSAGE;
+
+	ast_cli(fd, "Current ast_free() malloc'd frame component statistics:\n"
+			"------------------------------------------------------------\n"
+			"header & data & src:   %d\n"
+			"header & data:         %d\n"
+			"header & src:          %d\n"
+			"data & src:            %d\n"
+			"header:                %d\n"
+			"data:                  %d\n"
+			"src:                   %d\n",
+			mallocd_header_data_src, mallocd_header_data, mallocd_header_src,
+			mallocd_data_src, mallocd_header, mallocd_data, mallocd_src);
+	
+	return RESULT_SUCCESS;
+}
+
+static char frfree_stats_usage[] =
+"Usage: show frfree stats\n"
+"	Display information about malloc'd frame elements passed to ast_frfree\n";
+
 /* Builtin Asterisk CLI-commands for debugging */
 static struct ast_cli_entry my_clis[] = {
 { { "show", "codecs", NULL }, show_codecs, "Shows codecs", frame_show_codecs_usage },
@@ -887,6 +949,7 @@
 #ifdef TRACE_FRAMES
 { { "show", "frame", "stats", NULL }, show_frame_stats, "Shows frame statistics", frame_stats_usage },
 #endif
+{ { "show", "frfree", "stats", NULL }, show_frfree_stats, "Show ast_frfree stats", frfree_stats_usage },
 };
 
 int init_framer(void)



More information about the asterisk-commits mailing list