Implement nearly all the remaining items required to allow the virtual kernel
[dragonfly.git] / share / man / man9 / ktr.9
CommitLineData
81540c2d
EN
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.\"
1bf4b486 25.\" $FreeBSD: src/share/man/man9/ktr.9,v 1.8 2005/03/08 01:37:36 hmp Exp $
44cb301e 26.\" $DragonFly: src/share/man/man9/ktr.9,v 1.8 2006/05/26 19:39:40 swildner Exp $
81540c2d
EN
27.\"
28.Dd February 15, 2001
29.Dt KTR 9
30.Os
31.Sh NAME
d0de9052
SW
32.Nm CTR0 ,
33.Nm CTR1 ,
34.Nm CTR2 ,
35.Nm CTR3 ,
36.Nm CTR4 ,
37.Nm CTR5 ,
38.Nm CTR6
81540c2d
EN
39.Nd kernel tracing facility
40.Sh SYNOPSIS
41.In sys/param.h
42.In sys/ktr.h
43.Vt "extern int ktr_cpumask" ;
44.Vt "extern int ktr_entries" ;
45.Vt "extern int ktr_extend" ;
46.Vt "extern int ktr_mask" ;
47.Vt "extern int ktr_verbose" ;
48.Vt "extern struct ktr_entry ktr_buf[]" ;
49.Ft void
50.Fn CTR0 "u_int mask" "char *format"
51.Ft void
52.Fn CTR1 "u_int mask" "char *format" "arg1"
53.Ft void
54.Fn CTR2 "u_int mask" "char *format" "arg1" "arg2"
55.Ft void
56.Fn CTR3 "u_int mask" "char *format" "arg1" "arg2" "arg3"
57.Ft void
58.Fn CTR4 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4"
59.Ft void
60.Fn CTR5 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5"
61.Ft void
62.Fn CTR6 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5" "arg6"
63.Sh DESCRIPTION
64KTR provides a circular buffer of events that can be logged in a
65.Xr printf 9
66style
67fashion.
cdbdd4f6
HP
68These events can then be dumped with
69.Xr ddb 4 ,
70.Xr gdb 1
81540c2d 71or
cdbdd4f6 72.Xr ktrdump 8 .
81540c2d
EN
73.Pp
74Events are created and logged in the kernel via the
75.Dv CTR Ns Ar x
76macros.
77The first parameter is a mask of event types
78.Pq Dv KTR_*
79defined in
44cb301e 80.In sys/ktr.h .
81540c2d
EN
81The event will be logged only if any of the event types specified in
82.Fa mask
83are enabled in the global event mask stored in
84.Va ktr_mask .
85The
86.Fa format
87argument is a
88.Xr printf 9
89style format string used to build the text of the event log message.
90Following the
91.Fa format
92string are zero to five arguments referenced by
93.Fa format .
94Note that the different macros differ only in the number of arguments each
95one takes, as indicated by its name.
96Each event is logged with a timestamp in addition to the log message.
97.Pp
98The
99.Va ktr_entries
100variable contains the number of entries in the
101.Va ktr_buf
102array.
103These variables are mostly useful for post-mortem crash dump tools to locate
104the base of the circular trace buffer and its length.
105.Pp
106The
107.Va ktr_mask
108variable contains the run time mask of events to log.
109.Pp
110The CPU event mask is stored in the
111.Va ktr_cpumask
112variable.
113.Pp
114The
115.Va ktr_verbose
116variable stores the verbose flag that controls whether events are logged to
117the console in addition to the event buffer.
118.Sh EXAMPLES
119This example demonstrates the use of tracepoints at the
120.Dv KTR_PROC
121logging level.
bd02a712 122.Bd -literal -compact
81540c2d
EN
123void
124mi_switch()
125{
126 ...
127 /*
128 * Pick a new current process and record its start time.
129 */
130 ...
131 CTR3(KTR_PROC, "mi_switch: old proc %p (pid %d, %s)", p, p->p_pid,
132 p->p_comm);
133 ...
134 cpu_switch();
135 ...
136 CTR3(KTR_PROC, "mi_switch: new proc %p (pid %d, %s)", p, p->p_pid,
137 p->p_comm);
138 ...
139}
140.Ed
141.Sh SEE ALSO
142.Xr ktr 4
143.Sh HISTORY
144The KTR kernel tracing facility first appeared in
145.Bsx 3.0
146and was imported into
147.Fx 5.0
148and
149.Dx 1.1 .