sm_debug.c 2.4 KB

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