1 /*
2 * Copyright (c) 2004 Matthew Gream
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 /*
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
41 #include <string.h>
42
43 #include "conf.h"
44 #include "error.h"
45 #include "symon.h"
46
47 /* Globals for this module start with db_ */
48 static int db_mib[] = { CTL_DEBUG, 0, CTL_DEBUG_VALUE };
49 static int db_v[SYMON_MAXDEBUGID];
50
51 void
init_debug(struct stream * st)52 init_debug(struct stream *st)
53 {
54 info("started module debug(%.200s)", st->arg);
55 }
56
57 int
get_debug(char * symon_buf,int maxlen,struct stream * st)58 get_debug(char *symon_buf, int maxlen, struct stream *st)
59 {
60 size_t len;
61 int i;
62
63 bzero((void *) db_v, sizeof(db_v));
64 len = sizeof(int);
65
66 for (i = 0; i < SYMON_MAXDEBUGID; i++) {
67 db_mib[1] = i;
68
69 sysctl(db_mib, sizeof(db_mib)/sizeof(int), &db_v[i], &len, NULL, 0);
70 }
71
72 return snpack(symon_buf, maxlen, st->arg, MT_DEBUG,
73 db_v[0], db_v[1], db_v[2], db_v[3], db_v[4], db_v[5], db_v[6],
74 db_v[7], db_v[8], db_v[9], db_v[10], db_v[11], db_v[12], db_v[13],
75 db_v[14], db_v[15], db_v[16], db_v[17], db_v[18], db_v[19]);
76
77 }
78