Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

trace(1) [freebsd man page]

KTRACE(1)						    BSD General Commands Manual 						 KTRACE(1)

ktrace -- enable kernel process tracing SYNOPSIS
ktrace [-aCcdi] [-f trfile] [-g pgrp | -p pid] [-t trstr] ktrace [-adi] [-f trfile] [-t trstr] command DESCRIPTION
The ktrace utility enables kernel trace logging for the specified processes. Kernel trace data is logged to the file ktrace.out. The kernel operations that are traced include system calls, namei translations, signal processing, and I/O. Once tracing is enabled on a process, trace data will be logged until either the process exits or the trace point is cleared. A traced process can generate enormous amounts of log data quickly; It is strongly suggested that users memorize how to disable tracing before attempting to trace a process. The following command is sufficient to disable tracing on all user-owned processes, and, if executed by root, all processes: $ ktrace -C The trace file is not human readable; use kdump(1) to decode it. The utility may be used only with a kernel that has been built with the ``KTRACE'' option in the kernel configuration file. The options are: -a Append to the trace file instead of recreating it. -C Disable tracing on all user-owned processes, and, if executed by root, all processes in the system. -c Clear the specified trace points associated with the given file or processes. -d Descendants; perform the operation for all current children of the designated processes. -f trfile Log trace records to trfile instead of ktrace.out. -g pgid Enable (disable) tracing on all processes in the process group (only one -g flag is permitted). -i Inherit; pass the trace flags to all future children of the designated processes. -p pid Enable (disable) tracing on the indicated process id (only one -p flag is permitted). -t trstr Specify the list of trace points to enable or disable, one per letter. If an explicit list is not specified, the default set of trace points is used. The following trace points are supported: c trace system calls f trace page faults i trace I/O n trace namei translations p trace capability check failures s trace signal processing t trace various structures u userland traces w context switches y trace sysctl(3) requests + trace the default set of trace points - c, i, n, p, s, t, u, y command Execute command with the specified trace flags. The -p, -g, and command options are mutually exclusive. EXAMPLES
# trace all kernel operations of process id 34 $ ktrace -p 34 # trace all kernel operations of processes in process group 15 and # pass the trace flags to all current and future children $ ktrace -idg 15 # disable all tracing of process 65 $ ktrace -cp 65 # disable tracing signals on process 70 and all current children $ ktrace -t s -cdp 70 # enable tracing of I/O on process 67 $ ktrace -ti -p 67 # run the command "w", tracing only system calls $ ktrace -tc w # disable all tracing to the file "tracedata" $ ktrace -c -f tracedata # disable tracing of all user-owned processes $ ktrace -C SEE ALSO
kdump(1) HISTORY
The ktrace command appeared in 4.4BSD. BUGS
Only works if trfile is a regular file. BSD
August 26, 2014 BSD

Check Out this Related Man Page

KTRACE(2)						      BSD System Calls Manual							 KTRACE(2)

ktrace -- process tracing LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/param.h> #include <sys/time.h> #include <sys/uio.h> #include <sys/ktrace.h> int ktrace(const char *tracefile, int ops, int trpoints, int pid); DESCRIPTION
The ktrace() system call enables or disables tracing of one or more processes. Users may only trace their own processes. Only the super- user can trace setuid or setgid programs. The tracefile argument gives the pathname of the file to be used for tracing. The file must exist and be a regular file writable by the calling process. All trace records are always appended to the file, so the file must be truncated to zero length to discard previous trace data. If tracing points are being disabled (see KTROP_CLEAR below), tracefile may be NULL. The ops argument specifies the requested ktrace operation. The defined operations are: KTROP_SET Enable trace points specified in trpoints. KTROP_CLEAR Disable trace points specified in trpoints. KTROP_CLEARFILE Stop all tracing. KTRFLAG_DESCEND The tracing change should apply to the specified process and all its current children. The trpoints argument specifies the trace points of interest. The defined trace points are: KTRFAC_SYSCALL Trace system calls. KTRFAC_SYSRET Trace return values from system calls. KTRFAC_NAMEI Trace name lookup operations. KTRFAC_GENIO Trace all I/O (note that this option can generate much output). KTRFAC_PSIG Trace posted signals. KTRFAC_CSW Trace context switch points. KTRFAC_INHERIT Inherit tracing to future children. Each tracing event outputs a record composed of a generic header followed by a trace point specific structure. The generic header is: struct ktr_header { int ktr_len; /* length of buf */ short ktr_type; /* trace record type */ pid_t ktr_pid; /* process id */ char ktr_comm[MAXCOMLEN+1]; /* command name */ struct timeval ktr_time; /* timestamp */ intptr_t ktr_tid; /* was ktr_buffer */ }; The ktr_len field specifies the length of the ktr_type data that follows this header. The ktr_pid and ktr_comm fields specify the process and command generating the record. The ktr_time field gives the time (with microsecond resolution) that the record was generated. The ktr_tid field holds a threadid. The generic header is followed by ktr_len bytes of a ktr_type record. The type specific records are defined in the <sys/ktrace.h> include file. SYSCTL TUNABLES
The following sysctl(8) tunables influence the behaviour of ktrace(): kern.ktrace.geniosize bounds the amount of data a traced I/O request will log to the trace file. kern.ktrace.request_pool bounds the number of trace events being logged at a time. Sysctl tunables that control process debuggability (as determined by p_candebug(9)) also affect the operation of ktrace(). RETURN VALUES
The ktrace() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate the error. ERRORS
The ktrace() system call will fail if: [ENOTDIR] A component of the path prefix is not a directory. [ENAMETOOLONG] A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters. [ENOENT] The named tracefile does not exist. [EACCES] Search permission is denied for a component of the path prefix. [ELOOP] Too many symbolic links were encountered in translating the pathname. [EIO] An I/O error occurred while reading from or writing to the file system. [ENOSYS] The kernel was not compiled with ktrace support. A thread may be unable to log one or more tracing events due to a temporary shortage of resources. This condition is remembered by the ker- nel, and the next tracing request that succeeds will have the flag KTR_DROP set in its ktr_type field. SEE ALSO
kdump(1), ktrace(1), utrace(2), sysctl(8), p_candebug(9) HISTORY
The ktrace() system call first appeared in 4.4BSD. BSD
July 13, 2008 BSD
Man Page

Featured Tech Videos