ktrace (2)
Leading comments
Copyright (c) 1993 The Regents of the University of California. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following discl...
NAME
ktrace - process tracingLIBRARY
Lb libcSYNOPSIS
In sys/param.h In sys/time.h In sys/uio.h In sys/ktrace.h Ft int Fn ktrace const char *tracefile int ops int trpoints int pidDESCRIPTION
The Fn 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 Fa 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), Fa tracefile may be NULL.
The Fa ops argument specifies the requested ktrace operation. The defined operations are:
- KTROP_SET Ta Enable trace points specified in
- Fa trpoints .
- KTROP_CLEAR Ta Disable trace points specified in
- Fa trpoints .
- KTROP_CLEARFILE Ta Stop all tracing.
- KTRFLAG_DESCEND Ta The tracing change should apply to the
- specified process and all its current children.
The Fa trpoints argument specifies the trace points of interest. The defined trace points are:
- KTRFAC_SYSCALL Ta Trace system calls.
- KTRFAC_SYSRET Ta Trace return values from system calls.
- KTRFAC_NAMEI Ta Trace name lookup operations.
- KTRFAC_GENIO Ta Trace all I/O (note that this option can
- generate much output).
- KTRFAC_PSIG Ta Trace posted signals.
- KTRFAC_CSW Ta Trace context switch points.
- KTRFAC_USER Ta Trace application-specific events.
- KTRFAC_STRUCT Ta Trace certain data structures.
- KTRFAC_SYSCTL Ta Trace sysctls.
- KTRFAC_PROCCTOR Ta Trace process construction.
- KTRFAC_PROCDTOR Ta Trace process destruction.
- KTRFAC_CAPFAIL Ta Trace capability failures.
- KTRFAC_INHERIT Ta 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 thread id.
The generic header is followed by ktr_len bytes of a ktr_type record. The type specific records are defined in the In sys/ktrace.h include file.
SYSCTL TUNABLES
The following sysctl(8) tunables influence the behaviour of Fn 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_candebug9) also affect the operation of Fn ktrace .
RETURN VALUES
Rv -std ktraceERRORS
The Fn ktrace system call will fail if:- Bq Er ENOTDIR
- A component of the path prefix is not a directory.
- Bq Er ENAMETOOLONG
- A component of a pathname exceeded 255 characters, or an entire path name exceeded 1023 characters.
- Bq Er ENOENT
- The named tracefile does not exist.
- Bq Er EACCES
- Search permission is denied for a component of the path prefix.
- Bq Er ELOOP
- Too many symbolic links were encountered in translating the pathname.
- Bq Er EIO
- An I/O error occurred while reading from or writing to the file system.
- Bq Er ENOSYS
- The kernel was not compiled with 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 kernel, and the next tracing request that succeeds will have the flag KTR_DROP set in its ktr_type field.