sm_debug.c 2.5 KB

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