xref: /csrg-svn/lib/libc/sys/ktrace.2 (revision 61181)
1*61181Sbostic.\" Copyright (c) 1993
2*61181Sbostic.\"	The Regents of the University of California.  All rights reserved.
360937Smckusick.\"
460937Smckusick.\" %sccs.include.redist.man%
560937Smckusick.\"
6*61181Sbostic.\"     @(#)ktrace.2	8.1 (Berkeley) 06/04/93
760937Smckusick.\"
860937Smckusick.Dd
960937Smckusick.Dt KTRACE 2
1060937Smckusick.Os BSD 4
1160937Smckusick.Sh NAME
1260937Smckusick.Nm ktrace
1360937Smckusick.Nd process tracing
1460937Smckusick.Sh SYNOPSIS
1560937Smckusick.Fd #include <sys/types.h>
1660937Smckusick.Fd #include <sys/ktrace.h>
1760937Smckusick.Ft int
1860937Smckusick.Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid"
1960937Smckusick.Sh DESCRIPTION
2060937SmckusickThe
2160937Smckusick.Fn ktrace
2260937Smckusickfunction enables or disables tracing of one or more processes.
2360937SmckusickUsers may only trace their own processes.
2460937SmckusickOnly the super-user can trace setuid or setgid programs.
2560937Smckusick.Pp
2660937SmckusickThe
2760937Smckusick.Ar tracefile
2860937Smckusickgives the pathname of the file to be used for tracing.
2960937SmckusickThe file must exist and be writable by the calling process.
3060937SmckusickAll trace records are always appended to the file,
3160937Smckusickso the file must be truncated to zero length to discard
3260937Smckusickprevious trace data.
3360937SmckusickIf tracing points are being disabled (see KTROP_CLEAR below),
3460937Smckusick.Ar tracefile
3560937Smckusickmay be NULL.
3660937Smckusick.Pp
3760937SmckusickThe
3860937Smckusick.Nm ops
3960937Smckusickparameter specifies the requested ktrace operation.
4060937SmckusickThe defined operations are:
4160937Smckusick.Bl -column KTRFLAG_DESCENDXXX -offset indent
4260937Smckusick.It KTROP_SET	Enable trace points specified in Ar trpoints .
4360937Smckusick.It KTROP_CLEAR	Disable trace points specified in Ar trpoints .
4460937Smckusick.It KTROP_CLEARFILE	Stop all tracing.
4560937Smckusick.It KTRFLAG_DESCEND	The tracing change should apply to the
4660937Smckusickspecified process and all its current children.
4760937Smckusick.El
4860937Smckusick.Pp
4960937SmckusickThe
5060937Smckusick.Nm trpoints
5160937Smckusickparameter specifies the trace points of interest.
5260937SmckusickThe defined trace points are:
5360937Smckusick.Bl -column KTRFAC_SYSCALLXXX -offset indent
5460937Smckusick.It KTRFAC_SYSCALL	Trace system calls.
5560937Smckusick.It KTRFAC_SYSRET	Trace return values from system calls.
5660937Smckusick.It KTRFAC_NAMEI	Trace name lookup operations.
5760937Smckusick.It KTRFAC_GENIO	Trace all I/O (note that this option can
5860937Smckusickgenerate much output).
5960937Smckusick.It KTRFAC_PSIG	Trace posted signals.
6060937Smckusick.It KTRFAC_CSW	Trace context switch points.
6160937Smckusick.It KTRFAC_INHERIT	Inherit tracing to future children.
6260937Smckusick.El
6360937Smckusick.Pp
6460937SmckusickEach tracing event outputs a record composed of a generic header
6560937Smckusickfollowed by a trace point specific structure.
6660937SmckusickThe generic header is:
6760937Smckusick.Bd -literal
6860937Smckusickstruct ktr_header {
6960937Smckusick	int	ktr_len;		/* length of buf */
7060937Smckusick	short	ktr_type;		/* trace record type */
7160937Smckusick	pid_t	ktr_pid;		/* process id */
7260937Smckusick	char	ktr_comm[MAXCOMLEN+1];	/* command name */
7360937Smckusick	struct	timeval ktr_time;	/* timestamp */
7460937Smckusick	caddr_t	ktr_buf;
7560937Smckusick};
7660937Smckusick.Ed
7760937Smckusick.Pp
7860937SmckusickThe
7960937Smckusick.Nm ktr_len
8060937Smckusickfield specifies the length of the
8160937Smckusick.Nm ktr_type
8260937Smckusickdata that follows this header.
8360937SmckusickThe
8460937Smckusick.Nm ktr_pid
8560937Smckusickand
8660937Smckusick.Nm ktr_comm
8760937Smckusickfields specify the process and command generating the record.
8860937SmckusickThe
8960937Smckusick.Nm ktr_time
9060937Smckusickfield gives the time (with microsecond resolution)
9160937Smckusickthat the record was generated.
9260937SmckusickThe
9360937Smckusick.Nm ktr_buf
9460937Smckusickis an internal kernel pointer and is not useful.
9560937Smckusick.Pp
9660937SmckusickThe generic header is followed by
9760937Smckusick.Nm ktr_len
9860937Smckusickbytes of a
9960937Smckusick.Nm ktr_type
10060937Smckusickrecord.
10160937SmckusickThe type specific records are defined in the
10260937Smckusick.Pa <sys/ktrace.h>
10360937Smckusickinclude file.
10460937Smckusick.Sh RETURN VALUES
10560937SmckusickOn successful completion a value of 0 is returned.
10660937SmckusickOtherwise, a value of -1 is returned and
10760937Smckusick.Va errno
10860937Smckusickis set to show the error.
10960937Smckusick.Sh ERRORS
11060937Smckusick.Fn Ktrace
11160937Smckusickwill fail if:
11260937Smckusick.Bl -tag -width ENAMETOOLONGAA
11360937Smckusick.It Bq Er ENOTDIR
11460937SmckusickA component of the path prefix is not a directory.
11560937Smckusick.It Bq Er EINVAL
11660937SmckusickThe pathname contains a character with the high-order bit set.
11760937Smckusick.It Bq Er ENAMETOOLONG
11860937SmckusickA component of a pathname exceeded 255 characters,
11960937Smckusickor an entire path name exceeded 1023 characters.
12060937Smckusick.It Bq Er ENOENT
12160937SmckusickThe named tracefile does not exist.
12260937Smckusick.It Bq Er EACCES
12360937SmckusickSearch permission is denied for a component of the path prefix.
12460937Smckusick.It Bq Er ELOOP
12560937SmckusickToo many symbolic links were encountered in translating the pathname.
12660937Smckusick.It Bq Er EIO
12760937SmckusickAn I/O error occurred while reading from or writing to the file system.
12860937Smckusick.El
12960937Smckusick.Sh SEE ALSO
13060937Smckusick.Xr ktrace 1 ,
13160937Smckusick.Xr kdump 1
13260937Smckusick.Sh HISTORY
13360937SmckusickA
13460937Smckusick.Nm ktrace
13560937Smckusickfunction call first appeared in
13660937Smckusick.Bx 4.4 .
137