@@ -23,11 +23,42 @@ lblock(lua_State *L) {
2323
2424static int
2525ldumpinfo (lua_State * L ) {
26- memory_info_dump ();
26+ const char * opts = NULL ;
27+ if (lua_isstring (L , 1 )) {
28+ opts = luaL_checkstring (L ,1 );
29+ }
30+ memory_info_dump (opts );
2731
2832 return 0 ;
2933}
3034
35+ static int
36+ ljestat (lua_State * L ) {
37+ static const char * names [] = {
38+ "stats.allocated" ,
39+ "stats.resident" ,
40+ "stats.retained" ,
41+ "stats.mapped" ,
42+ "stats.active" };
43+ static size_t flush = 1 ;
44+ mallctl_int64 ("epoch" , & flush ); // refresh je.stats.cache
45+ lua_newtable (L );
46+ int i ;
47+ for (i = 0 ; i < (sizeof (names )/sizeof (names [0 ])); i ++ ) {
48+ lua_pushstring (L , names [i ]);
49+ lua_pushinteger (L , (lua_Integer ) mallctl_int64 (names [i ], NULL ));
50+ lua_settable (L , -3 );
51+ }
52+ return 1 ;
53+ }
54+
55+ static int
56+ lmallctl (lua_State * L ) {
57+ const char * name = luaL_checkstring (L ,1 );
58+ lua_pushinteger (L , (lua_Integer ) mallctl_int64 (name , NULL ));
59+ return 1 ;
60+ }
61+
3162static int
3263ldump (lua_State * L ) {
3364 dump_c_mem ();
@@ -69,6 +100,8 @@ luaopen_skynet_memory(lua_State *L) {
69100 { "total" , ltotal },
70101 { "block" , lblock },
71102 { "dumpinfo" , ldumpinfo },
103+ { "jestat" , ljestat },
104+ { "mallctl" , lmallctl },
72105 { "dump" , ldump },
73106 { "info" , dump_mem_lua },
74107 { "current" , lcurrent },
0 commit comments