REORG: cli: move 'show pools' to memory.c

Move 'show pools' CLI functions to memory.c and use the cli keyword
API to register it on the CLI.
This commit is contained in:
William Lallemand 2016-11-19 02:25:36 +01:00 committed by Willy Tarreau
parent 222baf20da
commit e7ed8855de
3 changed files with 42 additions and 25 deletions

View File

@ -117,7 +117,6 @@ enum {
STAT_CLI_O_CLR, /* clear tables */
STAT_CLI_O_SET, /* set entries in tables */
STAT_CLI_O_STAT, /* dump stats */
STAT_CLI_O_POOLS, /* dump memory pools */
STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */
STAT_CLI_O_BACKEND, /* dump backend list */
STAT_CLI_O_ENV, /* dump environment */

View File

@ -137,7 +137,6 @@ static int stats_dump_backend_to_buffer(struct stream_interface *si);
static int stats_dump_env_to_buffer(struct stream_interface *si);
static int stats_dump_info_to_buffer(struct stream_interface *si);
static int stats_dump_servers_state_to_buffer(struct stream_interface *si);
static int stats_dump_pools_to_buffer(struct stream_interface *si);
static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess);
static int stats_dump_sess_to_buffer(struct stream_interface *si);
static int stats_dump_errors_to_buffer(struct stream_interface *si);
@ -157,7 +156,6 @@ static const char stats_sock_usage_msg[] =
" show backend : list backends in the current running config\n"
" show env [var] : dump environment variables known to the process\n"
" show info : report information about the running process\n"
" show pools : report information about the memory pools usage\n"
" show stat : report counters for each proxy and server\n"
" show errors : report last request and response errors for each proxy\n"
" show sess [id] : report the list of current sessions or dump this session\n"
@ -1136,10 +1134,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer
return 1;
}
else if (strcmp(args[1], "pools") == 0) {
appctx->st2 = STAT_ST_INIT;
appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer
}
else if (strcmp(args[1], "sess") == 0) {
appctx->st2 = STAT_ST_INIT;
if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
@ -1961,10 +1955,6 @@ static void cli_io_handler(struct appctx *appctx)
if (stats_table_request(si, appctx->st0))
appctx->st0 = STAT_CLI_PROMPT;
break;
case STAT_CLI_O_POOLS:
if (stats_dump_pools_to_buffer(si))
appctx->st0 = STAT_CLI_PROMPT;
break;
case STAT_CLI_O_ENV: /* environment dump */
if (stats_dump_env_to_buffer(si))
appctx->st0 = STAT_CLI_PROMPT;
@ -2344,20 +2334,6 @@ static int stats_dump_servers_state_to_buffer(struct stream_interface *si)
return 1;
}
/* This function dumps memory usage information onto the stream interface's
* read buffer. It returns 0 as long as it does not complete, non-zero upon
* completion. No state is used.
*/
static int stats_dump_pools_to_buffer(struct stream_interface *si)
{
dump_pools_to_trash();
if (bi_putchk(si_ic(si), &trash) == -1) {
si_applet_cant_put(si);
return 0;
}
return 1;
}
static inline const char *get_conn_ctrl_name(const struct connection *conn)
{
if (!conn_ctrl_ready(conn))

View File

@ -10,14 +10,23 @@
*
*/
#include <types/applet.h>
#include <types/cli.h>
#include <types/global.h>
#include <types/stats.h>
#include <common/config.h>
#include <common/debug.h>
#include <common/memory.h>
#include <common/mini-clist.h>
#include <common/standard.h>
#include <proto/applet.h>
#include <proto/cli.h>
#include <proto/channel.h>
#include <proto/log.h>
#include <proto/stream_interface.h>
#include <proto/stats.h>
static struct list pools = LIST_HEAD_INIT(pools);
int mem_poison_byte = -1;
@ -264,6 +273,39 @@ unsigned long pool_total_used()
return used;
}
/* This function dumps memory usage information onto the stream interface's
* read buffer. It returns 0 as long as it does not complete, non-zero upon
* completion. No state is used.
*/
static int cli_io_handler_dump_pools(struct appctx *appctx)
{
struct stream_interface *si = appctx->owner;
dump_pools_to_trash();
if (bi_putchk(si_ic(si), &trash) == -1) {
si_applet_cant_put(si);
return 0;
}
return 1;
}
static int cli_parse_show_pools(char **args, struct appctx *appctx, void *private)
{
return 0;
}
/* register cli keywords */
static struct cli_kw_list cli_kws = {{ },{
{ { "show", "pools", NULL }, "show pools : report information about the memory pools usage", cli_parse_show_pools, cli_io_handler_dump_pools },
{{},}
}};
__attribute__((constructor))
static void __memory_init(void)
{
cli_register_kw(&cli_kws);
}
/*
* Local variables:
* c-indent-level: 8