12e5fc9fdSJohn Baldwin.\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org> 22e5fc9fdSJohn Baldwin.\" All rights reserved. 32e5fc9fdSJohn Baldwin.\" 42e5fc9fdSJohn Baldwin.\" Redistribution and use in source and binary forms, with or without 52e5fc9fdSJohn Baldwin.\" modification, are permitted provided that the following conditions 62e5fc9fdSJohn Baldwin.\" are met: 72e5fc9fdSJohn Baldwin.\" 1. Redistributions of source code must retain the above copyright 82e5fc9fdSJohn Baldwin.\" notice, this list of conditions and the following disclaimer. 92e5fc9fdSJohn Baldwin.\" 2. Redistributions in binary form must reproduce the above copyright 102e5fc9fdSJohn Baldwin.\" notice, this list of conditions and the following disclaimer in the 112e5fc9fdSJohn Baldwin.\" documentation and/or other materials provided with the distribution. 122e5fc9fdSJohn Baldwin.\" 132e5fc9fdSJohn Baldwin.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 142e5fc9fdSJohn Baldwin.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 152e5fc9fdSJohn Baldwin.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 162e5fc9fdSJohn Baldwin.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 172e5fc9fdSJohn Baldwin.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 182e5fc9fdSJohn Baldwin.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 192e5fc9fdSJohn Baldwin.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 202e5fc9fdSJohn Baldwin.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 212e5fc9fdSJohn Baldwin.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 222e5fc9fdSJohn Baldwin.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 232e5fc9fdSJohn Baldwin.\" SUCH DAMAGE. 242e5fc9fdSJohn Baldwin.\" 252e5fc9fdSJohn Baldwin.\" $FreeBSD$ 262e5fc9fdSJohn Baldwin.\" 272e5fc9fdSJohn Baldwin.Dd February 16, 2001 282e5fc9fdSJohn Baldwin.Dt KTR 4 292e5fc9fdSJohn Baldwin.Os 302e5fc9fdSJohn Baldwin.Sh NAME 312e5fc9fdSJohn Baldwin.Nm ktr 322e5fc9fdSJohn Baldwin.Nd kernel tracing facility 332e5fc9fdSJohn Baldwin.Sh SYNOPSIS 342e5fc9fdSJohn Baldwin.Cd options KTR 357229a4a2SJeff Roberson.Cd options KTR_ALQ 362e5fc9fdSJohn Baldwin.Cd options KTR_COMPILE=(KTR_LOCK|KTR_INTR|KTR_PROC) 372e5fc9fdSJohn Baldwin.Cd options KTR_CPUMASK=0x3 382e5fc9fdSJohn Baldwin.Cd options KTR_ENTRIES=8192 392e5fc9fdSJohn Baldwin.Cd options KTR_MASK=(KTR_INTR|KTR_PROC) 402e5fc9fdSJohn Baldwin.Cd options KTR_VERBOSE 412e5fc9fdSJohn Baldwin.Sh DESCRIPTION 422e5fc9fdSJohn BaldwinThe 432e5fc9fdSJohn Baldwin.Nm 442e5fc9fdSJohn Baldwinfacility allows kernel events to be logged while the kernel executes so that 452e5fc9fdSJohn Baldwinthey can be examined later when debugging. 462e5fc9fdSJohn BaldwinThe only mandatory option to enable 472e5fc9fdSJohn Baldwin.Nm 488d458e5bSRuslan Ermilovis 498d458e5bSRuslan Ermilov.Dq Li options KTR . 502e5fc9fdSJohn Baldwin.Pp 518d458e5bSRuslan ErmilovThe 528d458e5bSRuslan Ermilov.Dv KTR_ENTRIES 538d458e5bSRuslan Ermilovoption sets the size of the buffer of events. 542e5fc9fdSJohn BaldwinIt should be a power of two. 552e5fc9fdSJohn BaldwinThe size of the buffer in the currently running kernel can be found via the 562e5fc9fdSJohn Baldwinread-only sysctl 578d458e5bSRuslan Ermilov.Va debug.ktr.entries . 582e5fc9fdSJohn BaldwinBy default the buffer contains 1024 entries. 592e5fc9fdSJohn Baldwin.Ss Event Masking 602e5fc9fdSJohn BaldwinEvent levels can be enabled or disabled to trim excessive and overly verbose 612e5fc9fdSJohn Baldwinlogging. 628d458e5bSRuslan ErmilovFirst, a mask of events is specified at compile time via the 638d458e5bSRuslan Ermilov.Dv KTR_COMPILE 642e5fc9fdSJohn Baldwinoption to limit which events are actually compiled into the kernel. 652e5fc9fdSJohn BaldwinThe default value for this option is for all events to be enabled. 662e5fc9fdSJohn Baldwin.Pp 672e5fc9fdSJohn BaldwinSecondly, the actual events logged while the kernel runs can be further 682e5fc9fdSJohn Baldwinmasked via the run time event mask. 698d458e5bSRuslan ErmilovThe 708d458e5bSRuslan Ermilov.Dv KTR_MASK 718d458e5bSRuslan Ermilovoption sets the default value of the run time event mask. 722e5fc9fdSJohn BaldwinThe runtime event mask can also be set by the 732e5fc9fdSJohn Baldwin.Xr loader 8 742e5fc9fdSJohn Baldwinvia the 758d458e5bSRuslan Ermilov.Va debug.ktr.mask 762e5fc9fdSJohn Baldwinenvironment variable. 772e5fc9fdSJohn BaldwinIt can also be examined and set after booting via the 788d458e5bSRuslan Ermilov.Va debug.ktr.mask 792e5fc9fdSJohn Baldwinsysctl. 802e5fc9fdSJohn BaldwinBy default the run time mask is set to log only 812e5fc9fdSJohn Baldwin.Dv KTR_GEN 822e5fc9fdSJohn Baldwinevents. 832e5fc9fdSJohn BaldwinThe definitions of the event mask bits can be found in 842e5fc9fdSJohn Baldwin.Aq Pa sys/ktr.h . 852e5fc9fdSJohn Baldwin.Pp 8654dc0e41SJeff RobersonFurthermore, there is a CPU event mask whose default value can be changed via 878d458e5bSRuslan Ermilovthe 888d458e5bSRuslan Ermilov.Dv KTR_CPUMASK 898d458e5bSRuslan Ermilovoption. 902e5fc9fdSJohn BaldwinA CPU must have the bit corresponding to its logical id set in this bitmask 912e5fc9fdSJohn Baldwinfor events that occur on it to be logged. 922e5fc9fdSJohn BaldwinThis mask can be set by the 932e5fc9fdSJohn Baldwin.Xr loader 8 942e5fc9fdSJohn Baldwinvia the 958d458e5bSRuslan Ermilov.Va debug.ktr.cpumask 962e5fc9fdSJohn Baldwinenvironment variable. 972e5fc9fdSJohn BaldwinIt can also be examined and set after booting via the 988d458e5bSRuslan Ermilov.Va debug.ktr.cpumask 992e5fc9fdSJohn Baldwinsysctl. 1002e5fc9fdSJohn BaldwinBy default events on all CPUs are enabled. 10154dc0e41SJeff Roberson.Ss Verbose mode 1022e5fc9fdSJohn BaldwinBy default, events are only logged to the internal buffer for examination 1032e5fc9fdSJohn Baldwinlater, but if the verbose flag is set then they are dumped to the kernel 1042e5fc9fdSJohn Baldwinconsole as well. 1052e5fc9fdSJohn BaldwinThis flag can also be set from the loader via the 1068d458e5bSRuslan Ermilov.Va debug.ktr.verbose 1072e5fc9fdSJohn Baldwinenvironment variable, or it can be examined and set after booting via the 1088d458e5bSRuslan Ermilov.Va debug.ktr.verbose 1092e5fc9fdSJohn Baldwinsysctl. 1102e5fc9fdSJohn BaldwinIf the flag is set to zero, which is the default, then verbose output is 1112e5fc9fdSJohn Baldwindisabled. 1122e5fc9fdSJohn BaldwinIf the flag is set to one, then the contents of the log message and the CPU 1132e5fc9fdSJohn Baldwinnumber are printed to the kernel console. 1142e5fc9fdSJohn BaldwinIf the flag is greater than one, then the filename and line number of the 1152e5fc9fdSJohn Baldwinevent are output to the console in addition to the log message and the CPU 1162e5fc9fdSJohn Baldwinnumber. 1178d458e5bSRuslan ErmilovThe 1188d458e5bSRuslan Ermilov.Dv KTR_VERBOSE 1198d458e5bSRuslan Ermilovoption sets the flag to one. 1202e5fc9fdSJohn Baldwin.Ss Examining the Events 1212e5fc9fdSJohn BaldwinThe KTR buffer can be examined from within 1222e5fc9fdSJohn Baldwin.Xr ddb 4 1232e5fc9fdSJohn Baldwinvia the 1248d458e5bSRuslan Ermilov.Ic show ktr Op Cm /v 1252e5fc9fdSJohn Baldwincommand. 1262e5fc9fdSJohn BaldwinThis command displays the contents of the trace buffer one page at a time. 1272e5fc9fdSJohn BaldwinAt the 1288d458e5bSRuslan Ermilov.Dq Li --more-- 1292e5fc9fdSJohn Baldwinprompt, the Enter key displays one more entry and prompts again. 1302e5fc9fdSJohn BaldwinThe spacebar displays another page of entries. 1312e5fc9fdSJohn BaldwinAny other key quits. 1322e5fc9fdSJohn BaldwinBy default the timestamp, filename, and line number are not displayed with 1332e5fc9fdSJohn Baldwineach log entry. 1342e5fc9fdSJohn BaldwinIf the 1358d458e5bSRuslan Ermilov.Cm /v 1362e5fc9fdSJohn Baldwinmodifier is specified, then they are displayed in addition to the normal 1372e5fc9fdSJohn Baldwinoutput. 1382e5fc9fdSJohn BaldwinNote that the events are displayed in reverse chronological order. 1392e5fc9fdSJohn BaldwinThat is, the most recent events are displayed first. 1407229a4a2SJeff Roberson.Ss Logging ktr to disk 1417229a4a2SJeff RobersonThe 1427229a4a2SJeff Roberson.Dv KTR_ALQ 1437229a4a2SJeff Robersonoption can be used to log ktr entries to disk for post analysis using the 1447229a4a2SJeff Roberson.Xr ktrdump 8 1457229a4a2SJeff Robersonutility. 1467229a4a2SJeff RobersonDue to the potentially high volume of trace messages the trace mask should be 1477229a4a2SJeff Robersonselected carefully. 1487229a4a2SJeff RobersonThis feature is configured through a group of sysctls. 1497229a4a2SJeff Roberson.Pp 1507229a4a2SJeff Roberson.Va debug.ktr.alq_file 1517229a4a2SJeff Robersondisplays or sets the file that ktr will log to. By default its value is 1527229a4a2SJeff Roberson"/tmp/ktr.out". 1537229a4a2SJeff RobersonIf the file name is changed while ktr is enabled it will not take effect until 1547229a4a2SJeff Robersonthe next invocation. 1557229a4a2SJeff Roberson.Pp 1567229a4a2SJeff Roberson.Va debug.ktr.alq_enable 1577229a4a2SJeff Robersonenables logging of ktr entries to disk if it is set to one. 1587229a4a2SJeff RobersonSetting this to 0 will terminate logging. 1597229a4a2SJeff Roberson.Pp 1607229a4a2SJeff Roberson.Va debug.ktr.alq_max 1617229a4a2SJeff Robersonis the maximum number of entries that will be recorded to disk, or 0 for 1627229a4a2SJeff Robersoninfinite. 1637229a4a2SJeff RobersonThis is helpful for limiting the number of particularly high frequency entries 1647229a4a2SJeff Robersonthat are recorded. 1657229a4a2SJeff Roberson.Pp 1667229a4a2SJeff Roberson.Va debug.ktr.alq_depth 1677229a4a2SJeff Robersondetermines the number of entries in the write buffer. 1687229a4a2SJeff RobersonThis is the buffer that holds entries before they are written to disk and 1697229a4a2SJeff Robersondefaults to the value of the 1707229a4a2SJeff Roberson.Dv KTR_ENTRIES 1717229a4a2SJeff Robersonoption. 1727229a4a2SJeff Roberson.Pp 1737229a4a2SJeff Roberson.Va debug.ktr.alq_failed 1747229a4a2SJeff Robersonrecords the number of times we failed to write an entry due to overflowing the 1757229a4a2SJeff Robersonwrite buffer. 1767229a4a2SJeff RobersonThis may happen if the frequency of the logged ktr messages outpaces the depth 1777229a4a2SJeff Robersonof the queue. 1787229a4a2SJeff Roberson.Pp 1797229a4a2SJeff Roberson.Va debug.ktr.alq_cnt 1807229a4a2SJeff Robersonrecords the number of entries that have currently been written to disk. 1812e5fc9fdSJohn Baldwin.Sh SEE ALSO 18272517de5SJeff Roberson.Xr ktr 9 , 18372517de5SJeff Roberson.Xr ktrdump 8 1842e5fc9fdSJohn Baldwin.Sh HISTORY 1852e5fc9fdSJohn BaldwinThe KTR kernel tracing facility first appeared in 186a867da6fSJohn Baldwin.Bsx 3.0 187a867da6fSJohn Baldwinand was imported into 1882e5fc9fdSJohn Baldwin.Fx 5.0 . 189