Skip to content
Snippets Groups Projects
Commit 8f97c051 authored by mechanik20051988's avatar mechanik20051988 Committed by Nikita Pettik
Browse files

memtx: implement unified interface for getting allocator statistics

Since tarantool can use different allocators, we need a single
interface for getting statistics that is suitable for all allocators.
Follow-up #5419
parent dcf6fdb3
No related branches found
No related tags found
No related merge requests found
...@@ -34,7 +34,7 @@ struct small_alloc SmallAlloc::small_alloc; ...@@ -34,7 +34,7 @@ struct small_alloc SmallAlloc::small_alloc;
struct sys_alloc SysAlloc::sys_alloc; struct sys_alloc SysAlloc::sys_alloc;
int int
small_stats_noop_cb(const struct mempool_stats *stats, void *cb_ctx) stats_noop_cb(const void *stats, void *cb_ctx)
{ {
(void) stats; (void) stats;
(void) cb_ctx; (void) cb_ctx;
...@@ -42,14 +42,14 @@ small_stats_noop_cb(const struct mempool_stats *stats, void *cb_ctx) ...@@ -42,14 +42,14 @@ small_stats_noop_cb(const struct mempool_stats *stats, void *cb_ctx)
} }
void void
allocators_stats(struct allocator_stats *stats, mempool_stats_cb cb, allocators_stats(struct allocator_stats *stats, allocator_stats_cb cb,
void *cb_ctx) { void *cb_ctx) {
foreach_allocator<allocator_stat, foreach_allocator<allocator_stat,
struct allocator_stats *&, mempool_stats_cb&, void *&> struct allocator_stats *&, allocator_stats_cb&, void *&>
(stats, cb, cb_ctx); (stats, cb, cb_ctx);
} }
void void
allocators_stats(struct allocator_stats *stats) { allocators_stats(struct allocator_stats *stats) {
allocators_stats(stats, small_stats_noop_cb, nullptr); allocators_stats(stats, stats_noop_cb, nullptr);
} }
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
#include <small/small.h> #include <small/small.h>
#include "sysalloc.h" #include "sysalloc.h"
typedef int (*allocator_stats_cb)(const void *, void *);
struct alloc_stat { struct alloc_stat {
size_t used; size_t used;
size_t total; size_t total;
...@@ -45,7 +47,7 @@ struct allocator_stats { ...@@ -45,7 +47,7 @@ struct allocator_stats {
}; };
int int
small_stats_noop_cb(const struct mempool_stats *stats, void *cb_ctx); stats_noop_cb(const void *stats, void *cb_ctx);
struct allocator_settings { struct allocator_settings {
struct small_allocator { struct small_allocator {
...@@ -113,7 +115,7 @@ class SmallAlloc ...@@ -113,7 +115,7 @@ class SmallAlloc
return smfree(&small_alloc, ptr, size); return smfree(&small_alloc, ptr, size);
} }
static inline void static inline void
stats(struct allocator_stats *alloc_stats, mempool_stats_cb cb, stats(struct allocator_stats *alloc_stats, allocator_stats_cb cb,
void *cb_ctx) void *cb_ctx)
{ {
struct small_stats data_stats; struct small_stats data_stats;
...@@ -155,7 +157,7 @@ class SysAlloc ...@@ -155,7 +157,7 @@ class SysAlloc
return sysfree(&sys_alloc, ptr, size); return sysfree(&sys_alloc, ptr, size);
} }
static inline void static inline void
stats(struct allocator_stats *alloc_stats, mempool_stats_cb cb, stats(struct allocator_stats *alloc_stats, allocator_stats_cb cb,
void *cb_ctx) void *cb_ctx)
{ {
(void) cb; (void) cb;
...@@ -222,8 +224,8 @@ struct allocator_stat { ...@@ -222,8 +224,8 @@ struct allocator_stat {
}; };
void void
allocators_stats(struct allocator_stats *stats, mempool_stats_cb cb, allocators_stats(struct allocator_stats *stats, allocator_stats_cb cb,
void *cb_ctx); void *cb_ctx);
void void
allocators_stats(struct allocator_stats *stats); allocators_stats(struct allocator_stats *stats);
\ No newline at end of file
...@@ -47,10 +47,12 @@ ...@@ -47,10 +47,12 @@
#include "box/allocator.h" #include "box/allocator.h"
static int static int
small_stats_lua_cb(const struct mempool_stats *stats, void *cb_ctx) small_stats_lua_cb(const void *stats, void *cb_ctx)
{ {
const struct mempool_stats *mempool_stats =
(const struct mempool_stats *)stats;
/** Don't publish information about empty slabs. */ /** Don't publish information about empty slabs. */
if (stats->slabcount == 0) if (mempool_stats->slabcount == 0)
return 0; return 0;
struct lua_State *L = (struct lua_State *) cb_ctx; struct lua_State *L = (struct lua_State *) cb_ctx;
...@@ -69,27 +71,28 @@ small_stats_lua_cb(const struct mempool_stats *stats, void *cb_ctx) ...@@ -69,27 +71,28 @@ small_stats_lua_cb(const struct mempool_stats *stats, void *cb_ctx)
luaL_setmaphint(L, -1); luaL_setmaphint(L, -1);
lua_pushstring(L, "mem_used"); lua_pushstring(L, "mem_used");
luaL_pushuint64(L, stats->totals.used); luaL_pushuint64(L, mempool_stats->totals.used);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "slab_size"); lua_pushstring(L, "slab_size");
luaL_pushuint64(L, stats->slabsize); luaL_pushuint64(L, mempool_stats->slabsize);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "mem_free"); lua_pushstring(L, "mem_free");
luaL_pushuint64(L, stats->totals.total - stats->totals.used); luaL_pushuint64(L, mempool_stats->totals.total -
mempool_stats->totals.used);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "item_size"); lua_pushstring(L, "item_size");
luaL_pushuint64(L, stats->objsize); luaL_pushuint64(L, mempool_stats->objsize);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "slab_count"); lua_pushstring(L, "slab_count");
luaL_pushuint64(L, stats->slabcount); luaL_pushuint64(L, mempool_stats->slabcount);
lua_settable(L, -3); lua_settable(L, -3);
lua_pushstring(L, "item_count"); lua_pushstring(L, "item_count");
luaL_pushuint64(L, stats->objcount); luaL_pushuint64(L, mempool_stats->objcount);
lua_settable(L, -3); lua_settable(L, -3);
lua_settable(L, -3); lua_settable(L, -3);
......
Subproject commit 8c3a4be19932458a16618eb86c906928c984b271 Subproject commit 3d15a705817ff60ef6fe5e4b70ae4c09056927e3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment