return rv;
}
+APR_DECLARE(int) apr_pool_walk_tree_debug(apr_pool_t *pool,
+ int(*fn)(apr_pool_t *pool, void *data),
+ void *data)
+{
+ return apr_pool_walk_tree(pool, fn, data);
+}
+
+APR_DECLARE(void) apr_pool_get_stats(apr_pool_t *pool, unsigned int *alloc, unsigned int *total_alloc, unsigned int *clear)
+{
+ if (pool) {
+ *alloc = pool->stat_alloc;
+ *total_alloc = pool->stat_total_alloc;
+ *clear = pool->stat_clear;
+ }
+}
+
#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL)
static void apr_pool_log_event(apr_pool_t *pool, const char *event,
const char *file_line, int deref)
for (index = 0; index < node->index; index++) {
memset(node->beginp[index], POOL_POISON_BYTE,
- node->endp[index] - node->beginp[index]);
+ (char *)node->endp[index] - (char *)node->beginp[index]);
free(node->beginp[index]);
}
return SWITCH_STATUS_SUCCESS;
}
+SWITCH_STANDARD_API(pool_stats_function)
+{
+ switch_core_pool_stats(stream);
+ return SWITCH_STATUS_SUCCESS;
+}
+
SWITCH_STANDARD_API(db_cache_function)
{
int argc;
SWITCH_ADD_API(commands_api_interface, "nat_map", "Manage NAT", nat_map_function, "[status|republish|reinit] | [add|del] <port> [tcp|udp] [static]");
SWITCH_ADD_API(commands_api_interface, "originate", "Originate a call", originate_function, ORIGINATE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "pause", "Pause media on a channel", pause_function, PAUSE_SYNTAX);
+ SWITCH_ADD_API(commands_api_interface, "pool_stats", "Core pool memory usage", pool_stats_function, "Core pool memory usage.");
SWITCH_ADD_API(commands_api_interface, "quote_shell_arg", "Quote/escape a string for use on shell command line", quote_shell_arg_function, "<data>");
SWITCH_ADD_API(commands_api_interface, "regex", "Evaluate a regex", regex_function, "<data>|<pattern>[|<subst string>][n|b]");
SWITCH_ADD_API(commands_api_interface, "reloadacl", "Reload XML", reload_acl_function, "");
(void *) session->pool, (void *) session, apr_pool_tag(session->pool, NULL), (int) memory);
#endif
+#if APR_POOL_DEBUG
+ ptr = apr_palloc_debug(session->pool, memory, func);
+#else
ptr = apr_palloc(session->pool, memory);
+#endif
switch_assert(ptr != NULL);
memset(ptr, 0, memory);
}
+#if APR_POOL_DEBUG
+static int switch_core_pool_stats_callback(apr_pool_t *pool, void *data) {
+ switch_stream_handle_t *stream = (switch_stream_handle_t *)data;
+ unsigned int size = (unsigned int)apr_pool_num_bytes(pool, 1);
+ unsigned int alloc = 0, total_alloc = 0, clear = 0;
+ char *line = NULL;
+
+ apr_pool_userdata_get((void**)&line, "line", pool);
+ apr_pool_get_stats(pool, &alloc, &total_alloc, &clear);
+ if (stream) {
+ stream->write_function(stream, "Pool '%s' size: %d, alloc:%d, total_alloc:%d, clear:%d\n", (line ? line : apr_pool_tag(pool, NULL)), (int)size, alloc, total_alloc, clear);
+ } else {
+ printf("Pool '%s' size: %d, alloc:%d, total_alloc:%d, clear:%d\n", (line ? line : apr_pool_tag(pool, NULL)), (int)size, alloc, total_alloc, clear);
+ }
+ return 0;
+}
+#endif
+
+SWITCH_DECLARE(void) switch_core_pool_stats(switch_stream_handle_t *stream)
+{
+#if APR_POOL_DEBUG
+ if (runtime.memory_pool) {
+ apr_pool_walk_tree_debug(runtime.memory_pool, switch_core_pool_stats_callback, (void *)stream);
+ }
+#else
+ if (stream) {
+ stream->write_function(stream, "Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
+ } else {
+ printf("Unable to get core pool statictics. Please rebuild FreeSWITCH with --enable-pool-debug");
+ }
+#endif
+}
SWITCH_DECLARE(switch_status_t) switch_core_perform_new_memory_pool(switch_memory_pool_t **pool, const char *file, const char *func, int line)
{
abort();
}
+#if APR_POOL_DEBUG
+ if ((apr_pool_create_ex_debug(pool, memory_manager.memory_pool, NULL, my_allocator, func)) != APR_SUCCESS) {
+#else
if ((apr_pool_create_ex(pool, NULL, NULL, my_allocator)) != APR_SUCCESS) {
+#endif
abort();
}
tmp = switch_core_sprintf(*pool, "%s:%d", file, line);
apr_pool_tag(*pool, tmp);
+#if APR_POOL_DEBUG
+ apr_pool_userdata_set(tmp, "line", NULL, *pool);
+#endif
+
#ifdef DEBUG_ALLOC2
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_CONSOLE, "%p New Pool %s\n", (void *) *pool, apr_pool_tag(*pool, NULL));
#endif
#ifdef USE_MEM_LOCK
switch_mutex_lock(memory_manager.mem_lock);
#endif
+#if APR_POOL_DEBUG
+ apr_pool_destroy_debug(*pool, func);
+#else
apr_pool_destroy(*pool);
+#endif
#ifdef USE_MEM_LOCK
switch_mutex_unlock(memory_manager.mem_lock);
#endif
/*switch_assert(memory < 20000); */
#endif
+#if APR_POOL_DEBUG
+ ptr = apr_palloc_debug(pool, memory, func);
+#else
ptr = apr_palloc(pool, memory);
+#endif
switch_assert(ptr != NULL);
memset(ptr, 0, memory);