2 * IRC - Internet Relay Chat, ircd/s_debug.c
3 * Copyright (C) 1990 Jarkko Oikarinen and
4 * University of Oulu, Computing Center
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include "ircd_alloc.h"
30 #include "ircd_osdep.h"
31 #include "ircd_reply.h"
48 #include <stddef.h> /* offsetof */
56 * Option string. Must be before #ifdef DEBUGMODE.
59 #if BUFFERPOOL < 1000000
61 #if BUFFERPOOL > 99999
62 (char)('0' + (BUFFERPOOL/100000)),
65 (char)('0' + (BUFFERPOOL/10000) % 10),
67 (char)('0' + (BUFFERPOOL/1000) % 10),
70 #if BUFFERPOOL > 99999999
71 (char)('0' + (BUFFERPOOL/100000000)),
73 #if BUFFERPOOL > 9999999
74 (char)('0' + (BUFFERPOOL/10000000) % 10),
76 (char)('0' + (BUFFERPOOL/1000000) % 10),
96 #ifdef OPER_NO_CHAN_LIMIT
99 #ifdef OPER_MODE_LCHAN
105 #if defined(SHOW_INVISIBLE_USERS) || defined(SHOW_ALL_INVISIBLE_USERS)
106 #ifdef SHOW_ALL_INVISIBLE_USERS
113 #ifdef LOCAL_KILL_ONLY
122 #ifdef OPER_WALK_THROUGH_LMODES
131 #ifdef NO_OPER_DEOP_LCHAN
134 #ifdef CRYPT_OPER_PASSWORD
137 #ifdef CRYPT_LINK_PASSWORD
147 #ifdef RELIABLE_CLOCK
159 #if defined(USE_POLL) && defined(HAVE_POLL_H)
180 * If the -t option is not given on the command line when the server is
181 * started, all debugging output is sent to the file set by LPATH in config.h
182 * Here we just open that file and make sure it is opened to fd 2 so that
183 * any fprintf's to stderr also goto the logfile. If the debuglevel is not
184 * set from the command line by -x, use /dev/null as the dummy logfile as long
185 * as DEBUGMODE has been defined, else dont waste the fd.
187 void debug_init(int use_tty)
190 if (debuglevel >= 0) {
191 printf("isatty = %d ttyname = %s\n", isatty(2), ttyname(2));
192 log_debug_init(use_tty ? 0 : LOGFILE);
198 void vdebug(int level, const char *form, va_list vl)
203 if (!loop && (debuglevel >= 0) && (level <= debuglevel))
206 log_vwrite(LS_DEBUG, L_DEBUG, 0, form, vl);
212 void debug(int level, const char *form, ...)
216 vdebug(level, form, vl);
220 static void debug_enumerator(struct Client* cptr, const char* msg)
223 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":%s", msg);
227 * This is part of the STATS replies. There is no offical numeric for this
228 * since this isnt an official command, in much the same way as HASH isnt.
229 * It is also possible that some systems wont support this call or have
230 * different field names for "struct rusage".
233 void send_usage(struct Client *cptr, char *nick)
235 os_get_rusage(cptr, CurrentTime - me.since, debug_enumerator);
237 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":DBUF alloc %d used %d",
238 DBufAllocCount, DBufUsedCount);
240 #endif /* DEBUGMODE */
242 void count_memory(struct Client *cptr, char *nick)
244 struct Client *acptr;
246 struct Channel *chptr;
247 struct ConfItem *aconf;
248 const struct ConnectionClass* cltmp;
249 struct Membership* member;
251 int lc = 0, /* local clients */
252 ch = 0, /* channels */
253 lcc = 0, /* local client conf links */
254 rc = 0, /* remote clients */
255 us = 0, /* user structs */
256 chi = 0, /* channel invites */
257 chb = 0, /* channel bans */
258 wwu = 0, /* whowas users */
259 cl = 0, /* classes */
260 co = 0, /* conf lines */
261 memberships = 0; /* channel memberships */
263 int usi = 0, /* users invited */
264 aw = 0, /* aways set */
265 wwa = 0; /* whowas aways */
267 size_t chm = 0, /* memory used by channels */
268 chbm = 0, /* memory used by channel bans */
269 lcm = 0, /* memory used by local clients */
270 rcm = 0, /* memory used by remote clients */
271 awm = 0, /* memory used by aways */
272 wwam = 0, /* whowas away memory used */
273 wwm = 0, /* whowas array memory used */
274 com = 0, /* memory used by conf lines */
275 dbufs_allocated = 0, /* memory used by dbufs */
276 dbufs_used = 0, /* memory used by dbufs */
277 rm = 0, /* res memory used */
278 totcl = 0, totch = 0, totww = 0, tot = 0;
280 count_whowas_memory(&wwu, &wwm, &wwa, &wwam);
281 wwm += sizeof(struct Whowas) * NICKNAMEHISTORYLENGTH;
282 wwm += sizeof(struct Whowas *) * WW_MAX;
284 for (acptr = GlobalClientList; acptr; acptr = acptr->next)
286 if (MyConnect(acptr))
289 for (link = acptr->confs; link; link = link->next)
297 for (link = acptr->user->invited; link; link = link->next)
299 for (member = acptr->user->channel; member; member = member->next_channel)
301 if (acptr->user->away)
304 awm += (strlen(acptr->user->away) + 1);
308 lcm = lc * CLIENT_LOCAL_SIZE;
309 rcm = rc * CLIENT_REMOTE_SIZE;
311 for (chptr = GlobalChannelList; chptr; chptr = chptr->next)
314 chm += (strlen(chptr->chname) + sizeof(struct Channel));
317 * XXX - Members already counted in clients, don't count twice
319 for (member = chptr->members; member; member = member->next_member)
322 for (link = chptr->invites; link; link = link->next)
324 for (link = chptr->banlist; link; link = link->next)
327 chbm += (strlen(link->value.cp) + 1 + sizeof(struct SLink));
331 for (aconf = GlobalConfList; aconf; aconf = aconf->next)
334 com += aconf->host ? strlen(aconf->host) + 1 : 0;
335 com += aconf->passwd ? strlen(aconf->passwd) + 1 : 0;
336 com += aconf->name ? strlen(aconf->name) + 1 : 0;
337 com += sizeof(struct ConfItem);
340 for (cltmp = get_class_list(); cltmp; cltmp = cltmp->next)
343 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
344 ":Client Local %d(%zu) Remote %d(%zu)", lc, lcm, rc, rcm);
345 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
346 ":Users %d(%zu) Invites %d(%zu)", us, us * sizeof(struct User),
347 usi, usi * sizeof(struct SLink));
348 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
349 ":User channels %d(%zu) Aways %d(%zu)", memberships,
350 memberships * sizeof(struct Membership), aw, awm);
351 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Attached confs %d(%zu)",
352 lcc, lcc * sizeof(struct SLink));
354 totcl = lcm + rcm + us * sizeof(struct User) + memberships * sizeof(struct Membership) + awm;
355 totcl += lcc * sizeof(struct SLink) + usi * sizeof(struct SLink);
357 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Conflines %d(%zu)", co,
360 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Classes %d(%zu)", cl,
361 cl * sizeof(struct ConnectionClass));
363 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
364 ":Channels %d(%zu) Bans %d(%zu)", ch, chm, chb, chbm);
365 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
366 ":Channel membrs %d(%zu) invite %d(%zu)", memberships,
367 memberships * sizeof(struct Membership), chi,
368 chi * sizeof(struct SLink));
370 totch = chm + chbm + chi * sizeof(struct SLink);
372 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
373 ":Whowas users %d(%zu) away %d(%zu)", wwu,
374 wwu * sizeof(struct User), wwa, wwam);
375 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Whowas array %d(%zu)",
376 NICKNAMEHISTORYLENGTH, wwm);
378 totww = wwu * sizeof(struct User) + wwam + wwm;
380 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
381 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
382 sizeof(void *) * HASHSIZE);
385 * NOTE: this count will be accurate only for the exact instant that this
386 * message is being sent, so the count is affected by the dbufs that
387 * are being used to send this message out. If this is not desired, move
388 * the dbuf_count_memory call to a place before we start sending messages
389 * and cache DBufAllocCount and DBufUsedCount in variables until they
392 dbuf_count_memory(&dbufs_allocated, &dbufs_used);
393 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
394 ":DBufs allocated %d(%zu) used %d(%zu)", DBufAllocCount,
395 dbufs_allocated, DBufUsedCount, dbufs_used);
400 totww + totch + totcl + com + cl * sizeof(struct ConnectionClass) + dbufs_allocated +
402 tot += sizeof(void *) * HASHSIZE * 3;
405 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, ":Allocations: %zu(%zu)",
406 fda_get_block_count(), fda_get_byte_count());
409 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
410 ":Total: ww %zu ch %zu cl %zu co %zu db %zu", totww, totch,
411 totcl, com, dbufs_allocated);