]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man9/ktr.9
accept_filter(9): Fix a mandoc related error
[FreeBSD/FreeBSD.git] / share / man / man9 / ktr.9
1 .\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 .\" SUCH DAMAGE.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd November 30, 2008
27 .Dt KTR 9
28 .Os
29 .Sh NAME
30 .Nm CTR0 , CTR1 , CTR2 , CTR3 , CTR4 , CTR5
31 .Nd kernel tracing facility
32 .Sh SYNOPSIS
33 .In sys/param.h
34 .In sys/ktr.h
35 .Vt "extern int ktr_cpumask" ;
36 .Vt "extern int ktr_entries" ;
37 .Vt "extern int ktr_extend" ;
38 .Vt "extern int ktr_mask" ;
39 .Vt "extern int ktr_verbose" ;
40 .Vt "extern struct ktr_entry ktr_buf[]" ;
41 .Ft void
42 .Fn CTR0 "u_int mask" "char *format"
43 .Ft void
44 .Fn CTR1 "u_int mask" "char *format" "arg1"
45 .Ft void
46 .Fn CTR2 "u_int mask" "char *format" "arg1" "arg2"
47 .Ft void
48 .Fn CTR3 "u_int mask" "char *format" "arg1" "arg2" "arg3"
49 .Ft void
50 .Fn CTR4 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4"
51 .Ft void
52 .Fn CTR5 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5"
53 .Ft void
54 .Fn CTR6 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5" "arg6"
55 .Sh DESCRIPTION
56 KTR provides a circular buffer of events that can be logged in a
57 .Xr printf 9
58 style
59 fashion.
60 These events can then be dumped with
61 .Xr ddb 4 ,
62 .Xr gdb 1
63 or
64 .Xr ktrdump 8 .
65 .Pp
66 Events are created and logged in the kernel via the
67 .Dv CTR Ns Ar x
68 macros.
69 The first parameter is a mask of event types
70 .Pq Dv KTR_*
71 defined in
72 .In sys/ktr.h .
73 The event will be logged only if any of the event types specified in
74 .Fa mask
75 are enabled in the global event mask stored in
76 .Va ktr_mask .
77 The
78 .Fa format
79 argument is a
80 .Xr printf 9
81 style format string used to build the text of the event log message.
82 Following the
83 .Fa format
84 string are zero to five arguments referenced by
85 .Fa format .
86 Each event is logged with a file name and source line number of the
87 originating CTR call, and a timestamp in addition to the log message.
88 .Pp
89 The event is stored in the circular buffer with supplied arguments as is,
90 and formatting is done at the dump time.
91 Do not use pointers to the objects with limited lifetime, for instance,
92 strings, because the pointer may become invalid when buffer is printed.
93 .Pp
94 Note that the different macros differ only in the number of arguments each
95 one takes, as indicated by its name.
96 .Pp
97 The
98 .Va ktr_entries
99 variable contains the number of entries in the
100 .Va ktr_buf
101 array.
102 These variables are mostly useful for post-mortem crash dump tools to locate
103 the base of the circular trace buffer and its length.
104 .Pp
105 The
106 .Va ktr_mask
107 variable contains the run time mask of events to log.
108 .Pp
109 The CPU event mask is stored in the
110 .Va ktr_cpumask
111 variable.
112 .Pp
113 The
114 .Va ktr_verbose
115 variable stores the verbose flag that controls whether events are logged to
116 the console in addition to the event buffer.
117 .Sh EXAMPLES
118 This example demonstrates the use of tracepoints at the
119 .Dv KTR_PROC
120 logging level.
121 .Bd -literal
122 void
123 mi_switch()
124 {
125         ...
126         /*
127          * Pick a new current process and record its start time.
128          */
129         ...
130         CTR3(KTR_PROC, "mi_switch: old proc %p (pid %d)", p, p->p_pid);
131         ...
132         cpu_switch();
133         ...
134         CTR3(KTR_PROC, "mi_switch: new proc %p (pid %d)", p, p->p_pid);
135         ...
136 }
137 .Ed
138 .Sh SEE ALSO
139 .Xr ktr 4 ,
140 .Xr ktrdump 8
141 .Sh HISTORY
142 The KTR kernel tracing facility first appeared in
143 .Bsx 3.0
144 and was imported into
145 .Fx 5.0 .
146 .Sh BUGS
147 Currently there is one global buffer shared among all CPUs.
148 It might be profitable at some point in time to use per-CPU buffers instead
149 so that if one CPU halts or starts spinning, then the log messages it
150 emitted just prior to halting or spinning will not be drowned out by events
151 from the other CPUs.
152 .Pp
153 The arguments given in
154 .Fn CTRx
155 macros are stored as
156 .Vt u_long ,
157 so do not pass arguments larger than size of an
158 .Vt u_long
159 type.
160 For example passing 64bit arguments on 32bit architectures will give incorrect
161 results.