diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-23 17:32:42 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-12-23 17:32:42 +0000 |
commit | b9bc147e382dde1d807d0ae5c7e536100d920bd0 (patch) | |
tree | 38cf4e038326cf56f025daac4668b37d5be955ed /src/libutil/mem_pool.c | |
parent | 3dc7b7581362bb008d65d0f4b165be4e065baefd (diff) | |
download | rspamd-b9bc147e382dde1d807d0ae5c7e536100d920bd0.tar.gz rspamd-b9bc147e382dde1d807d0ae5c7e536100d920bd0.zip |
[Project] Sort by memory usage
Diffstat (limited to 'src/libutil/mem_pool.c')
-rw-r--r-- | src/libutil/mem_pool.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c index 8ab328f55..5e4d1fe1a 100644 --- a/src/libutil/mem_pool.c +++ b/src/libutil/mem_pool.c @@ -725,6 +725,20 @@ rspamd_mempool_destructors_enforce (rspamd_mempool_t *pool) POOL_MTX_UNLOCK (); } +struct mempool_debug_elt { + gsize sz; + const gchar *loc; +}; + +static gint +rspamd_mempool_debug_elt_cmp (const void *a, const void *b) +{ + const struct mempool_debug_elt *e1 = a, *e2 = b; + + /* Inverse order */ + return (gint)((gssize)e2->sz) - ((gssize)e1->sz); +} + void rspamd_mempool_delete (rspamd_mempool_t * pool) { @@ -755,14 +769,29 @@ rspamd_mempool_delete (rspamd_mempool_t * pool) GHashTableIter it; gpointer k, v; + GArray *sorted_debug_size = g_array_sized_new (FALSE, FALSE, + sizeof (struct mempool_debug_elt), + g_hash_table_size (debug_tbl)); g_hash_table_iter_init (&it, debug_tbl); while (g_hash_table_iter_next (&it, &k, &v)) { - msg_info_pool ("allocated %Hz from %s", GPOINTER_TO_SIZE (v), - (const gchar *)k); + struct mempool_debug_elt e; + e.loc = (const gchar *)k; + e.sz = GPOINTER_TO_SIZE (v); + g_array_append_val (sorted_debug_size, e); + } + + g_array_sort (sorted_debug_size, rspamd_mempool_debug_elt_cmp); + + for (guint _i = 0; _i < sorted_debug_size->len; _i ++) { + struct mempool_debug_elt *e; + + e = &g_array_index (sorted_debug_size, struct mempool_debug_elt, _i); + msg_info_pool ("allocated %Hz from %s", e->sz, e->loc); } + g_array_free (sorted_debug_size, TRUE); g_hash_table_unref (debug_tbl); } |