2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2008-2022 NetApp, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #ifndef _SYS_BOOTTRACE_H_
28 #define _SYS_BOOTTRACE_H_
30 #define _BOOTTRACE_BOOTTRACE "kern.boottrace.boottrace"
31 #define _BOOTTRACE_RUNTRACE "kern.boottrace.runtrace"
32 #define _BOOTTRACE_SHUTTRACE "kern.boottrace.shuttrace"
34 /* Messages are formatted as 'tdname:name' */
35 #define BT_EVENT_TDNAMELEN 24
36 #define BT_EVENT_NAMELEN 40
37 #define BT_MSGLEN (BT_EVENT_NAMELEN + 1 + BT_EVENT_TDNAMELEN)
43 #include <sys/sysctl.h>
46 * Convenience macros. Userland API.
48 #define BOOTTRACE(...) _boottrace(_BOOTTRACE_BOOTTRACE, __VA_ARGS__)
49 #define RUNTRACE(...) _boottrace(_BOOTTRACE_RUNTRACE, __VA_ARGS__)
50 #define SHUTTRACE(...) _boottrace(_BOOTTRACE_SHUTTRACE, __VA_ARGS__)
53 * Call the requested boottrace sysctl with provided va-formatted message.
56 _boottrace(const char *sysctlname, const char *fmt, ...)
63 len = vsnprintf(msg, sizeof(msg), fmt, ap);
66 /* Log the event, even if truncated. */
68 (void)sysctlbyname(sysctlname, NULL, NULL, msg, strlen(msg));
74 * Convenience macros. Kernel API.
76 #define _BOOTTRACE(tdname, ...) do { \
77 if (boottrace_enabled) \
78 (void)boottrace(tdname, __VA_ARGS__); \
80 #define BOOTTRACE(...) _BOOTTRACE(NULL, __VA_ARGS__)
81 #define BOOTTRACE_INIT(...) _BOOTTRACE("kernel", __VA_ARGS__)
83 extern bool boottrace_enabled;
84 extern bool shutdown_trace;
86 int boottrace(const char *_tdname, const char *_eventfmt, ...)
88 void boottrace_reset(const char *_actor);
89 int boottrace_resize(u_int _newsize);
90 void boottrace_dump_console(void);
93 #endif /* _SYS_BOOTTRACE_H_ */