Merge branch 'vendor/AWK'
[dragonfly.git] / share / man / man9 / ktr.9
1 .\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD: src/share/man/man9/ktr.9,v 1.8 2005/03/08 01:37:36 hmp Exp $
26 .\"
27 .Dd July 16, 2011
28 .Dt KTR 9
29 .Os
30 .Sh NAME
31 .Nm KTR_INFO_MASTER ,
32 .Nm KTR_INFO_MASTER_EXTERN ,
33 .Nm KTR_INFO ,
34 .Nm KTR_LOG
35 .Nd kernel tracing facility
36 .Sh SYNOPSIS
37 .In sys/ktr.h
38 .Vt "extern int ktr_entries" ;
39 .Vt "extern int ktr_verbose" ;
40 .Vt "extern struct ktr_entry *ktr_buf[MAXCPU]" ;
41 .Fn KTR_INFO_MASTER "master"
42 .Fn KTR_INFO_MASTER_EXTERN "master"
43 .Fn KTR_INFO "compile" "master" "name" "maskbit" "format" "datasize"
44 .Fn KTR_LOG "info" "arg ..."
45 .Sh DESCRIPTION
46 The
47 .Nm ktr
48 facility provides a circular buffer of events that can be logged in a
49 .Xr kprintf 9
50 style fashion.
51 These events can then be dumped with
52 .Xr ddb 4 ,
53 .Xr gdb 1
54 or
55 .Xr ktrdump 8 .
56 .Pp
57 .Fn KTR_INFO_MASTER
58 declares a new master variable
59 .Dv ktr Ns _ Ns Fa master Ns _ Ns Dv enable
60 that is used to turn on and off event logging.
61 .Fn KTR_INFO_MASTER_EXTERN
62 is a convenience macro for declaring a master variable
63 .Sy extern .
64 .Pp
65 The
66 .Fn KTR_INFO
67 macro registers a new event
68 .Fa name
69 that will be controlled by the
70 .Fa master
71 enable variable.
72 Code for logging this event will be compiled in when
73 .Fa compile
74 is defined.
75 The
76 .Fa format
77 argument is a limited (i.e.\& only integral types, no formatting)
78 .Xr kprintf 9
79 style format string used to build the text of the event log message while
80 .Fa datasize
81 specifies the size of the data to be logged, either the total size of the
82 arguments required by the
83 .Fa format
84 string.
85 For logging a fixed string with
86 .Fn KTR_INFO ,
87 .Fa datasize
88 is 0.
89 The
90 .Fa maskbit
91 is a bit number that determines which of the corresponding
92 .Va debug.ktr.*_enable
93 sysctl's bits will enable logging of this event.
94 .Pp
95 Kernel events are logged via the
96 .Fn KTR_LOG
97 macro.
98 The
99 .Fa info
100 parameter is an identifier of the format
101 .Fa master Ns _ Ns Fa name .
102 .Fn KTR_LOG
103 accepts zero or more additional
104 .Fa arg
105 arguments as required by the
106 .Fa format
107 string passed to the associated
108 .Fn KTR_INFO
109 call.
110 .Pp
111 The
112 .Va ktr_entries
113 variable contains the number of entries in the
114 .Va ktr_buf
115 array.
116 These variables are mostly useful for post-mortem crash dump tools to locate
117 the base of the circular trace buffer and its length.
118 .Pp
119 The
120 .Va ktr_verbose
121 variable stores the verbose flag that controls whether events are logged to
122 the console in addition to the event buffer.
123 .Sh EXAMPLES
124 This example demonstrates a simple usage of the KTR facility:
125 .Pp
126 .Bd -literal -compact
127 #include <sys/ktr.h>
128
129 \&...
130
131 #if !defined(KTR_FOO)
132 #define KTR_FOO         KTR_ALL
133 #endif
134 KTR_INFO_MASTER(foo);
135 KTR_INFO(KTR_FOO, foo, func1, 0, "func1()", 0);
136 KTR_INFO(KTR_FOO, foo, func2, 1, "func2(%d)", sizeof(int));
137
138 \&...
139
140 void
141 func1(void)
142 {
143         KTR_LOG(foo_func1);
144         ...
145 }
146
147 void
148 func2(int arg)
149 {
150         KTR_LOG(foo_func2, arg);
151         ...
152 }
153 .Ed
154 .Sh SEE ALSO
155 .Xr gdb 1 ,
156 .Xr ddb 4 ,
157 .Xr ktr 4 ,
158 .Xr ktrdump 8 ,
159 .Xr kprintf 9
160 .Sh HISTORY
161 The
162 .Nm ktr
163 kernel tracing facility first appeared in
164 .Bsx 3.0
165 and was imported into
166 .Fx 5.0
167 and
168 .Dx 1.1 .
169 It was completely rewritten by Matthew Dillon in
170 .Dx 1.3 .