[svn-commits] russell: branch russell/frame_caching r41148 - in
/team/russell/frame_caching...
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Fri Aug 25 13:33:57 MST 2006
Author: russell
Date: Fri Aug 25 15:33:57 2006
New Revision: 41148
URL: http://svn.digium.com/view/asterisk?rev=41148&view=rev
Log:
- fix a potentially unitialized variable
- enable the ability to profile the caching of ast_frame structures, with
caching turned on or off
Modified:
team/russell/frame_caching/channels/iax2-parser.c
team/russell/frame_caching/main/frame.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=41148&r1=41147&r2=41148&view=diff
==============================================================================
--- team/russell/frame_caching/channels/iax2-parser.c (original)
+++ team/russell/frame_caching/channels/iax2-parser.c Fri Aug 25 15:33:57 2006
@@ -942,7 +942,7 @@
struct iax_frame *iax_frame_new(int direction, int datalen)
{
struct iax_frames *iax_frames;
- struct iax_frame *fr;
+ struct iax_frame *fr = NULL;
/* Attempt to get a frame from this thread's cache */
if ((iax_frames = ast_threadstorage_get(&frame_cache, sizeof(*iax_frames)))) {
Modified: team/russell/frame_caching/main/frame.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/main/frame.c?rev=41148&r1=41147&r2=41148&view=diff
==============================================================================
--- team/russell/frame_caching/main/frame.c (original)
+++ team/russell/frame_caching/main/frame.c Fri Aug 25 15:33:57 2006
@@ -63,6 +63,13 @@
static unsigned int headers_allocated = 0;
static unsigned int headers_freed = 0;
+static int frame_alloc_profile = -1;
+static int frame_free_profile = -1;
+static int frame_dup_profile = -1;
+
+#define ENABLE_FRAME_CACHING
+
+#ifdef ENABLE_FRAME_CACHING
static void frame_cache_cleanup(void *data);
/*! \brief A per-thread cache of frame headers */
@@ -87,6 +94,7 @@
struct ast_frames list;
size_t size;
};
+#endif
#define SMOOTHER_SIZE 8000
@@ -293,8 +301,12 @@
static struct ast_frame *ast_frame_header_new(void)
{
struct ast_frame *f;
+#ifdef ENABLE_FRAME_CACHING
struct ast_frame_cache *frames;
-
+#endif
+
+ ast_mark(frame_alloc_profile, 1);
+#ifdef ENABLE_FRAME_CACHING
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
if ((f = AST_LIST_REMOVE_HEAD(&frames->list, frame_list))) {
size_t mallocd_len = f->mallocd_hdr_len;
@@ -302,15 +314,17 @@
f->mallocd_hdr_len = mallocd_len;
f->mallocd = AST_MALLOCD_HDR;
frames->size--;
+ ast_mark(frame_alloc_profile, 0);
ast_atomic_fetchadd_int((int *) &removed_from_cache, 1);
return f;
}
}
-
- if (!(f = ast_calloc(1, sizeof(*f))))
+#endif
+
+ if (!(f = ast_calloc(1, sizeof(*f)))) {
+ ast_mark(frame_alloc_profile, 0);
return NULL;
-
- ast_atomic_fetchadd_int((int *) &headers_allocated, 1);
+ }
f->mallocd_hdr_len = sizeof(*f);
#ifdef TRACE_FRAMES
@@ -320,9 +334,12 @@
AST_LIST_UNLOCK(&headerlist);
#endif
+ ast_mark(frame_alloc_profile, 0);
+ ast_atomic_fetchadd_int((int *) &headers_allocated, 1);
return f;
}
+#ifdef ENABLE_FRAME_CACHING
static void frame_cache_cleanup(void *data)
{
struct ast_frame_cache *frames = data;
@@ -335,6 +352,7 @@
free(frames);
}
+#endif
void ast_frfree(struct ast_frame *fr)
{
@@ -367,6 +385,11 @@
ast_log(LOG_ERROR, "Totally bogus frame malloc'd value of '%d'!\n", fr->mallocd);
}
+ if (!fr->mallocd)
+ return;
+
+ ast_mark(frame_free_profile, 1);
+#ifdef ENABLE_FRAME_CACHING
if (fr->mallocd == AST_MALLOCD_HDR) {
/* Cool, only the header is malloc'd, let's just cache those for now
* to keep things simple... */
@@ -376,11 +399,12 @@
&& frames->size < FRAME_CACHE_MAX_SIZE) {
AST_LIST_INSERT_HEAD(&frames->list, fr, frame_list);
frames->size++;
+ ast_mark(frame_free_profile, 0);
ast_atomic_fetchadd_int((int *) &added_to_cache, 1);
return;
}
}
-
+#endif
if (fr->mallocd & AST_MALLOCD_DATA) {
if (fr->data)
free(fr->data - fr->offset);
@@ -399,6 +423,8 @@
free(fr);
ast_atomic_fetchadd_int((int *) &headers_freed, 1);
}
+
+ ast_mark(frame_free_profile, 0);
}
/*!
@@ -464,10 +490,13 @@
struct ast_frame *ast_frdup(const struct ast_frame *f)
{
+#ifdef ENABLE_FRAME_CACHING
struct ast_frame_cache *frames;
+#endif
struct ast_frame *out;
int len, srclen = 0;
void *buf = NULL;
+
/* Start with standard stuff */
len = sizeof(*out) + AST_FRIENDLY_OFFSET + f->datalen;
/* If we have a source, add space for it */
@@ -479,7 +508,10 @@
srclen = strlen(f->src);
if (srclen > 0)
len += srclen + 1;
-
+
+ ast_mark(frame_dup_profile, 1);
+
+#ifdef ENABLE_FRAME_CACHING
if ((frames = ast_threadstorage_get(&frame_cache, sizeof(*frames)))) {
AST_LIST_TRAVERSE_SAFE_BEGIN(&frames->list, out, frame_list) {
if (out->mallocd_hdr_len >= len) {
@@ -495,14 +527,19 @@
}
AST_LIST_TRAVERSE_SAFE_END
}
-
if (!buf) {
- if (!(buf = ast_calloc(1, len)))
+#endif
+ if (!(buf = ast_calloc(1, len))) {
+ ast_mark(frame_dup_profile, 0);
return NULL;
+ }
ast_atomic_fetchadd_int((int *) &headers_allocated, 1);
out = buf;
out->mallocd_hdr_len = len;
- }
+#ifdef ENABLE_FRAME_CACHING
+ }
+#endif
+ ast_mark(frame_dup_profile, 0);
out->frametype = f->frametype;
out->subclass = f->subclass;
@@ -1049,9 +1086,13 @@
{ { "show", "framecache", "stats", NULL }, show_framecache_stats, "Show ast_framecache stats", framecache_stats_usage },
};
+
int init_framer(void)
{
ast_cli_register_multiple(my_clis, sizeof(my_clis)/sizeof(my_clis[0]) );
+ frame_alloc_profile = ast_add_profile("frame_alloc_profile", 0);
+ frame_free_profile = ast_add_profile("frame_free_profile", 0);
+ frame_dup_profile = ast_add_profile("frame_dup_profile", 0);
return 0;
}
More information about the svn-commits
mailing list