1.\" Copyright (c) 1990, 1993 2.\" The Regents of the University of California. 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.\" 3. All advertising materials mentioning features or use of this software 13.\" must display the following acknowledgement: 14.\" This product includes software developed by the University of 15.\" California, Berkeley and its contributors. 16.\" 4. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" @(#)ktrace.1 8.1 (Berkeley) 6/6/93 33.\" $FreeBSD$ 34.\" 35.Dd June 6, 1993 36.Dt KTRACE 1 37.Os BSD 4.4 38.Sh NAME 39.Nm ktrace 40.Nd enable kernel process tracing 41.Sh SYNOPSIS 42.Nm ktrace 43.Op Fl aCcdi 44.Op Fl f Ar trfile 45.Op Fl g Ar pgrp 46.Op Fl p Ar pid 47.Op Fl t Ar trstr 48.Nm ktrace 49.Op Fl adi 50.Op Fl f Ar trfile 51.Op Fl t Ar trstr 52command 53.Sh DESCRIPTION 54The 55.Nm 56command enables kernel trace logging for the specified processes. 57Kernel trace data is logged to the file 58.Pa ktrace.out . 59The kernel operations that are traced include system calls, namei 60translations, signal processing, and 61.Tn I/O . 62.Pp 63Once tracing is enabled on a process, trace data will be logged until 64either the process exits or the trace point is cleared. 65A traced process can generate enormous amounts of log data quickly; 66It is strongly suggested that users memorize how to disable tracing before 67attempting to trace a process. 68The following command is sufficient to disable tracing on all user owned 69processes, and, if executed by root, all processes: 70.Pp 71.Dl \&$ ktrace -C 72.Pp 73The trace file is not human readable; use 74.Xr kdump 1 75to decode it. 76.Pp 77The options are as follows: 78.Bl -tag -width indent 79.It Fl a 80Append to the trace file instead of recreating it. 81.It Fl C 82Disable tracing on all user owned processes, and, if executed by root, all 83processes in the system. 84.It Fl c 85Clear the trace points associated with the specified file or processes. 86.It Fl d 87Descendants; perform the operation for all current children of the 88designated processes. 89.It Fl f Ar file 90Log trace records to 91.Ar file 92instead of 93.Pa ktrace.out . 94.It Fl g Ar pgid 95Enable (disable) tracing on all processes in the process group (only one 96.Fl g 97flag is permitted). 98.It Fl i 99Inherit; pass the trace flags to all future children of the designated 100processes. 101.It Fl p Ar pid 102Enable (disable) tracing on the indicated process id (only one 103.Fl p 104flag is permitted). 105.It Fl t Ar trstr 106The string argument represents the kernel trace points, one per letter. 107The following table equates the letters with the tracepoints: 108.Pp 109.Bl -tag -width flag -compact 110.It Cm c 111trace system calls 112.It Cm n 113trace namei translations 114.It Cm i 115trace 116.Tn I/O 117.It Cm s 118trace signal processing 119.It Cm u 120userland traces 121.It Cm w 122context switches 123.El 124.It Ar command 125Execute 126.Ar command 127with the specified trace flags. 128.El 129.Pp 130The 131.Fl p , 132.Fl g , 133and 134.Ar command 135options are mutually exclusive. 136.Sh EXAMPLES 137# trace all kernel operations of process id 34 138.Dl $ ktrace -p 34 139.Pp 140# trace all kernel operations of processes in process group 15 and 141# pass the trace flags to all current and future children 142.Dl $ ktrace -idg 15 143.Pp 144# disable all tracing of process 65 145.Dl $ ktrace -cp 65 146.Pp 147# disable tracing signals on process 70 and all current children 148.Dl $ ktrace -t s -cdp 70 149.Pp 150# enable tracing of 151.Tn I/O 152on process 67 153.Dl $ ktrace -ti -p 67 154.Pp 155# run the command "w", tracing only system calls 156.Dl $ ktrace -tc w 157.Pp 158# disable all tracing to the file "tracedata" 159.Dl $ ktrace -c -f tracedata 160.Pp 161# disable tracing of all processes owned by the user 162.Dl $ ktrace -C 163.Sh SEE ALSO 164.Xr kdump 1 165.Sh BUGS 166Only works if 167.Ar file 168is a regular file. 169.Sh HISTORY 170The 171.Nm 172command appeared in 173.Bx 4.4 . 174