[asterisk-commits] russell: trunk r82338 - in /trunk: ./ include/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Sep 13 13:52:36 CDT 2007


Author: russell
Date: Thu Sep 13 13:52:35 2007
New Revision: 82338

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82338
Log:
Merged revisions 82337 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r82337 | russell | 2007-09-13 13:45:59 -0500 (Thu, 13 Sep 2007) | 4 lines

Only compile in tracking astobj2 statistics if dev-mode is enabled.  Also, when
dev mode is enabled, register the CLI command that can be used to run the astobj2
test and print out statistics.

........

Modified:
    trunk/   (props changed)
    trunk/include/asterisk.h
    trunk/main/asterisk.c
    trunk/main/astobj2.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk.h?view=diff&rev=82338&r1=82337&r2=82338
==============================================================================
--- trunk/include/asterisk.h (original)
+++ trunk/include/asterisk.h Thu Sep 13 13:52:35 2007
@@ -88,6 +88,7 @@
 void threadstorage_init(void);			/*!< Provided by threadstorage.c */
 void ast_event_init(void);          /*!< Provided by event.c */
 int ast_device_state_engine_init(void); /*!< Provided by devicestate.c */
+int astobj2_init(void);				/*! Provided by astobj2.c */
 
 /* Many headers need 'ast_channel' to be defined */
 struct ast_channel;

Modified: trunk/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/main/asterisk.c?view=diff&rev=82338&r1=82337&r2=82338
==============================================================================
--- trunk/main/asterisk.c (original)
+++ trunk/main/asterisk.c Thu Sep 13 13:52:35 2007
@@ -2869,6 +2869,8 @@
 
 	threadstorage_init();
 
+	astobj2_init();
+
 	if (load_modules(1)) {		/* Load modules, pre-load only */
 		printf(term_quit());
 		exit(1);

Modified: trunk/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/trunk/main/astobj2.c?view=diff&rev=82338&r1=82337&r2=82338
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Thu Sep 13 13:52:35 2007
@@ -57,6 +57,11 @@
 	void *user_data[0];
 };
 
+#ifdef AST_DEVMODE
+#define AO2_DEBUG 1
+#endif
+
+#ifdef AO2_DEBUG
 struct ao2_stats {
 	volatile int total_objects;
 	volatile int total_mem;
@@ -66,6 +71,7 @@
 };
 
 static struct ao2_stats ao2;
+#endif
 
 #ifndef HAVE_BKTR	/* backtrace support */
 void ao2_bt(void) {}
@@ -126,7 +132,9 @@
 	if (p == NULL)
 		return -1;
 
+#ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_locked, 1);
+#endif
 
 	return ast_mutex_lock(&p->priv_data.lock);
 }
@@ -138,7 +146,9 @@
 	if (p == NULL)
 		return -1;
 
+#ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_locked, -1);
+#endif
 
 	return ast_mutex_unlock(&p->priv_data.lock);
 }
@@ -161,9 +171,12 @@
 
 	/* we modify with an atomic operation the reference counter */
 	ret = ast_atomic_fetchadd_int(&obj->priv_data.ref_counter, delta);
+	current_value = ret + delta;
+
+#ifdef AO2_DEBUG	
 	ast_atomic_fetchadd_int(&ao2.total_refs, delta);
-	current_value = ret + delta;
-	
+#endif
+
 	/* this case must never happen */
 	if (current_value < 0)
 		ast_log(LOG_ERROR, "refcount %d on object %p\n", current_value, user_data);
@@ -173,13 +186,15 @@
 			obj->priv_data.destructor_fn(user_data);
 
 		ast_mutex_destroy(&obj->priv_data.lock);
+#ifdef AO2_DEBUG
 		ast_atomic_fetchadd_int(&ao2.total_mem, - obj->priv_data.data_size);
+		ast_atomic_fetchadd_int(&ao2.total_objects, -1);
+#endif
 		/* for safety, zero-out the astobj2 header and also the
 		 * first word of the user-data, which we make sure is always
 		 * allocated. */
 		bzero(obj, sizeof(struct astobj2 *) + sizeof(void *) );
 		free(obj);
-		ast_atomic_fetchadd_int(&ao2.total_objects, -1);
 	}
 
 	return ret;
@@ -207,9 +222,12 @@
 	obj->priv_data.data_size = data_size;
 	obj->priv_data.ref_counter = 1;
 	obj->priv_data.destructor_fn = destructor_fn;	/* can be NULL */
+
+#ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_objects, 1);
 	ast_atomic_fetchadd_int(&ao2.total_mem, data_size);
 	ast_atomic_fetchadd_int(&ao2.total_refs, 1);
+#endif
 
 	/* return a pointer to the user data */
 	return EXTERNAL_OBJ(obj);
@@ -289,8 +307,11 @@
 	c->n_buckets = n_buckets;
 	c->hash_fn = hash_fn ? hash_fn : hash_zero;
 	c->cmp_fn = cmp_fn;
+
+#ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_containers, 1);
-	
+#endif
+
 	return c;
 }
 
@@ -567,7 +588,10 @@
 	struct ao2_container *c = _c;
 
 	ao2_callback(c, OBJ_UNLINK, cd_cb, NULL);
+
+#ifdef AO2_DEBUG
 	ast_atomic_fetchadd_int(&ao2.total_containers, -1);
+#endif
 }
 
 static int print_cb(void *obj, void *arg, int flag)
@@ -579,6 +603,7 @@
 	return 0;
 }
 
+#ifdef AO2_DEBUG
 /*
  * Print stats
  */
@@ -669,10 +694,13 @@
 	handle_astobj2_stats, "Print astobj2 statistics", },
 	{ { "astobj2", "test", NULL } , handle_astobj2_test, "Test astobj2", },
 };
-
-int astobj2_init(void);
+#endif /* AO2_DEBUG */
+
 int astobj2_init(void)
 {
+#ifdef AO2_DEBUG
 	ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
+#endif
+
 	return 0;
 }




More information about the asterisk-commits mailing list