1 .\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
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.
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
30 .Nm CTR0 , CTR1 , CTR2 , CTR3 , CTR4 , CTR5
31 .Nd kernel tracing facility
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[]" ;
42 .Fn CTR0 "u_int mask" "char *format"
44 .Fn CTR1 "u_int mask" "char *format" "arg1"
46 .Fn CTR2 "u_int mask" "char *format" "arg1" "arg2"
48 .Fn CTR3 "u_int mask" "char *format" "arg1" "arg2" "arg3"
50 .Fn CTR4 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4"
52 .Fn CTR5 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5"
54 .Fn CTR6 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5" "arg6"
56 KTR provides a circular buffer of events that can be logged in a
60 These events can then be dumped with
66 Events are created and logged in the kernel via the
69 The first parameter is a mask of event types
73 The event will be logged only if any of the event types specified in
75 are enabled in the global event mask stored in
81 style format string used to build the text of the event log message.
84 string are zero to five arguments referenced by
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.
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.
94 Note that the different macros differ only in the number of arguments each
95 one takes, as indicated by its name.
99 variable contains the number of entries in the
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.
107 variable contains the run time mask of events to log.
109 The CPU event mask is stored in the
115 variable stores the verbose flag that controls whether events are logged to
116 the console in addition to the event buffer.
118 This example demonstrates the use of tracepoints at the
127 * Pick a new current process and record its start time.
130 CTR3(KTR_PROC, "mi_switch: old proc %p (pid %d)", p, p->p_pid);
134 CTR3(KTR_PROC, "mi_switch: new proc %p (pid %d)", p, p->p_pid);
142 The KTR kernel tracing facility first appeared in
144 and was imported into
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
153 The arguments given in
157 so do not pass arguments larger than size of an
160 For example passing 64bit arguments on 32bit architectures will give incorrect