Improved to diagnostic routines and documentation for the debug cli interpreter

This commit is contained in:
Mark Riddoch 2013-06-20 15:03:55 +02:00
parent e55631e60f
commit 088b3473bc
6 changed files with 85 additions and 5 deletions

View File

@ -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:

View File

@ -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);

View File

@ -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";
}
}

View File

@ -17,6 +17,7 @@
*
* Copyright SkySQL Ab 2013
*/
#include <dcb.h>
/**
* @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

View File

@ -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

View File

@ -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
*/