sm_debug.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* $Id: sm_debug.c,v 1.2 2005/02/04 09:49:26 dijkstra Exp $ */
  2. /*
  3. * Copyright (c) 2004 Matthew Gream
  4. * Copyright (c) 2001-2004 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. */
  38. #include <sys/param.h>
  39. #include <sys/sysctl.h>
  40. #include <string.h>
  41. #include "error.h"
  42. #include "symon.h"
  43. #define SYMON_MAXDEBUGID 20 /* = CTL_DEBUG_MAXID; depends lib/data.h */
  44. /* Globals for this module start with db_ */
  45. static int db_mib[] = { CTL_DEBUG, 0, CTL_DEBUG_VALUE };
  46. static int db_v[SYMON_MAXDEBUGID];
  47. /* Prepare if module for first use */
  48. void
  49. init_debug(char *s)
  50. {
  51. info("started module debug(%.200s)", s);
  52. }
  53. /* Get debug statistics */
  54. int
  55. get_debug(char *symon_buf, int maxlen, char *s)
  56. {
  57. size_t len;
  58. int i;
  59. bzero((void *) db_v, sizeof(db_v));
  60. len = sizeof(int);
  61. for (i = 0; i < SYMON_MAXDEBUGID; i++) {
  62. db_mib[1] = i;
  63. sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
  64. }
  65. return snpack(symon_buf, maxlen, s, MT_DEBUG,
  66. db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
  67. db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
  68. db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
  69. }