[svn-commits] russell: branch russell/frame_caching r38632 - in /team/russell/frame_caching...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Jul 31 19:25:11 MST 2006


Author: russell
Date: Mon Jul 31 21:25:10 2006
New Revision: 38632

URL: http://svn.digium.com/view/asterisk?rev=38632&view=rev
Log:
Gather some more statistics for the ast_frame and iax_frame caches

So far, the ast_frame cache is working great, but I'm not happy with how well
the iax_frame cache is working ...

Modified:
    team/russell/frame_caching/channels/chan_iax2.c
    team/russell/frame_caching/channels/iax2-parser.c
    team/russell/frame_caching/channels/iax2-parser.h
    team/russell/frame_caching/frame.c

Modified: team/russell/frame_caching/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/channels/chan_iax2.c?rev=38632&r1=38631&r2=38632&view=diff
==============================================================================
--- team/russell/frame_caching/channels/chan_iax2.c (original)
+++ team/russell/frame_caching/channels/chan_iax2.c Mon Jul 31 21:25:10 2006
@@ -1069,8 +1069,10 @@
 {
 	struct iax_frame *new = iax_frame_new(DIRECTION_INGRESS, fr->af.datalen);
 	if (new) {
-		memcpy(new, fr, sizeof(struct iax_frame));	
+		size_t mallocd_datalen = new->mallocd_datalen;
+		memcpy(new, fr, sizeof(*new));
 		iax_frame_wrap(new, &fr->af);
+		new->mallocd_datalen = mallocd_datalen;
 		new->data = NULL;
 		new->datalen = 0;
 		new->direction = DIRECTION_INGRESS;
@@ -2077,7 +2079,17 @@
 	ast_cli(fd, "    IAX Statistics\n");
 	ast_cli(fd, "---------------------\n");
 	ast_cli(fd, "Outstanding frames: %d (%d ingress, %d egress)\n", iax_get_frames(), iax_get_iframes(), iax_get_oframes());
-	ast_cli(fd, "Packets in transmit queue: %d dead, %d final, %d total\n", dead, final, cnt);
+	ast_cli(fd, "Packets in transmit queue: %d dead, %d final, %d total\n\n", dead, final, cnt);
+	
+	ast_cli(fd, "    IAX Frame Cache Statistics\n"
+			"---------------------------------------\n"
+			"Added to Cache:     %d\n"
+			"Removed from Cache: %d\n"
+			"Frames Allocated:   %d\n"
+			"Frames Freed        %d\n\n",
+			iax_get_added_to_cache(), iax_get_removed_from_cache(),
+			iax_get_frames_allocated(), iax_get_frames_freed());
+
 	return RESULT_SUCCESS;
 }
 

Modified: team/russell/frame_caching/channels/iax2-parser.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/channels/iax2-parser.c?rev=38632&r1=38631&r2=38632&view=diff
==============================================================================
--- team/russell/frame_caching/channels/iax2-parser.c (original)
+++ team/russell/frame_caching/channels/iax2-parser.c Mon Jul 31 21:25:10 2006
@@ -49,6 +49,11 @@
 static int frames = 0;
 static int iframes = 0;
 static int oframes = 0;
+
+static unsigned int added_to_cache = 0;
+static unsigned int removed_from_cache = 0;
+static unsigned int frames_allocated = 0;
+static unsigned int frames_freed = 0;
 
 static void frame_cache_cleanup(void *data);
 
@@ -947,14 +952,19 @@
 				AST_LIST_REMOVE_CURRENT(iax_frames, list);
 				memset(fr, 0, sizeof(*fr));
 				fr->mallocd_datalen = mallocd_datalen;
+				ast_atomic_fetchadd_int((int *) &removed_from_cache, 1);
 				break;
 			}
 		}
 		AST_LIST_TRAVERSE_SAFE_END
 	}
 
-	if (!fr && !(fr = ast_calloc(1, sizeof(*fr) + datalen)))
-		return NULL;
+	if (!fr) {
+		if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
+			return NULL;
+		ast_atomic_fetchadd_int((int *) &frames_allocated, 1);
+		fr->mallocd_datalen = datalen;
+	}
 
 	fr->direction = direction;
 	fr->retrans = -1;
@@ -986,15 +996,18 @@
 
 	if (!cache) {
 		free(fr);
+		ast_atomic_fetchadd_int((int *) &frames_freed, 1);
 		return;
 	}
 
 	if (!(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
 		free(fr);
+		ast_atomic_fetchadd_int((int *) &frames_freed, 1);
 		return;
 	}
 
 	AST_LIST_INSERT_HEAD(iax_frames, fr, list);
+	ast_atomic_fetchadd_int((int *) &added_to_cache, 1);
 }
 
 static void frame_cache_cleanup(void *data)
@@ -1002,8 +1015,10 @@
 	struct iax_frames *frames = data;
 	struct iax_frame *cur;
 
-	while ((cur = AST_LIST_REMOVE_HEAD(frames, list)))
+	while ((cur = AST_LIST_REMOVE_HEAD(frames, list))) {
 		__iax_frame_free(cur, 0);
+		ast_atomic_fetchadd_int((int *) &frames_freed, 1);
+	}
 
 	free(frames);
 }
@@ -1016,3 +1031,9 @@
 int iax_get_frames(void) { return frames; }
 int iax_get_iframes(void) { return iframes; }
 int iax_get_oframes(void) { return oframes; }
+
+unsigned int iax_get_added_to_cache(void) { return added_to_cache; }
+unsigned int iax_get_removed_from_cache(void) { return removed_from_cache; }
+unsigned int iax_get_frames_allocated(void) { return frames_allocated; }
+unsigned int iax_get_frames_freed(void) { return frames_freed; }
+

Modified: team/russell/frame_caching/channels/iax2-parser.h
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/channels/iax2-parser.h?rev=38632&r1=38631&r2=38632&view=diff
==============================================================================
--- team/russell/frame_caching/channels/iax2-parser.h (original)
+++ team/russell/frame_caching/channels/iax2-parser.h Mon Jul 31 21:25:10 2006
@@ -152,6 +152,11 @@
 int iax_get_iframes(void);
 int iax_get_oframes(void);
 
+unsigned int iax_get_added_to_cache(void);
+unsigned int iax_get_removed_from_cache(void);
+unsigned int iax_get_frames_allocated(void);
+unsigned int iax_get_frames_freed(void);
+
 void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f);
 struct iax_frame *iax_frame_new(int direction, int datalen);
 void iax_frame_free(struct iax_frame *fr);

Modified: team/russell/frame_caching/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/frame.c?rev=38632&r1=38631&r2=38632&view=diff
==============================================================================
--- team/russell/frame_caching/frame.c (original)
+++ team/russell/frame_caching/frame.c Mon Jul 31 21:25:10 2006
@@ -60,6 +60,8 @@
 
 static unsigned int added_to_cache = 0;
 static unsigned int removed_from_cache = 0;
+static unsigned int headers_allocated = 0;
+static unsigned int headers_freed = 0;
 
 static void frame_cache_cleanup(void *data);
 
@@ -291,6 +293,8 @@
 	if (!(f = ast_calloc(1, sizeof(*f))))
 		return NULL;
 
+	ast_atomic_fetchadd_int((int *) &headers_allocated, 1);
+
 	f->mallocd_hdr_len = sizeof(*f);
 #ifdef TRACE_FRAMES
 	AST_LIST_LOCK(&headerlist);
@@ -307,8 +311,10 @@
 	struct ast_frames *frames = data;
 	struct ast_frame *f;
 
-	while ((f = AST_LIST_REMOVE_HEAD(frames, frame_list)))
+	while ((f = AST_LIST_REMOVE_HEAD(frames, frame_list))) {
 		free(f);
+		ast_atomic_fetchadd_int((int *) &headers_freed, 1);
+	}
 	
 	free(frames);
 }
@@ -372,6 +378,7 @@
 		AST_LIST_UNLOCK(&headerlist);
 #endif			
 		free(fr);
+		ast_atomic_fetchadd_int((int *) &headers_freed, 1);
 	}
 }
 
@@ -472,6 +479,7 @@
 	if (!buf) {
 		if (!(buf = ast_calloc(1, len)))
 			return NULL;
+		ast_atomic_fetchadd_int((int *) &headers_allocated, 1);
 		out = buf;
 		out->mallocd_hdr_len = len;
 	}
@@ -995,8 +1003,11 @@
 	ast_cli(fd, "Frame cache statistics\n"
 			"------------------------------------------------------------\n"
 			"Added to cache:      %d\n"
-			"Removed from cache:  %d\n",
-			added_to_cache, removed_from_cache);
+			"Removed from cache:  %d\n"
+			"Headers Allocated:   %d\n"
+			"Headers Freed:       %d\n\n",
+			added_to_cache, removed_from_cache,
+			headers_allocated, headers_freed);
 	
 	return RESULT_SUCCESS;
 }



More information about the svn-commits mailing list