xref: /freebsd/share/man/man9/ktr.9 (revision d6071d2f5f2f599bc09525b83d2c26eea6872171)
1a1382e7fSJohn Baldwin.\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
2a1382e7fSJohn Baldwin.\" All rights reserved.
3a1382e7fSJohn Baldwin.\"
4a1382e7fSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without
5a1382e7fSJohn Baldwin.\" modification, are permitted provided that the following conditions
6a1382e7fSJohn Baldwin.\" are met:
7a1382e7fSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright
8a1382e7fSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer.
9a1382e7fSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright
10a1382e7fSJohn Baldwin.\"    notice, this list of conditions and the following disclaimer in the
11a1382e7fSJohn Baldwin.\"    documentation and/or other materials provided with the distribution.
12a1382e7fSJohn Baldwin.\"
13a1382e7fSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14a1382e7fSJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15a1382e7fSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16a1382e7fSJohn Baldwin.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17a1382e7fSJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18a1382e7fSJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19a1382e7fSJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20a1382e7fSJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21a1382e7fSJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22a1382e7fSJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23a1382e7fSJohn Baldwin.\" SUCH DAMAGE.
24a1382e7fSJohn Baldwin.\"
25a1382e7fSJohn Baldwin.\" $FreeBSD$
26a1382e7fSJohn Baldwin.\"
27a1382e7fSJohn Baldwin.Dd February 15, 2001
28a1382e7fSJohn Baldwin.Dt KTR 9
29a1382e7fSJohn Baldwin.Os
30a1382e7fSJohn Baldwin.Sh NAME
3183c93009SRuslan Ermilov.Nm CTR0 , CTR1 , CTR2 , CTR3 , CTR4 , CTR5
32a1382e7fSJohn Baldwin.Nd kernel tracing facility
33a1382e7fSJohn Baldwin.Sh SYNOPSIS
34f16b3c0dSChad David.In sys/param.h
3583c93009SRuslan Ermilov.In sys/ktr.h
36a1382e7fSJohn Baldwin.Vt "extern int ktr_cpumask" ;
37a1382e7fSJohn Baldwin.Vt "extern int ktr_entries" ;
38a1382e7fSJohn Baldwin.Vt "extern int ktr_extend" ;
39a1382e7fSJohn Baldwin.Vt "extern int ktr_mask" ;
40a1382e7fSJohn Baldwin.Vt "extern int ktr_verbose" ;
41a1382e7fSJohn Baldwin.Vt "extern struct ktr_entry ktr_buf[]" ;
42a1382e7fSJohn Baldwin.Ft void
43a1382e7fSJohn Baldwin.Fn CTR0 "u_int mask" "char *format"
44a1382e7fSJohn Baldwin.Ft void
45a1382e7fSJohn Baldwin.Fn CTR1 "u_int mask" "char *format" "arg1"
46a1382e7fSJohn Baldwin.Ft void
47a1382e7fSJohn Baldwin.Fn CTR2 "u_int mask" "char *format" "arg1" "arg2"
48a1382e7fSJohn Baldwin.Ft void
49a1382e7fSJohn Baldwin.Fn CTR3 "u_int mask" "char *format" "arg1" "arg2" "arg3"
50a1382e7fSJohn Baldwin.Ft void
51a1382e7fSJohn Baldwin.Fn CTR4 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4"
52a1382e7fSJohn Baldwin.Ft void
53a1382e7fSJohn Baldwin.Fn CTR5 "u_int mask" "char *format" "arg1" "arg2" "arg3" "arg4" "arg5"
54a1382e7fSJohn Baldwin.Sh DESCRIPTION
5583c93009SRuslan ErmilovKTR provides a circular buffer of events that can be logged in a
5683c93009SRuslan Ermilov.Xr printf 9
5783c93009SRuslan Ermilovstyle
58a1382e7fSJohn Baldwinfashion.
59a1382e7fSJohn BaldwinThese events can then be dumped either via
60a1382e7fSJohn Baldwin.Xr ddb 4
61a1382e7fSJohn Baldwinor
62a1382e7fSJohn Baldwin.Xr gdb 1 .
63a1382e7fSJohn Baldwin.Pp
64a1382e7fSJohn BaldwinEvents are created and logged in the kernel via the
65d6071d2fSRuslan Ermilov.Dv CTR Ns Ar x
66a1382e7fSJohn Baldwinmacros.
67a1382e7fSJohn BaldwinThe first parameter is a mask of event types
68a1382e7fSJohn Baldwin.Pq Dv KTR_*
69a1382e7fSJohn Baldwindefined in
70a1382e7fSJohn Baldwin.Aq Pa sys/ktr.h .
71a1382e7fSJohn BaldwinThe event will be logged only if any of the event types specified in
72a1382e7fSJohn Baldwin.Fa mask
73a1382e7fSJohn Baldwinare enabled in the global event mask stored in
74a1382e7fSJohn Baldwin.Va ktr_mask .
75a1382e7fSJohn BaldwinThe
76a1382e7fSJohn Baldwin.Fa format
77a1382e7fSJohn Baldwinargument is a
78a1382e7fSJohn Baldwin.Xr printf 9
79a1382e7fSJohn Baldwinstyle format string used to build the text of the event log message.
80a1382e7fSJohn BaldwinFollowing the
81a1382e7fSJohn Baldwin.Fa format
82a1382e7fSJohn Baldwinstring are zero to five arguments referenced by
83a1382e7fSJohn Baldwin.Fa format .
84a1382e7fSJohn BaldwinNote that the different macros differ only in the number of arguments each
85a1382e7fSJohn Baldwinone takes, as indicated by its name.
86a1382e7fSJohn BaldwinEach event is logged with a timestamp in addition to the log message.
87a1382e7fSJohn Baldwin.Pp
88a1382e7fSJohn BaldwinThe
89a1382e7fSJohn Baldwin.Va ktr_entries
90a1382e7fSJohn Baldwinvariable contains the number of entries in the
91a1382e7fSJohn Baldwin.Va ktr_buf
92a1382e7fSJohn Baldwinarray.
93a1382e7fSJohn BaldwinThese variables are mostly useful for post-mortem crash dump tools to locate
94a1382e7fSJohn Baldwinthe base of the circular trace buffer and its length.
95a1382e7fSJohn Baldwin.Pp
96a1382e7fSJohn BaldwinThe
97a1382e7fSJohn Baldwin.Va ktr_mask
98a1382e7fSJohn Baldwinvariable contains the run time mask of events to log.
99a1382e7fSJohn Baldwin.Pp
100a1382e7fSJohn BaldwinThe CPU event mask is stored in the
101a1382e7fSJohn Baldwin.Va ktr_cpumask
102a1382e7fSJohn Baldwinvariable.
103a1382e7fSJohn Baldwin.Pp
104a1382e7fSJohn BaldwinThe
105a1382e7fSJohn Baldwin.Va ktr_verbose
106a1382e7fSJohn Baldwinvariable stores the verbose flag that controls whether events are logged to
107a1382e7fSJohn Baldwinthe console in addition to the event buffer.
108a1382e7fSJohn Baldwin.Sh EXAMPLES
109a1382e7fSJohn BaldwinThis example demonstrates the use of tracepoints at the
110a1382e7fSJohn Baldwin.Dv KTR_PROC
111a1382e7fSJohn Baldwinlogging level.
112a1382e7fSJohn Baldwin.Bd -literal -offset indent
113a1382e7fSJohn Baldwinvoid
114a1382e7fSJohn Baldwinmi_switch()
115a1382e7fSJohn Baldwin{
116a1382e7fSJohn Baldwin	...
117a1382e7fSJohn Baldwin	/*
118a1382e7fSJohn Baldwin	 * Pick a new current process and record its start time.
119a1382e7fSJohn Baldwin	 */
120a1382e7fSJohn Baldwin	...
121a1382e7fSJohn Baldwin	CTR3(KTR_PROC, "mi_switch: old proc %p (pid %d, %s)", p, p->p_pid,
122a1382e7fSJohn Baldwin	    p->p_comm);
123a1382e7fSJohn Baldwin	...
124a1382e7fSJohn Baldwin	cpu_switch();
125a1382e7fSJohn Baldwin	...
126a1382e7fSJohn Baldwin	CTR3(KTR_PROC, "mi_switch: new proc %p (pid %d, %s)", p, p->p_pid,
127a1382e7fSJohn Baldwin	    p->p_comm);
128a1382e7fSJohn Baldwin	...
129a1382e7fSJohn Baldwin}
130a1382e7fSJohn Baldwin.Ed
131a1382e7fSJohn Baldwin.Sh SEE ALSO
132d627754aSJeff Roberson.Xr ktr 4 ,
133d627754aSJeff Roberson.Xr ktrdump 8
134a1382e7fSJohn Baldwin.Sh HISTORY
135a1382e7fSJohn BaldwinThe KTR kernel tracing facility first appeared in
136a1382e7fSJohn Baldwin.Bsx 3.0
137a1382e7fSJohn Baldwinand was imported into
138a1382e7fSJohn Baldwin.Fx 5.0 .
139a1382e7fSJohn Baldwin.Sh BUGS
140a1382e7fSJohn BaldwinCurrently there is one global buffer shared among all CPUs.
141a1382e7fSJohn BaldwinIt might be profitable at some point in time to use per-CPU buffers instead
142a1382e7fSJohn Baldwinso that if one CPU halts or starts spinning, then the log messages it
143a1382e7fSJohn Baldwinemitted just prior to halting or spinning will not be drowned out by events
144a1382e7fSJohn Baldwinfrom the other CPUs.
145