leak-detective: Use callback functions to report leaks and usage information

This is more flexible than printing reports to a FILE.
This commit is contained in:
Martin Willi
2013-11-06 10:30:59 +01:00
parent 9ae1140118
commit a426851f63
5 changed files with 158 additions and 47 deletions
+22 -1
View File
@@ -489,6 +489,25 @@ static void stroke_leases(private_stroke_socket_t *this,
this->list->leases(this->list, msg, out);
}
/**
* Callback function for usage report
*/
static void report_usage(FILE *out, int count, size_t bytes,
backtrace_t *bt, bool detailed)
{
fprintf(out, "%d bytes total, %d allocations, %d bytes average:\n",
bytes, count, bytes / count);
bt->log(bt, out, detailed);
}
/**
* Callback function for memusage summary
*/
static void sum_usage(FILE *out, int count, size_t bytes, int whitelisted)
{
fprintf(out, "Total memory usage: %zu\n", bytes);
}
/**
* Show memory usage
*/
@@ -497,7 +516,9 @@ static void stroke_memusage(private_stroke_socket_t *this,
{
if (lib->leak_detective)
{
lib->leak_detective->usage(lib->leak_detective, out);
lib->leak_detective->usage(lib->leak_detective,
(leak_detective_report_cb_t)report_usage,
(leak_detective_summary_cb_t)sum_usage, out);
}
}