Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more monitor data #14

Merged
merged 1 commit into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lualib-src/lualib-silly.c
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,16 @@ lmemallocator(lua_State *L)
return 1;
}

static int
lmemallocatorinfo(lua_State *L)
{
size_t allocated, active, resident;
silly_allocator_info(&allocated, &active, &resident);
lua_pushinteger(L, allocated);
lua_pushinteger(L, active);
lua_pushinteger(L, resident);
return 3;
}
static int
lmemused(lua_State *L)
{
Expand Down Expand Up @@ -646,6 +656,16 @@ lnetinfo(lua_State *L)
return 1;
}

static int
ltimerinfo(lua_State *L)
{
uint32_t active, expired;
active = silly_timer_info(&expired);
lua_pushinteger(L, active);
lua_pushinteger(L, expired);
return 2;
}

static int
lsocketinfo(lua_State *L)
{
Expand Down Expand Up @@ -709,10 +729,12 @@ luaopen_sys_silly(lua_State *L)
{"memused", lmemused},
{"memrss", lmemrss},
{"memallocator", lmemallocator},
{"memallocatorinfo", lmemallocatorinfo},
{"msgsize", lmsgsize},
{"cpuinfo", lcpuinfo},
{"pollapi", lpollapi},
{"netinfo", lnetinfo},
{"timerinfo", ltimerinfo},
{"socketinfo", lsocketinfo},
{"timerresolution", ltimerresolution},
//end
Expand Down
68 changes: 41 additions & 27 deletions lualib/sys/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ local desc = {
"HELP: List command description. [HELP]",
"PING: Test connection alive. [PING <text>]",
"GC: Performs a full garbage-collection cycle. [GC]",
"INFO: Show all information of server, include CPUINFO,MINFO,QINFO,NETINFO,TASK. [INFO]",
"INFO: Show all information of server, include CPUINFO,MINFO,QINFO. [INFO]",
"MINFO: Show memory infomation. [MINFO <kb|mb>]",
"QINFO: Show framework message queue size. [QINFO]",
"NETINFO: Show network info. [NETINFO]",
"TIMERINFO: Show timer pending/process event count. [TIMERINFO]",
"CPUINFO: Show system time and user time statistics. [CPUINFO]",
"SOCKET: Show socket detail information. [SOCKET]",
"TASK: Show all task status and traceback. [TASK]",
Expand Down Expand Up @@ -59,39 +60,55 @@ function console.gc()
return format("Lua Mem Used:%.2f KiB", collectgarbage("count"))
end

function console.timerinfo()
return format("#Timer\r\n\z
resolution:%s\r\n\z
active:%s\r\n\z
expired:%s\r\n",
core.timerrs, core.timerinfo())
end

function console.cpuinfo()
local sys, usr = core.cpuinfo()
return format("#CPU\r\ncpu_sys:%.2fs\r\ncpu_user:%.2fs", sys, usr)
end

local function format_size(fmt, size)
if fmt == "kb" then
return format("%.2f KiB", size / 1024)
elseif fmt == "mb" then
return format("%.2f MB", size / (1024 * 1024))
else
return format("%d B", size)
end
end

function console.minfo(_, fmt)
local tbl = {}
local sz = core.memused()
if fmt then
fmt = lower(fmt)
else
fmt = NULL
end
tbl[1] = "#Memory\r\n"
tbl[2] = "memory_used:"
if fmt == "kb" then
tbl[3] = format("%.2f", sz / 1024)
tbl[4] = " KiB\r\n"
elseif fmt == "mb" then
tbl[3] = format("%.2f", sz / (1024 * 1024))
tbl[4] = " MB\r\n"
else
tbl[3] = sz
tbl[4] = " B\r\n"
end
local sz = core.memused()
local rss = core.memrss()
tbl[5] = "memory_rss:"
tbl[6] = rss
tbl[7] = " B\r\n"
tbl[8] = "memory_fragmentation_ratio:"
tbl[9] = format("%.2f\r\n", rss / sz)
tbl[10] = "memory_allocator:"
tbl[11] = core.allocator
local allocated, active, resident = core.allocatorinfo()
local tbl = {
"#Memory",
"\r\nused_memory:",
format_size(fmt, sz),
"\r\nused_memory_rss:",
format_size(fmt, rss),
"\r\nallocator_allocated:",
format_size(fmt, allocated),
"\r\nallocator_active:",
format_size(fmt, active),
"\r\nallocator_resident:",
format_size(fmt, resident),
"\r\nmemory_fragmentation_ratio:",
format("%.2f", rss / sz),
"\r\nmemory_allocator:",
core.allocator,
}
return concat(tbl)
end

Expand Down Expand Up @@ -147,18 +164,15 @@ function console.info()
insert(tbl, format("version:%s", core.version))
insert(tbl, format("process_id:%s", core.getpid()))
insert(tbl, format("multiplexing_api:%s", core.pollapi))
insert(tbl, format("timer_resolution:%s", core.timerrs))
insert(tbl, format("uptime_in_seconds:%s", uptime))
insert(tbl, format("uptime_in_days:%.2f\r\n", uptime / (24 * 3600)))
insert(tbl, console.cpuinfo())
insert(tbl, NULL)
insert(tbl, console.qinfo())
insert(tbl, NULL)
insert(tbl, console.minfo("MB"))
insert(tbl, NULL)
insert(tbl, console.netinfo())
insert(tbl, console.minfo(nil, "MB"))
insert(tbl, NULL)
insert(tbl, console.task())
insert(tbl, console.timerinfo())
return concat(tbl, "\r\n")
end

Expand Down
2 changes: 2 additions & 0 deletions lualib/sys/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ core.cpuinfo = silly.cpuinfo
core.getpid = silly.getpid
core.netinfo = silly.netinfo
core.socketinfo = silly.socketinfo
core.timerinfo = silly.timerinfo
core.allocatorinfo = silly.memallocatorinfo
--const
core.allocator = silly.memallocator()
core.version = silly.version()
Expand Down
16 changes: 16 additions & 0 deletions silly-src/silly_malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ silly_memrss()
#else
return allocsize;
#endif
}

void
silly_allocator_info(size_t *allocated, size_t *active, size_t *resident)
{
size_t sz;
uint64_t epoch = 1;
*allocated = *resident = *active = 0;
#ifndef DISABLE_JEMALLOC
sz = sizeof(epoch);
je_mallctl("epoch", &epoch, &sz, &epoch, sz);
sz = sizeof(size_t);
je_mallctl("stats.resident", resident, &sz, NULL, 0);
je_mallctl("stats.active", active, &sz, NULL, 0);
je_mallctl("stats.allocated", allocated, &sz, NULL, 0);
#endif
return ;
}

1 change: 1 addition & 0 deletions silly-src/silly_malloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ void silly_free(void *ptr);
const char *silly_allocator();
size_t silly_memused();
size_t silly_memrss();
void silly_allocator_info(size_t *allocated, size_t *active, size_t *resident);

#endif

13 changes: 13 additions & 0 deletions silly-src/silly_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ struct silly_timer {
uint64_t monotonic;
struct slot_root root;
struct slot_level level[4];
uint32_t expired_count;
uint32_t active_count;
};

static struct silly_timer *T;

static inline struct node *
newnode()
{
atomic_add(&T->active_count, 1);
atomic_add(&T->expired_count, 1);
struct node *n = silly_malloc(sizeof(*n));
uint32_t session = silly_worker_genid();
n->session = session;
Expand All @@ -65,6 +69,7 @@ newnode()
static inline void
freenode(struct node *n)
{
atomic_sub(&T->active_count, 1);
silly_free(n);
return ;
}
Expand Down Expand Up @@ -107,6 +112,14 @@ silly_timer_monotonicsec()
return T->monotonic / scale;
}

uint32_t
silly_timer_info(uint32_t *expired)
{
if (expired!= NULL)
*expired = T->expired_count;
return T->active_count;
}

static inline void
linklist(struct node **list, struct node *n)
{
Expand Down
1 change: 1 addition & 0 deletions silly-src/silly_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ uint64_t silly_timer_now();
time_t silly_timer_nowsec();
uint64_t silly_timer_monotonic();
time_t silly_timer_monotonicsec();
uint32_t silly_timer_info(uint32_t *expired);

#endif

Expand Down