X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fs_debug.c;h=53338c225d43e5a7e9bb26302c36a2a2b32560ac;hb=1570a04e15bec6b2945e4351b1e05211aecdcacc;hp=91639d580737cb06da4855cf1551f4a7aa47a6fe;hpb=0b1c58ace7aad7919ce1ba9c7e58da9711e59dce;p=ircu2.10.12-pk.git diff --git a/ircd/s_debug.c b/ircd/s_debug.c index 91639d5..53338c2 100644 --- a/ircd/s_debug.c +++ b/ircd/s_debug.c @@ -16,9 +16,10 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * + */ +/** @file + * @brief Debug support for the ircd. + * @version $Id$ */ #include "config.h" @@ -36,6 +37,7 @@ #include "ircd.h" #include "jupe.h" #include "list.h" +#include "listener.h" #include "motd.h" #include "msgq.h" #include "numeric.h" @@ -43,13 +45,14 @@ #include "res.h" #include "s_bsd.h" #include "s_conf.h" +#include "s_user.h" #include "s_stats.h" #include "send.h" #include "struct.h" #include "sys.h" #include "whowas.h" -#include +/* #include -- Now using assert in ircd_log.h */ #include #include #include @@ -63,6 +66,9 @@ */ static char serveropts[256]; /* should be large enough for anything */ +/** Return a string describing important configuration information. + * @return Pointer to a static buffer. + */ const char* debug_serveropts(void) { int bp; @@ -105,21 +111,23 @@ const char* debug_serveropts(void) #if defined(USE_POLL) && defined(HAVE_POLL_H) AddC('U'); #endif +#ifdef IPV6 + AddC('6'); +#endif serveropts[i] = '\0'; return serveropts; } -/* - * debug_init - * +/** Initialize debugging. * If the -t option is not given on the command line when the server is * started, all debugging output is sent to the file set by LPATH in config.h * Here we just open that file and make sure it is opened to fd 2 so that - * any fprintf's to stderr also goto the logfile. If the debuglevel is not + * any fprintf's to stderr also go to the logfile. If the debuglevel is not * set from the command line by -x, use /dev/null as the dummy logfile as long - * as DEBUGMODE has been defined, else dont waste the fd. + * as DEBUGMODE has been defined, else don't waste the fd. + * @param use_tty Passed to log_debug_init(). */ void debug_init(int use_tty) { @@ -132,6 +140,12 @@ void debug_init(int use_tty) } #ifdef DEBUGMODE +/** Log a debug message using a va_list. + * If the current #debuglevel is less than \a level, do not display. + * @param level Debug level for message. + * @param form Format string, passed to log_vwrite(). + * @param vl Varargs argument list for format string. + */ void vdebug(int level, const char *form, va_list vl) { static int loop = 0; @@ -146,6 +160,11 @@ void vdebug(int level, const char *form, va_list vl) errno = err; } +/** Log a debug message using a variable number of arguments. + * This is a simple wrapper around debug(\a level, \a form, vl). + * @param level Debug level for message. + * @param form Format string of message. + */ void debug(int level, const char *form, ...) { va_list vl; @@ -154,18 +173,20 @@ void debug(int level, const char *form, ...) va_end(vl); } +/** Send a literal RPL_STATSDEBUG message to a user. + * @param cptr Client to receive the message. + * @param msg Text message to send to user. + */ static void debug_enumerator(struct Client* cptr, const char* msg) { assert(0 != cptr); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":%s", msg); } -/* - * This is part of the STATS replies. There is no offical numeric for this - * since this isnt an official command, in much the same way as HASH isnt. - * It is also possible that some systems wont support this call or have - * different field names for "struct rusage". - * -avalon +/** Send resource usage statistics to a client. + * @param cptr Client to send data to. + * @param sd StatDesc that generated the stats request (ignored). + * @param param Extra parameter from user (ignored). */ void send_usage(struct Client *cptr, const struct StatDesc *sd, char *param) @@ -177,11 +198,17 @@ void send_usage(struct Client *cptr, const struct StatDesc *sd, } #endif /* DEBUGMODE */ +/** Report memory usage statistics to a client. + * @param cptr Client to send data to. + * @param sd StatDesc that generated the stats request (ignored). + * @param param Extra parameter from user (ignored). + */ void count_memory(struct Client *cptr, const struct StatDesc *sd, char *param) { struct Client *acptr; struct SLink *link; + struct Ban *ban; struct Channel *chptr; struct ConfItem *aconf; const struct ConnectionClass* cltmp; @@ -192,12 +219,12 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, cn = 0, /* connections */ ch = 0, /* channels */ lcc = 0, /* local client conf links */ - us = 0, /* user structs */ chi = 0, /* channel invites */ chb = 0, /* channel bans */ wwu = 0, /* whowas users */ cl = 0, /* classes */ co = 0, /* conf lines */ + listeners = 0, /* listeners */ memberships = 0; /* channel memberships */ int usi = 0, /* users invited */ @@ -210,6 +237,8 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, chbm = 0, /* memory used by channel bans */ cm = 0, /* memory used by clients */ cnm = 0, /* memory used by connections */ + us = 0, /* user structs */ + usm = 0, /* memory used by user structs */ awm = 0, /* memory used by aways */ wwam = 0, /* whowas away memory used */ wwm = 0, /* whowas array memory used */ @@ -220,6 +249,7 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, dbufs_used = 0, /* memory used by dbufs */ msg_allocated = 0, /* memory used by struct Msg */ msgbuf_allocated = 0, /* memory used by struct MsgBuf */ + listenersm = 0, /* memory used by listetners */ rm = 0, /* res memory used */ totcl = 0, totch = 0, totww = 0, tot = 0; @@ -238,7 +268,6 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, } if (cli_user(acptr)) { - us++; for (link = cli_user(acptr)->invited; link; link = link->next) usi++; for (member = cli_user(acptr)->channel; member; member = member->next_channel) @@ -255,6 +284,7 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, } cm = c * sizeof(struct Client); cnm = cn * sizeof(struct Connection); + user_count_memory(&us, &usm); for (chptr = GlobalChannelList; chptr; chptr = chptr->next) { @@ -262,10 +292,10 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, chm += (strlen(chptr->chname) + sizeof(struct Channel)); for (link = chptr->invites; link; link = link->next) chi++; - for (link = chptr->banlist; link; link = link->next) + for (ban = chptr->banlist; ban; ban = ban->next) { chb++; - chbm += (strlen(link->value.cp) + 1 + sizeof(struct SLink)); + chbm += strlen(ban->who) + strlen(ban->banstr) + 2 + sizeof(*ban); } } @@ -284,38 +314,33 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Clients %d(%zu) Connections %d(%zu)", c, cm, cn, cnm); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, - ":Users %d(%zu) Accounts %d(%zu) Invites %d(%zu)", - us, us * sizeof(struct User), acc, acc * (ACCOUNTLEN + 1), + ":Users %zu(%zu) Accounts %d(%zu) Invites %d(%zu)", + us, usm, acc, acc * (ACCOUNTLEN + 1), usi, usi * sizeof(struct SLink)); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":User channels %d(%zu) Aways %d(%zu)", memberships, memberships * sizeof(struct Membership), aw, awm); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Attached confs %d(%zu)", - lcc, lcc * sizeof(struct SLink)); totcl = cm + cnm + us * sizeof(struct User) + memberships * sizeof(struct Membership) + awm; totcl += lcc * sizeof(struct SLink) + usi * sizeof(struct SLink); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Conflines %d(%zu)", co, - com); - - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Classes %d(%zu)", cl, - cl * sizeof(struct ConnectionClass)); + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Conflines %d(%zu) Attached %d(%zu) Classes %d(%zu)", + co, com, lcc, lcc * sizeof(struct SLink), + cl, cl * sizeof(struct ConnectionClass)); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Channels %d(%zu) Bans %d(%zu)", ch, chm, chb, chbm); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, - ":Channel membrs %d(%zu) invite %d(%zu)", memberships, + ":Channel Members %d(%zu) Invites %d(%zu)", memberships, memberships * sizeof(struct Membership), chi, chi * sizeof(struct SLink)); totch = chm + chbm + chi * sizeof(struct SLink); send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, - ":Whowas users %d(%zu) away %d(%zu)", wwu, - wwu * sizeof(struct User), wwa, wwam); - send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Whowas array %d(%zu)", - feature_int(FEAT_NICKNAMEHISTORYLENGTH), wwm); + ":Whowas Users %d(%zu) Away %d(%zu) Array %d(%zu)", + wwu, wwu * sizeof(struct User), wwa, wwam, + feature_int(FEAT_NICKNAMEHISTORYLENGTH), wwm); totww = wwu * sizeof(struct User) + wwam + wwm; @@ -330,6 +355,9 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, ":Hash: client %d(%zu), chan is the same", HASHSIZE, sizeof(void *) * HASHSIZE); + count_listener_memory(&listeners, &listenersm); + send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, + ":Listeners allocated %d(%zu)", listeners, listenersm); /* * NOTE: this count will be accurate only for the exact instant that this * message is being sent, so the count is affected by the dbufs that @@ -365,4 +393,3 @@ void count_memory(struct Client *cptr, const struct StatDesc *sd, totww, totch, totcl, com, dbufs_allocated, msg_allocated, msgbuf_allocated); } -