]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libc/sys/ktrace.2
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libc / sys / ktrace.2
1 .\" Copyright (c) 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 .\" 4. Neither the name of the University nor the names of its contributors
13 .\"    may be used to endorse or promote products derived from this software
14 .\"    without specific prior written permission.
15 .\"
16 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 .\" SUCH DAMAGE.
27 .\"
28 .\"     @(#)ktrace.2    8.1 (Berkeley) 6/4/93
29 .\" $FreeBSD$
30 .\"
31 .Dd July 13, 2008
32 .Dt KTRACE 2
33 .Os
34 .Sh NAME
35 .Nm ktrace
36 .Nd process tracing
37 .Sh LIBRARY
38 .Lb libc
39 .Sh SYNOPSIS
40 .In sys/param.h
41 .In sys/time.h
42 .In sys/uio.h
43 .In sys/ktrace.h
44 .Ft int
45 .Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
46 .Sh DESCRIPTION
47 The
48 .Fn ktrace
49 system call enables or disables tracing of one or more processes.
50 Users may only trace their own processes.
51 Only the super-user can trace setuid or setgid programs.
52 .Pp
53 The
54 .Fa tracefile
55 argument
56 gives the pathname of the file to be used for tracing.
57 The file must exist and be a regular file writable by the calling process.
58 All trace records are always appended to the file,
59 so the file must be truncated to zero length to discard
60 previous trace data.
61 If tracing points are being disabled (see KTROP_CLEAR below),
62 .Fa tracefile
63 may be NULL.
64 .Pp
65 The
66 .Fa ops
67 argument specifies the requested ktrace operation.
68 The defined operations are:
69 .Bl -column KTRFLAG_DESCENDXXX -offset indent
70 .It "KTROP_SET  Enable trace points specified in"
71 .Fa trpoints .
72 .It "KTROP_CLEAR        Disable trace points specified in
73 .Fa trpoints .
74 .It "KTROP_CLEARFILE    Stop all tracing."
75 .It "KTRFLAG_DESCEND    The tracing change should apply to the"
76 specified process and all its current children.
77 .El
78 .Pp
79 The
80 .Fa trpoints
81 argument specifies the trace points of interest.
82 The defined trace points are:
83 .Bl -column KTRFAC_SYSCALLXXX -offset indent
84 .It "KTRFAC_SYSCALL     Trace system calls."
85 .It "KTRFAC_SYSRET      Trace return values from system calls."
86 .It "KTRFAC_NAMEI       Trace name lookup operations."
87 .It "KTRFAC_GENIO       Trace all I/O (note that this option can"
88 generate much output).
89 .It "KTRFAC_PSIG        Trace posted signals."
90 .It "KTRFAC_CSW Trace context switch points."
91 .It "KTRFAC_INHERIT     Inherit tracing to future children."
92 .El
93 .Pp
94 Each tracing event outputs a record composed of a generic header
95 followed by a trace point specific structure.
96 The generic header is:
97 .Bd -literal
98 struct ktr_header {
99         int     ktr_len;                /* length of buf */
100         short   ktr_type;               /* trace record type */
101         pid_t   ktr_pid;                /* process id */
102         char    ktr_comm[MAXCOMLEN+1];  /* command name */
103         struct  timeval ktr_time;       /* timestamp */
104         intptr_t        ktr_tid;        /* was ktr_buffer */
105 };
106 .Ed
107 .Pp
108 The
109 .Va ktr_len
110 field specifies the length of the
111 .Va ktr_type
112 data that follows this header.
113 The
114 .Va ktr_pid
115 and
116 .Va ktr_comm
117 fields specify the process and command generating the record.
118 The
119 .Va ktr_time
120 field gives the time (with microsecond resolution)
121 that the record was generated.
122 The
123 .Va ktr_tid
124 field holds a threadid.
125 .Pp
126 The generic header is followed by
127 .Va ktr_len
128 bytes of a
129 .Va ktr_type
130 record.
131 The type specific records are defined in the
132 .In sys/ktrace.h
133 include file.
134 .Sh SYSCTL TUNABLES
135 The following
136 .Xr sysctl 8
137 tunables influence the behaviour of
138 .Fn ktrace :
139 .Bl -tag -width indent
140 .It Va kern.ktrace.geniosize
141 bounds the amount of data a traced I/O request will log
142 to the trace file.
143 .It Va kern.ktrace.request_pool
144 bounds the number of trace events being logged at a time.
145 .El
146 .Pp
147 Sysctl tunables that control process debuggability (as determined by
148 .Xr p_candebug 9 )
149 also affect the operation of
150 .Fn ktrace .
151 .Sh RETURN VALUES
152 .Rv -std ktrace
153 .Sh ERRORS
154 The
155 .Fn ktrace
156 system call
157 will fail if:
158 .Bl -tag -width Er
159 .It Bq Er ENOTDIR
160 A component of the path prefix is not a directory.
161 .It Bq Er ENAMETOOLONG
162 A component of a pathname exceeded 255 characters,
163 or an entire path name exceeded 1023 characters.
164 .It Bq Er ENOENT
165 The named tracefile does not exist.
166 .It Bq Er EACCES
167 Search permission is denied for a component of the path prefix.
168 .It Bq Er ELOOP
169 Too many symbolic links were encountered in translating the pathname.
170 .It Bq Er EIO
171 An I/O error occurred while reading from or writing to the file system.
172 .It Bq Er ENOSYS
173 The kernel was not compiled with
174 .Nm
175 support.
176 .El
177 .Pp
178 A thread may be unable to log one or more tracing events due to a
179 temporary shortage of resources.
180 This condition is remembered by the kernel, and the next tracing request
181 that succeeds will have the flag
182 .Li KTR_DROP
183 set in its
184 .Va ktr_type
185 field.
186 .Sh SEE ALSO
187 .Xr kdump 1 ,
188 .Xr ktrace 1 ,
189 .Xr utrace 2 ,
190 .Xr sysctl 8 ,
191 .Xr p_candebug 9
192 .Sh HISTORY
193 The
194 .Fn ktrace
195 system call first appeared in
196 .Bx 4.4 .