striker 02/01/12 18:12:25
Modified: include apr_pools.h
memory/unix apr_pools.c
misc/unix start.c
Log:
Another update of the pools debug code.
Stats are added. Unlike the old situation, stats are always
on in APR_POOL_DEBUG mode, no need to seperately activate them.
Debug output formatting is improved (IMHO). I actually got the
concept from subversion for this. We now show (in _VERBOSE
mode):
- action (CREATE, CLEAR, DESTROY)
- memory in the current pool
- memory in the current pool and its children
- total used memory
- address of the pool
- pools tag
- file and line number the action takes place
- stats for the pool
- allocs since last clear
- total allocs
- clears (number of times apr_pool_clear is called on the pool).
Moved the declaration of apr_pool_clear up so it sits in the
same group it sits in in the .c file.
Renamed the apr_pool_xxx_dbg functions to apr_pool_xxx_debug. It
wasn't really worth shortening the names in the first place. The
user will (in general) never call apr_pool_xxx_debug directly.
Removed some stale @deffunc lines. Doxygen doesn't need them
anyway.
Tag the pool created in apr_initialize().
Revision Changes Path
1.69 +36 -34 apr/include/apr_pools.h
Index: apr_pools.h
===================================================================
RCS file: /home/cvs/apr/include/apr_pools.h,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- apr_pools.h 12 Jan 2002 16:15:07 -0000 1.68
+++ apr_pools.h 13 Jan 2002 02:12:24 -0000 1.69
@@ -160,21 +160,22 @@
*/
#if defined(APR_POOL_DEBUG)
#define apr_pool_create_ex(newpool, parent, abort_fn, flag) \
- apr_pool_create_ex_dbg(newpool, parent, abort_fn, flag, __FILE__,
__LINE__)
+ apr_pool_create_ex_debug(newpool, parent, abort_fn, flag, \
+ __FILE__, __LINE__)
-APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
- apr_pool_t *parent,
- apr_abortfunc_t abort_fn,
- apr_uint32_t flags,
- const char *file,
- int line);
-#
+APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_uint32_t flags,
+ const char *file,
+ int line);
#else
APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool,
apr_pool_t *parent,
apr_abortfunc_t abort_fn,
apr_uint32_t flags);
#endif
+
/**
* Create a new pool.
* @param newpool The pool we have just created.
@@ -189,8 +190,8 @@
#else
#if defined(APR_POOL_DEBUG)
#define apr_pool_create(newpool, parent) \
- apr_pool_create_ex_dbg(newpool, parent, NULL, APR_POOL_FDEFAULT, \
- __FILE__, __LINE__)
+ apr_pool_create_ex_debug(newpool, parent, NULL, APR_POOL_FDEFAULT, \
+ __FILE__, __LINE__)
#else
#define apr_pool_create(newpool, parent) \
apr_pool_create_ex(newpool, parent, NULL, APR_POOL_FDEFAULT)
@@ -202,7 +203,6 @@
* @param newpool The new sub-pool
* @param parent The pool to use as a parent pool
* @param apr_abort A function to use if the pool cannot allocate more
memory.
- * @deffunc void apr_pool_sub_make(apr_pool_t **p, apr_pool_t *parent, int
(*apr_abort)(int retcode), const char *created)
* @remark The @a apr_abort function provides a way to quit the program if
the
* machine is out of memory. By default, APR will return on error.
*/
@@ -213,8 +213,9 @@
#else
#if defined(APR_POOL_DEBUG)
#define apr_pool_sub_make(newpool, parent, abort_fn) \
- (void)apr_pool_create_ex_dbg(newpool, parent, abort_fn,
APR_POOL_FDEFAULT, \
- __FILE__, __LINE__)
+ (void)apr_pool_create_ex_debug(newpool, parent, abort_fn, \
+ APR_POOL_FDEFAULT, \
+ __FILE__, __LINE__)
#else
#define apr_pool_sub_make(newpool, parent, abort_fn) \
(void)apr_pool_create_ex(newpool, parent, abort_fn, APR_POOL_FDEFAULT)
@@ -222,6 +223,24 @@
#endif
/**
+ * Clear all memory in the pool and run all the cleanups. This also destroys
all
+ * subpools.
+ * @param p The pool to clear
+ * @remark This does not actually free the memory, it just allows the pool
+ * to re-use this memory for the next allocation.
+ * @see apr_pool_destroy()
+ */
+#if defined(APR_POOL_DEBUG)
+#define apr_pool_clear(p) \
+ apr_pool_clear_debug(p, __FILE__, __LINE__)
+
+APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *p,
+ const char *file, int line);
+#else
+APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
+#endif
+
+/**
* Destroy the pool. This takes similar action as apr_pool_clear() and then
* frees all the memory.
* @param p The pool to destroy
@@ -229,13 +248,15 @@
*/
#if defined(APR_POOL_DEBUG)
#define apr_pool_destroy(p) \
- apr_pool_destroy_dbg(p, __FILE__, __LINE__)
+ apr_pool_destroy_debug(p, __FILE__, __LINE__)
-APR_DECLARE(void) apr_pool_destroy_dbg(apr_pool_t *p, const char *file, int
line);
+APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *p,
+ const char *file, int line);
#else
APR_DECLARE(void) apr_pool_destroy(apr_pool_t *p);
#endif
+
/*
* Memory allocation
*/
@@ -256,22 +277,6 @@
*/
APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size);
-/**
- * Clear all memory in the pool and run all the cleanups. This also clears
all
- * subpools.
- * @param p The pool to clear
- * @remark This does not actually free the memory, it just allows the pool
- * to re-use this memory for the next allocation.
- * @see apr_pool_destroy()
- */
-#if defined(APR_POOL_DEBUG)
-#define apr_pool_clear(p) \
- apr_pool_clear_dbg(p, __FILE__, __LINE__)
-
-APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *p, const char *file, int
line);
-#else
-APR_DECLARE(void) apr_pool_clear(apr_pool_t *p);
-#endif
/*
* Pool Properties
@@ -284,7 +289,6 @@
* performing cleanup and then exiting). If this function is not called,
* then APR will return an error and expect the calling program to
* deal with the error accordingly.
- * @deffunc apr_status_t apr_pool_set_abort(apr_abortfunc_t abortfunc,
apr_pool_t *pool)
*/
APR_DECLARE(void) apr_pool_set_abort(apr_abortfunc_t abortfunc,
apr_pool_t *pool);
@@ -293,7 +297,6 @@
* Get the abort function associated with the specified pool.
* @param pool The pool for retrieving the abort function.
* @return The abort function for the given pool.
- * @deffunc apr_abortfunc_t apr_pool_get_abort(apr_pool_t *pool)
*/
APR_DECLARE(apr_abortfunc_t) apr_pool_get_abort(apr_pool_t *pool);
@@ -301,7 +304,6 @@
* Get the parent pool of the specified pool.
* @param pool The pool for retrieving the parent pool.
* @return The parent of the given pool.
- * @deffunc apr_pool_t * apr_pool_get_parent(apr_pool_t *pool)
*/
APR_DECLARE(apr_pool_t *) apr_pool_get_parent(apr_pool_t *pool);
1.130 +60 -28 apr/memory/unix/apr_pools.c
Index: apr_pools.c
===================================================================
RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -r1.129 -r1.130
--- apr_pools.c 12 Jan 2002 16:15:07 -0000 1.129
+++ apr_pools.c 13 Jan 2002 02:12:24 -0000 1.130
@@ -163,6 +163,9 @@
debug_node_t *nodes;
const char *file;
int line;
+ unsigned int stat_alloc;
+ unsigned int stat_total_alloc;
+ unsigned int stat_clear;
#if APR_HAS_THREADS
apr_thread_mutex_t *mutex;
#endif
@@ -833,6 +836,11 @@
if (apr_pools_initialized++)
return APR_SUCCESS;
+ /* Since the debug code works a bit differently then the
+ * regular pools code, we ask for a lock here. The regular
+ * pools code has got this lock embedded in the global
+ * allocator, a concept unknown to debug mode.
+ */
if ((rv = apr_pool_create_ex(&global_pool, NULL, NULL,
APR_POOL_FNEW_ALLOCATOR|APR_POOL_FLOCK)) != APR_SUCCESS) {
return rv;
@@ -846,7 +854,12 @@
apr_file_open_stderr(&file_stderr, global_pool);
if (file_stderr) {
apr_file_printf(file_stderr,
- "POOL DEBUG: GLOBAL 0x%08X(%s)\n",
+ "POOL DEBUG: ACTION [SIZE /POOL SIZE /TOTAL SIZE] "
+ "POOL TAG [__FILE__:__LINE__] (ALLOCS/TOTAL
ALLOCS/CLEARS)\n");
+
+ apr_file_printf(file_stderr,
+ "POOL DEBUG: GLOBAL "
+ "0x%08X \"%s\"\n",
(unsigned int)global_pool, global_pool->tag);
}
#endif
@@ -905,7 +918,9 @@
#if defined(APR_POOL_DEBUG_VERBOSE)
if (file_stderr) {
apr_file_printf(file_stderr,
- "POOL DEBUG: INVALID 0x%08X, abort().\n", (unsigned
int)pool);
+ "POOL DEBUG: INVALID "
+ "0x%08X, abort().\n",
+ (unsigned int)pool);
}
#endif
@@ -949,6 +964,9 @@
node->endp[node->index] = (char *)mem + size;
node->index++;
+ pool->stat_alloc++;
+ pool->stat_total_alloc++;
+
return mem;
}
@@ -969,7 +987,7 @@
* Pool creation/destruction (debug)
*/
-static void pool_clear_dbg(apr_pool_t *pool, const char *file, int line)
+static void pool_clear_debug(apr_pool_t *pool, const char *file, int line)
{
debug_node_t *node;
apr_uint32_t index;
@@ -978,7 +996,7 @@
* this pool thus this loop is safe and easy.
*/
while (pool->child)
- apr_pool_destroy_dbg(pool->child, file, line);
+ apr_pool_destroy_debug(pool->child, file, line);
/* Run cleanups */
run_cleanups(pool->cleanups);
@@ -1000,40 +1018,51 @@
free(node);
}
+
+ pool->stat_alloc = 0;
+ pool->stat_clear++;
}
-APR_DECLARE(void) apr_pool_clear_dbg(apr_pool_t *pool,
- const char *file, int line)
+APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *pool,
+ const char *file, int line)
{
check_integrity(pool);
#if defined(APR_POOL_DEBUG_VERBOSE)
if (file_stderr) {
apr_file_printf(file_stderr,
- "POOL DEBUG: CLEAR 0x%08X(%s) [%s:%d]\n",
+ "POOL DEBUG: CLEAR [%10lu/%10lu/%10lu] 0x%08X \"%s\" [%s:%d]
(%u/%u/%u)\n",
+ (unsigned long)apr_pool_num_bytes(pool, 0),
+ (unsigned long)apr_pool_num_bytes(pool, 1),
+ (unsigned long)apr_pool_num_bytes(global_pool, 1),
(unsigned int)pool, pool->tag,
- file, line);
+ file, line,
+ pool->stat_alloc, pool->stat_total_alloc, pool->stat_clear);
}
#endif
- pool_clear_dbg(pool, file, line);
+ pool_clear_debug(pool, file, line);
}
-APR_DECLARE(void) apr_pool_destroy_dbg(apr_pool_t *pool,
- const char *file, int line)
+APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool,
+ const char *file, int line)
{
check_integrity(pool);
#if defined(APR_POOL_DEBUG_VERBOSE)
if (file_stderr) {
apr_file_printf(file_stderr,
- "POOL DEBUG: DESTROY 0x%08X(%s) [%s:%u]\n",
+ "POOL DEBUG: DESTROY [%10lu/%10lu/%10lu] 0x%08X \"%s\" [%s:%d]
(%u/%u/%u)\n",
+ (unsigned long)apr_pool_num_bytes(pool, 0),
+ (unsigned long)apr_pool_num_bytes(pool, 1),
+ (unsigned long)apr_pool_num_bytes(global_pool, 1),
(unsigned int)pool, pool->tag,
- file, line);
+ file, line,
+ pool->stat_alloc, pool->stat_total_alloc, pool->stat_clear);
}
#endif
- pool_clear_dbg(pool, file, line);
+ pool_clear_debug(pool, file, line);
/* Remove the pool from the parents child list */
if (pool->parent) {
@@ -1057,12 +1086,12 @@
free(pool);
}
-APR_DECLARE(apr_status_t) apr_pool_create_ex_dbg(apr_pool_t **newpool,
- apr_pool_t *parent,
- apr_abortfunc_t abort_fn,
- apr_uint32_t flags,
- const char *file,
- int line)
+APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool,
+ apr_pool_t *parent,
+ apr_abortfunc_t abort_fn,
+ apr_uint32_t flags,
+ const char *file,
+ int line)
{
apr_pool_t *pool;
@@ -1136,10 +1165,13 @@
#if defined(APR_POOL_DEBUG_VERBOSE)
if (file_stderr) {
apr_file_printf(file_stderr,
- "POOL DEBUG: CREATE 0x%08X(%s) parent = 0x%08X(%s) [%s:%u]\n",
+ "POOL DEBUG: CREATE [%10lu/%10lu/%10lu] 0x%08X \"%s\" [%s:%u]
parent: 0x%08X \"%s\"\n",
+ (unsigned long)0,
+ (unsigned long)0,
+ (unsigned long)apr_pool_num_bytes(global_pool, 1),
(unsigned int)pool, pool->tag,
- (unsigned int)parent, parent ? parent->tag : "<null>",
- file, line);
+ file, line,
+ (unsigned int)parent, parent ? parent->tag : "<null>");
}
#endif
@@ -1158,7 +1190,7 @@
APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool)
{
- apr_pool_clear_dbg(pool, "<undefined>", 0);
+ apr_pool_clear_debug(pool, "<undefined>", 0);
}
#undef apr_pool_destroy
@@ -1166,7 +1198,7 @@
APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool)
{
- apr_pool_destroy_dbg(pool, "<undefined>", 0);
+ apr_pool_destroy_debug(pool, "<undefined>", 0);
}
#undef apr_pool_create_ex
@@ -1180,9 +1212,9 @@
apr_abortfunc_t abort_fn,
apr_uint32_t flags)
{
- return apr_pool_create_ex_dbg(newpool, parent,
- abort_fn, flags,
- "<undefined>", 0);
+ return apr_pool_create_ex_debug(newpool, parent,
+ abort_fn, flags,
+ "<undefined>", 0);
}
1.59 +2 -0 apr/misc/unix/start.c
Index: start.c
===================================================================
RCS file: /home/cvs/apr/misc/unix/start.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- start.c 14 Dec 2001 02:16:55 -0000 1.58
+++ start.c 13 Jan 2002 02:12:25 -0000 1.59
@@ -99,6 +99,8 @@
return APR_ENOPOOL;
}
+ apr_pool_tag(pool, "apr_initilialize");
+
#ifdef WIN32
/* Initialize apr_os_level global */
if (apr_get_oslevel(pool, &osver) != APR_SUCCESS) {