sm_debug.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* $Id: sm_debug.c,v 1.7 2005/10/18 19:58:11 dijkstra Exp $ */
  2. /*
  3. * Copyright (c) 2001-2005 Willem Dijkstra
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * - Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following
  14. * disclaimer in the documentation and/or other materials provided
  15. * with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  27. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. /*
  32. * Get current debug statistics from kernel and return them in symon_buf as
  33. *
  34. * debug0 : debug1 : ... : debug19
  35. */
  36. #include <sys/param.h>
  37. #include <sys/sysctl.h>
  38. #include <string.h>
  39. #include "conf.h"
  40. #include "error.h"
  41. #include "symon.h"
  42. /* Globals for this module start with db_ */
  43. static int db_mib[] = { CTL_DEBUG, 0, CTL_DEBUG_VALUE };
  44. static int db_v[SYMON_MAXDEBUGID];
  45. void
  46. init_debug(struct stream *st)
  47. {
  48. info("started module debug(%.200s)", st->arg);
  49. }
  50. int
  51. get_debug(char *symon_buf, int maxlen, struct stream *st)
  52. {
  53. size_t len;
  54. int i;
  55. bzero((void *) db_v, sizeof(db_v));
  56. len = sizeof(int);
  57. for (i = 0; i < SYMON_MAXDEBUGID; i++) {
  58. db_mib[1] = i;
  59. sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
  60. }
  61. return snpack(symon_buf, maxlen, st->arg, MT_DEBUG,
  62. db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
  63. db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
  64. db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
  65. }