sm_debug.c 2.5 KB

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