From 088b3473bc9243a505cd52b86923fe4cde5e3bd7 Mon Sep 17 00:00:00 2001 From: Mark Riddoch Date: Thu, 20 Jun 2013 15:03:55 +0200 Subject: [PATCH] Improved to diagnostic routines and documentation for the debug cli interpreter --- core/dcb.c | 7 +++--- core/server.c | 1 + core/session.c | 45 ++++++++++++++++++++++++++++++++++++++ include/server.h | 3 ++- include/session.h | 4 +++- modules/routing/debugcmd.c | 30 +++++++++++++++++++++++++ 6 files changed, 85 insertions(+), 5 deletions(-) diff --git a/core/dcb.c b/core/dcb.c index f7e5f9b22..d1d7a5ff5 100644 --- a/core/dcb.c +++ b/core/dcb.c @@ -436,10 +436,10 @@ DCB *dcb; } /** - * Diagnostic to print a DCB + * Diagnostic to print a DCB to another DCB * + * @param pdcb The DCB to which send the output * @param dcb The DCB to print - * */ void dprintDCB(DCB *pdcb, DCB *dcb) @@ -448,6 +448,7 @@ dprintDCB(DCB *pdcb, DCB *dcb) dcb_printf(pdcb, "\tDCB state: %s\n", gw_dcb_state2string(dcb->state)); if (dcb->remote) dcb_printf(pdcb, "\tConnected to: %s\n", dcb->remote); + dcb_printf(pdcb, "\tOwning Session: %d\n", dcb->session); dcb_printf(pdcb, "\tQueued write data: %d\n", gwbuf_length(dcb->writeq)); dcb_printf(pdcb, "\tStatistics:\n"); dcb_printf(pdcb, "\t\tNo. of Reads: %d\n", dcb->stats.n_reads); @@ -471,7 +472,7 @@ gw_dcb_state2string (int state) { case DCB_STATE_IDLE: return "DCB not yet in polling"; case DCB_STATE_POLLING: - return "DCB in the EPOLL"; + return "DCB in the polling loop"; case DCB_STATE_PROCESSING: return "DCB processing event"; case DCB_STATE_LISTENING: diff --git a/core/server.c b/core/server.c index c8c5110f1..a82941a69 100644 --- a/core/server.c +++ b/core/server.c @@ -160,6 +160,7 @@ SERVER *ptr; dcb_printf(dcb, "\tServer: %s\n", ptr->name); dcb_printf(dcb, "\tProtocol: %s\n", ptr->protocol); dcb_printf(dcb, "\tPort: %d\n", ptr->port); + dcb_printf(dcb, "\tNumber of connections: %d\n", ptr->stats.n_connections); ptr = ptr->next; } spinlock_release(&server_spin); diff --git a/core/session.c b/core/session.c index 412661730..6cb57807d 100644 --- a/core/session.c +++ b/core/session.c @@ -152,6 +152,8 @@ SESSION *ptr; * * Designed to be called within a debugger session in order * to display all active sessions within the gateway + * + * @param dcb The DCB to print to */ void dprintAllSessions(DCB *dcb) @@ -172,3 +174,46 @@ SESSION *ptr; } spinlock_release(&session_spin); } + +/** + * Print a particular session to a DCB + * + * Designed to be called within a debugger session in order + * to display all active sessions within the gateway + * + * @param dcb The DCB to print to + * @param ptr The session to print + */ +void +dprintSession(DCB *dcb, SESSION *ptr) +{ + dcb_printf(dcb, "Session %p\n", ptr); + dcb_printf(dcb, "\tState: %s\n", session_state(ptr->state)); + dcb_printf(dcb, "\tService: %s (%p)\n", ptr->service->name, ptr->service); + dcb_printf(dcb, "\tClient DCB: %p\n", ptr->client); + if (ptr->client && ptr->client->remote) + dcb_printf(dcb, "\tClient Address: %s\n", ptr->client->remote); + dcb_printf(dcb, "\tConnected: %s", asctime(localtime(&ptr->stats.connect))); +} + +/** + * Convert a session state to a string representation + * + * @param state The session state + * @return A string representation of the session state + */ +char * +session_state(int state) +{ + switch (state) + { + case SESSION_STATE_ALLOC: + return "Session Allocated"; + case SESSION_STATE_READY: + return "Session Ready"; + case SESSION_STATE_LISTENER: + return "Listener Session"; + default: + return "Invalid State"; + } +} diff --git a/include/server.h b/include/server.h index d5097aba4..66bdd9620 100644 --- a/include/server.h +++ b/include/server.h @@ -17,6 +17,7 @@ * * Copyright SkySQL Ab 2013 */ +#include /** * @file service.h @@ -59,5 +60,5 @@ extern SERVER *server_alloc(char *, char *, unsigned short); extern int server_free(SERVER *); extern void printServer(SERVER *); extern void printAllServers(); -extern void dprintAllServers(); +extern void dprintAllServers(DCB *); #endif diff --git a/include/session.h b/include/session.h index b593345ba..eaa443f32 100644 --- a/include/session.h +++ b/include/session.h @@ -54,7 +54,7 @@ typedef struct session { struct dcb *client; /**< The client connection */ struct dcb *backends; /**< The set of backend servers */ void *data; /**< The session data */ - void *router_session;/**< The router insatnce data */ + void *router_session;/**< The router instance data */ SESSION_STATS stats; /**< Session statistics */ struct service *service; /**< The service this session is using */ struct session *next; /**< Linked list of all sessions */ @@ -71,4 +71,6 @@ extern void session_free(SESSION *); extern void printAllSessions(); extern void printSession(SESSION *); extern void dprintAllSessions(struct dcb *); +extern void dprintSession(struct dcb *, SESSION *); +extern char *session_state(int); #endif diff --git a/modules/routing/debugcmd.c b/modules/routing/debugcmd.c index af52b4e4c..cd472e967 100644 --- a/modules/routing/debugcmd.c +++ b/modules/routing/debugcmd.c @@ -19,6 +19,17 @@ /** * @file debugcmd.c - The debug CLI command line interpreter * + * The command interpreter for the dbug user interface. The command + * structure is such that there are a numerb of commands, notably + * show and a set of subcommands, the things to show in this case. + * + * Each subcommand has a handler function defined for it that is passeed + * the DCB to use to print the output of the commands and up to 3 arguments + * as numeric values. + * + * There are two "built in" commands, the help command and the quit + * command. + * * @verbatim * Revision History * @@ -54,8 +65,12 @@ struct subcommand { char *help; }; +/** + * The subcommands of the show command + */ struct subcommand showoptions[] = { { "sessions", 0, dprintAllSessions, "Show all active sessions in the gateway" }, + { "session", 1, dprintSession, "Show a single session in the gateway, e.g. show session 0x284830" }, { "services", 0, dprintAllServices, "Show all configured services in the gateway" }, { "servers", 0, dprintAllServers, "Show all configured servers" }, { "modules", 0, dprintAllModules, "Show all currently loaded modules" }, @@ -77,6 +92,13 @@ static struct { }; +/** + * Convert a string argument to a numeric, observing prefixes + * for number bases, e.g. 0x for hex, 0 for octal + * + * @param arg The string representation of the argument + * @return The argument as a long integer + */ static long convert_arg(char *arg) { @@ -86,6 +108,14 @@ convert_arg(char *arg) /** * We have a complete line from the user, lookup the commands and execute them * + * Commands are tokenised based on white space and then the firt + * word is checked againts the cmds table. If a amtch is found the + * second word is compared to the different options for that command. + * + * Commands may also take up to 3 additional arguments, these are all + * assumed to the numeric values and will be converted before being passed + * to the handler function for the command. + * * @param cli The CLI_SESSION * @return Returns 0 if the interpreter should exit */