aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins/stroke/stroke_socket.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-10-16 10:37:38 +0200
committerMartin Willi <martin@revosec.ch>2013-11-06 10:30:59 +0100
commita426851f6362f8d1d6cbecd133ef39a831b4ea2a (patch)
treed5ae0d9f3be281bcfa479f134cba53634d568d2c /src/libcharon/plugins/stroke/stroke_socket.c
parent9ae1140118837d981d7566e8dbdca3f0ebc3466b (diff)
downloadstrongswan-a426851f6362.tar.bz2
strongswan-a426851f6362.tar.xz
leak-detective: Use callback functions to report leaks and usage information
This is more flexible than printing reports to a FILE.
Diffstat (limited to 'src/libcharon/plugins/stroke/stroke_socket.c')
-rw-r--r--src/libcharon/plugins/stroke/stroke_socket.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/libcharon/plugins/stroke/stroke_socket.c b/src/libcharon/plugins/stroke/stroke_socket.c
index 3adebb523..cf7ec369c 100644
--- a/src/libcharon/plugins/stroke/stroke_socket.c
+++ b/src/libcharon/plugins/stroke/stroke_socket.c
@@ -490,6 +490,25 @@ static void stroke_leases(private_stroke_socket_t *this,
}
/**
+ * 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
*/
static void stroke_memusage(private_stroke_socket_t *this,
@@ -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);
}
}