Improve reporting from sf_report_leaked_memory()
Other things: - Added DBUG_EXECUTE_IF("print_allocated_thread_memory") at end of query to easier find not freed memory allocated by THD - Removed free_root() from plugin_init() that did nothing.
This commit is contained in:
parent
06f7ed4dcd
commit
83214c3406
@ -66,7 +66,7 @@ struct st_irem
|
|||||||
uint32 marker; /* Underrun marker value */
|
uint32 marker; /* Underrun marker value */
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sf_malloc_count= 0; /* Number of allocated chunks */
|
static uint sf_malloc_count= 0; /* Number of allocated chunks */
|
||||||
|
|
||||||
static void *sf_min_adress= (void*) (intptr)~0ULL,
|
static void *sf_min_adress= (void*) (intptr)~0ULL,
|
||||||
*sf_max_adress= 0;
|
*sf_max_adress= 0;
|
||||||
@ -344,7 +344,7 @@ int sf_sanity()
|
|||||||
{
|
{
|
||||||
struct st_irem *irem;
|
struct st_irem *irem;
|
||||||
int flag= 0;
|
int flag= 0;
|
||||||
int count= 0;
|
uint count= 0;
|
||||||
|
|
||||||
pthread_mutex_lock(&sf_mutex);
|
pthread_mutex_lock(&sf_mutex);
|
||||||
count= sf_malloc_count;
|
count= sf_malloc_count;
|
||||||
@ -369,6 +369,7 @@ void sf_report_leaked_memory(my_thread_id id)
|
|||||||
{
|
{
|
||||||
size_t total= 0;
|
size_t total= 0;
|
||||||
struct st_irem *irem;
|
struct st_irem *irem;
|
||||||
|
uint first= 0, chunks= 0;
|
||||||
|
|
||||||
sf_sanity();
|
sf_sanity();
|
||||||
|
|
||||||
@ -380,15 +381,18 @@ void sf_report_leaked_memory(my_thread_id id)
|
|||||||
{
|
{
|
||||||
my_thread_id tid = irem->thread_id && irem->flags & MY_THREAD_SPECIFIC ?
|
my_thread_id tid = irem->thread_id && irem->flags & MY_THREAD_SPECIFIC ?
|
||||||
irem->thread_id : 0;
|
irem->thread_id : 0;
|
||||||
|
if (!first++)
|
||||||
|
fprintf(stderr, "Memory report from safemalloc\n");
|
||||||
fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%llu at ",
|
fprintf(stderr, "Warning: %4lu bytes lost at %p, allocated by T@%llu at ",
|
||||||
(ulong) irem->datasize, (char*) (irem + 1), tid);
|
(ulong) irem->datasize, (char*) (irem + 1), tid);
|
||||||
print_stack(irem->frame);
|
print_stack(irem->frame);
|
||||||
total+= irem->datasize;
|
total+= irem->datasize;
|
||||||
|
chunks++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (total)
|
if (total)
|
||||||
fprintf(stderr, "Memory lost: %lu bytes in %d chunks\n",
|
fprintf(stderr, "Memory lost: %lu bytes in %u chunks of %u total chunks\n",
|
||||||
(ulong) total, sf_malloc_count);
|
(ulong) total, chunks, sf_malloc_count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2480,6 +2480,8 @@ dispatch_end:
|
|||||||
*/
|
*/
|
||||||
thd->lex->m_sql_cmd= NULL;
|
thd->lex->m_sql_cmd= NULL;
|
||||||
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
|
||||||
|
DBUG_EXECUTE_IF("print_allocated_thread_memory",
|
||||||
|
SAFEMALLOC_REPORT_MEMORY(sf_malloc_dbug_id()););
|
||||||
|
|
||||||
#if defined(ENABLED_PROFILING)
|
#if defined(ENABLED_PROFILING)
|
||||||
thd->profiling.finish_current_query();
|
thd->profiling.finish_current_query();
|
||||||
|
@ -1646,7 +1646,6 @@ int plugin_init(int *argc, char **argv, int flags)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE));
|
|
||||||
tmp.state= PLUGIN_IS_UNINITIALIZED;
|
tmp.state= PLUGIN_IS_UNINITIALIZED;
|
||||||
if (register_builtin(plugin, &tmp, &plugin_ptr))
|
if (register_builtin(plugin, &tmp, &plugin_ptr))
|
||||||
goto err_unlock;
|
goto err_unlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user