subr_syscall_stats.c revision 1.1.6.2 1 /* $NetBSD: subr_syscall_stats.c,v 1.1.6.2 2007/02/27 16:54:29 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by David Laight.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The NetBSD Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __RCSID("$NetBSD: subr_syscall_stats.c,v 1.1.6.2 2007/02/27 16:54:29 yamt Exp $");
37
38 #include "opt_syscall_stats.h"
39
40 #include <sys/param.h>
41 #include <sys/syscall.h>
42 #include <sys/sysctl.h>
43
44 #include <sys/syscall_stats.h>
45
46 #ifdef SYSCALL_STATS
47 uint64_t syscall_counts[SYS_NSYSENT];
48 uint64_t syscall_count_user, syscall_count_system, syscall_count_interrupt;
49
50 #ifdef SYSCALL_TIMES
51 uint64_t syscall_times[SYS_NSYSENT];
52 #endif
53
54 SYSCTL_SETUP(sysctl_syscall_setup, "sysctl system call stats")
55 {
56 const struct sysctlnode *cnode;
57 int kern_syscalls;
58
59 sysctl_createv(clog, 0, NULL, NULL,
60 CTLFLAG_PERMANENT,
61 CTLTYPE_NODE, "kern", NULL,
62 NULL, 0, NULL, 0,
63 CTL_KERN, CTL_EOL);
64 sysctl_createv(clog, 0, NULL, &cnode,
65 CTLFLAG_PERMANENT,
66 CTLTYPE_NODE, "syscalls",
67 SYSCTL_DESCR("per syscall statistics"),
68 NULL, 0, NULL, 0,
69 CTL_KERN, CTL_CREATE);
70 kern_syscalls = cnode->sysctl_num;
71 sysctl_createv(clog, 0, NULL, NULL,
72 CTLFLAG_PERMANENT,
73 CTLTYPE_STRUCT, "counts",
74 SYSCTL_DESCR("per syscall counts"),
75 NULL, 0, syscall_counts, sizeof syscall_counts,
76 CTL_KERN, kern_syscalls, CTL_CREATE);
77 #ifdef SYSCALL_TIMES
78 sysctl_createv(clog, 0, NULL, NULL,
79 CTLFLAG_PERMANENT,
80 CTLTYPE_STRUCT, "times",
81 SYSCTL_DESCR("per syscall times"),
82 NULL, 0, syscall_times, sizeof syscall_times,
83 CTL_KERN, kern_syscalls, CTL_CREATE);
84 #endif
85 }
86 #endif
87