From 5d3c3c576c905c21a217c8919411470a64f9b543 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 12 Feb 2020 19:11:52 +0800 Subject: [PATCH] add function fast_mpool_log_stats --- .gitignore | 1 + HISTORY | 3 ++- src/fast_mpool.c | 18 ++++++++++++++++-- src/fast_mpool.h | 12 +++++++++++- src/tests/test_uniq_skiplist.c | 2 +- src/uniq_skiplist.c | 14 ++++++++------ 6 files changed, 39 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 03a9130..5f8b3dc 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,7 @@ src/tests/test_split_string src/tests/test_uniq_skiplist # other +*.swp php-fastcommon/.deps php-fastcommon/.libs/ diff --git a/HISTORY b/HISTORY index e63341e..3928aee 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-02-09 +Version 1.44 2020-02-12 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex @@ -7,6 +7,7 @@ Version 1.44 2020-02-09 * struct fast_task_info add field: nio_stage * add function fc_memrchr * add function is_network_error + * add function fast_mpool_log_stats Version 1.43 2019-12-25 * replace function call system to getExecResult, diff --git a/src/fast_mpool.c b/src/fast_mpool.c index 46b3302..acaf201 100644 --- a/src/fast_mpool.c +++ b/src/fast_mpool.c @@ -200,7 +200,8 @@ void fast_mpool_reset(struct fast_mpool_man *mpool) } } -void fast_mpool_stats(struct fast_mpool_man *mpool, struct fast_mpool_stats *stats) +void fast_mpool_stats(struct fast_mpool_man *mpool, + struct fast_mpool_stats *stats) { struct fast_mpool_malloc *pMallocNode; @@ -213,7 +214,8 @@ void fast_mpool_stats(struct fast_mpool_man *mpool, struct fast_mpool_stats *sta while (pMallocNode != NULL) { stats->total_bytes += pMallocNode->alloc_size; - stats->free_bytes += (int)(pMallocNode->end_ptr - pMallocNode->free_ptr); + stats->free_bytes += (int)(pMallocNode->end_ptr - + pMallocNode->free_ptr); stats->total_trunk_count++; pMallocNode = pMallocNode->malloc_next; @@ -227,3 +229,15 @@ void fast_mpool_stats(struct fast_mpool_man *mpool, struct fast_mpool_stats *sta } } +void fast_mpool_log_stats(struct fast_mpool_man *mpool) +{ + struct fast_mpool_stats stats; + + fast_mpool_stats(mpool, &stats); + logInfo("alloc_size_once: %d, discard_size: %d, " + "bytes: {total: %"PRId64", free: %"PRId64"}, " + "trunk_count: {total: %d, free: %d}", + mpool->alloc_size_once, mpool->discard_size, + stats.total_bytes, stats.free_bytes, + stats.total_trunk_count, stats.free_trunk_count); +} diff --git a/src/fast_mpool.h b/src/fast_mpool.h index 8f9f4f4..4276612 100644 --- a/src/fast_mpool.h +++ b/src/fast_mpool.h @@ -130,8 +130,18 @@ get stats parameters: mpool: the mpool pointer stats: return the stats +return none */ -void fast_mpool_stats(struct fast_mpool_man *mpool, struct fast_mpool_stats *stats); +void fast_mpool_stats(struct fast_mpool_man *mpool, + struct fast_mpool_stats *stats); + +/** +log stats info +parameters: + mpool: the mpool pointer +return none +*/ +void fast_mpool_log_stats(struct fast_mpool_man *mpool); #ifdef __cplusplus } diff --git a/src/tests/test_uniq_skiplist.c b/src/tests/test_uniq_skiplist.c index 5787361..34f7dbd 100644 --- a/src/tests/test_uniq_skiplist.c +++ b/src/tests/test_uniq_skiplist.c @@ -21,7 +21,7 @@ static UniqSkiplist *sl = NULL; static UniqSkiplistIterator iterator; static int instance_count = 0; -static void free_test_func(void *ptr) +static void free_test_func(void *ptr, const int delay_seconds) { instance_count--; } diff --git a/src/uniq_skiplist.c b/src/uniq_skiplist.c index 9f09c2d..241b387 100644 --- a/src/uniq_skiplist.c +++ b/src/uniq_skiplist.c @@ -48,6 +48,7 @@ int uniq_skiplist_init_ex(UniqSkiplistFactory *factory, uniq_skiplist_free_func free_func, const int alloc_skiplist_once, const int min_alloc_elements_once, const int delay_free_seconds) { + char name[64]; int bytes; int element_size; int i; @@ -91,10 +92,11 @@ int uniq_skiplist_init_ex(UniqSkiplistFactory *factory, } for (i=max_level_count-1; i>=0; i--) { + sprintf(name, "sl-level%02d", i); element_size = sizeof(UniqSkiplistNode) + sizeof(UniqSkiplistNode *) * (i + 1); - if ((result=fast_mblock_init_ex(factory->node_allocators + i, - element_size, alloc_elements_once, NULL, NULL, false)) != 0) + if ((result=fast_mblock_init_ex1(factory->node_allocators + i, + name, element_size, alloc_elements_once, NULL, NULL, false)) != 0) { return result; } @@ -103,10 +105,10 @@ int uniq_skiplist_init_ex(UniqSkiplistFactory *factory, } } - if ((result=fast_mblock_init_ex(&factory->skiplist_allocator, - sizeof(UniqSkiplist), alloc_skiplist_once > 0 ? - alloc_skiplist_once : 16 * 1024, - NULL, NULL, false)) != 0) + if ((result=fast_mblock_init_ex1(&factory->skiplist_allocator, + "skiplist", sizeof(UniqSkiplist), + alloc_skiplist_once > 0 ? alloc_skiplist_once : + 16 * 1024, NULL, NULL, false)) != 0) { return result; }