[asterisk-commits] russell: branch russell/frame_caching r41193 -
/team/russell/frame_caching/ch...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sat Aug 26 11:38:50 MST 2006
Author: russell
Date: Sat Aug 26 13:38:50 2006
New Revision: 41193
URL: http://svn.digium.com/view/asterisk?rev=41193&view=rev
Log:
add stuff for profiling iax_frame caching
Modified:
team/russell/frame_caching/channels/iax2-parser.c
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=41193&r1=41192&r2=41193&view=diff
==============================================================================
--- team/russell/frame_caching/channels/iax2-parser.c (original)
+++ team/russell/frame_caching/channels/iax2-parser.c Sat Aug 26 13:38:50 2006
@@ -55,6 +55,12 @@
static unsigned int frames_allocated = 0;
static unsigned int frames_freed = 0;
+#define ENABLE_FRAME_CACHING
+
+static int iax_frame_new_profile = -1;
+static int iax_frame_free_profile = -1;
+
+#ifdef ENABLE_FRAME_CACHING
static void frame_cache_cleanup(void *data);
/*! \brief A per-thread cache of iax_frame structures */
@@ -63,6 +69,7 @@
/*! \brief This is just so iax_frames, a list head struct for holding a list of
* iax_frame structures, is defined. */
AST_LIST_HEAD_NOLOCK(iax_frames, iax_frame);
+#endif
static void internaloutput(const char *str)
{
@@ -605,6 +612,8 @@
void iax_set_error(void (*func)(const char *))
{
+ iax_frame_new_profile = ast_add_profile("iax_frame_new_profile", 0);
+ iax_frame_free_profile = ast_add_profile("iax_frame_free_profile", 0);
errorf = func;
}
@@ -941,9 +950,14 @@
struct iax_frame *iax_frame_new(int direction, int datalen)
{
+ struct iax_frame *fr = NULL;
+#ifdef ENABLE_FRAME_CACHING
struct iax_frames *iax_frames;
- struct iax_frame *fr = NULL;
-
+#endif
+
+ ast_mark(iax_frame_new_profile, 1);
+
+#ifdef ENABLE_FRAME_CACHING
/* Attempt to get a frame from this thread's cache */
if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
AST_LIST_TRAVERSE_SAFE_BEGIN(iax_frames, fr, list) {
@@ -960,12 +974,19 @@
}
if (!fr) {
- if (!(fr = ast_calloc(1, sizeof(*fr) + datalen)))
+#endif
+ if (!(fr = ast_calloc(1, sizeof(*fr) + datalen))) {
+ ast_mark(iax_frame_new_profile, 0);
return NULL;
+ }
ast_atomic_fetchadd_int((int *) &frames_allocated, 1);
fr->mallocd_datalen = datalen;
- }
-
+#ifdef ENABLE_FRAME_CACHING
+ }
+#endif
+
+ ast_mark(iax_frame_new_profile, 0);
+
fr->direction = direction;
fr->retrans = -1;
@@ -980,7 +1001,9 @@
static void __iax_frame_free(struct iax_frame *fr, int cache)
{
+#ifdef ENABLE_FRAME_CACHING
struct iax_frames *iax_frames;
+#endif
/* Note: does not remove from scheduler! */
if (fr->direction == DIRECTION_INGRESS)
@@ -993,23 +1016,32 @@
}
fr->direction = 0;
ast_atomic_fetchadd_int(&frames, -1);
-
+ if (cache)
+ ast_mark(iax_frame_free_profile, 1);
+#ifdef ENABLE_FRAME_CACHING
if (!cache) {
+#endif
free(fr);
ast_atomic_fetchadd_int((int *) &frames_freed, 1);
+ ast_mark(iax_frame_free_profile, 0);
return;
+#ifdef ENABLE_FRAME_CACHING
}
if (!(iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
free(fr);
+ ast_mark(iax_frame_free_profile, 0);
ast_atomic_fetchadd_int((int *) &frames_freed, 1);
return;
}
AST_LIST_INSERT_HEAD(iax_frames, fr, list);
+ ast_mark(iax_frame_free_profile, 0);
ast_atomic_fetchadd_int((int *) &added_to_cache, 1);
-}
-
+#endif
+}
+
+#ifdef ENABLE_FRAME_CACHING
static void frame_cache_cleanup(void *data)
{
struct iax_frames *frames = data;
@@ -1022,6 +1054,7 @@
free(frames);
}
+#endif
void iax_frame_free(struct iax_frame *fr)
{
More information about the asterisk-commits
mailing list