1*a4c6ec8cScheloha.\" $OpenBSD: bt.5,v 1.17 2023/10/22 19:30:35 cheloha Exp $ 223160851Smpi.\" 323160851Smpi.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org> 423160851Smpi.\" 523160851Smpi.\" Permission to use, copy, modify, and distribute this software for any 623160851Smpi.\" purpose with or without fee is hereby granted, provided that the above 723160851Smpi.\" copyright notice and this permission notice appear in all copies. 823160851Smpi.\" 923160851Smpi.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1023160851Smpi.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1123160851Smpi.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1223160851Smpi.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1323160851Smpi.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1423160851Smpi.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1523160851Smpi.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1623160851Smpi.\" 17*a4c6ec8cScheloha.Dd $Mdocdate: October 22 2023 $ 1823160851Smpi.Dt BT 5 1923160851Smpi.Os 2023160851Smpi.Sh NAME 2123160851Smpi.Nm BT 22a378a2aaSmpi.Nd Bug Tracing language 2323160851Smpi.Sh SYNTAX 2423160851Smpi.D1 Ar probe Ic \&/ Ar filter Ic \&/ \&{ Ar action Ic \&} 2523160851Smpi.Sh DESCRIPTION 2623160851SmpiThe 2723160851Smpi.Nm 2823160851Smpilanguage, also known as BPFtrace syntax, describes how to format and display 2923160851Smpiinformation gathered from specified 3023160851Smpi.Ar probe 3123160851Smpievents. 3223160851Smpi.Pp 3323160851SmpiEvents are generated by the dynamic tracer 3423160851Smpi.Xr dt 4 3523160851Smpiwhen an enabled 3623160851Smpi.Ar probe 3723160851Smpiis triggered. 3823160851SmpiThey are periodically collected by 39b897e42eSjmc.Xr btrace 8 , 4023160851Smpiwhich formats them using the corresponding 4123160851Smpi.Ar action . 4223160851SmpiIf a recorded event doesn't match the optional 4341ce3b17Snaddy.Ar filter , 4423160851Smpiit will be silently ignored. 4523160851Smpi.Pp 4623160851SmpiA valid 4723160851Smpi.Nm 4823160851Smpisource file contains at least one 4923160851Smpi.Ar probe 5023160851Smpiclause associated with an 5123160851Smpi.Ar action 5223160851Smpistatement. 5323160851Smpi.Sh PROBE 5423160851SmpiThe list of available probes may vary from system to system and can be queried 5523160851Smpiwith 5623160851Smpi.Xr btrace 8 . 5723160851Smpi.Pp 5823160851SmpiThe special probes 5923160851Smpi.Ic BEGIN 6023160851Smpiand 6123160851Smpi.Ic END 6223160851Smpimay be used to manipulate states before the first event is recorded and after 6323160851Smpithe last. 6423160851SmpiThey cannot be combined with any 6523160851Smpi.Ar filter . 6623160851Smpi.Sh FILTER 67b897e42eSjmcDefine under which condition an event should be recorded when its related 6823160851Smpi.Ar probe 6923160851Smpiis executed. 7023160851SmpiAn empty 7123160851Smpi.Ar filter 7223160851Smpimeans record all events. 7323160851Smpi.Pp 7423160851SmpiVariable names available in filters: 7523160851Smpi.Pp 76b897e42eSjmc.Bl -tag -width "kstack " -compact -offset indent 7723160851Smpi.It Va pid 78b897e42eSjmcProcess ID of the current thread. 7923160851Smpi.It Va tid 80b897e42eSjmcThread ID of the current thread. 8123160851Smpi.El 8223160851Smpi.Sh ACTION 8323160851SmpiAn action is a sequence of statements that are evaluated for each event recorded 8423160851Smpiby the associated 8523160851Smpi.Ar probe . 8623160851Smpi.Pp 8723160851SmpiVariable names with special meaning: 8823160851Smpi.Pp 89b897e42eSjmc.Bl -tag -width "kstack " -compact -offset indent 906ca6ae3fSmpi.It Va $N 916ca6ae3fSmpiCommand line argument 926ca6ae3fSmpi.Va N 936ca6ae3fSmpiafter the script name. 9423160851Smpi.It Va argN 9523160851SmpiArgument 9623160851Smpi.Va N 97b897e42eSjmcof the corresponding probe. 980948ba6cSmpi.It Va comm 99b897e42eSjmcCommand name of the current process. 1000948ba6cSmpi.It Va cpu 101b897e42eSjmcID of the processor that recorded the event. 1020948ba6cSmpi.It Va kstack 103b897e42eSjmcKernel stack of the current thread. 1040948ba6cSmpi.It Va nsecs 105b897e42eSjmcTimestamp of the event in nanoseconds. 1060948ba6cSmpi.It Va pid 107b897e42eSjmcProcess ID of the current thread. 108ca210abeSclaudio.It Va probe 109ca210abeSclaudioFull name of the probe. 1100948ba6cSmpi.It Va retval 111b897e42eSjmcReturn value of the traced syscall. 1120948ba6cSmpi.It Va tid 113b897e42eSjmcThread ID of the current thread. 1143fc75573Sclaudio.It Va ustack 1153fc75573SclaudioUserland stack of the current thread. 11623160851Smpi.El 117a378a2aaSmpi.Pp 118a378a2aaSmpiFunctions: 1199c84395dSmpi.Bl -tag -width "lhist(value, min, max, step)" 120a378a2aaSmpi.It Fn clear "@map" 1215d3454a6SknDelete all (key, value) pairs from 1224417fdbbSjasper.Va @map . 1235d3454a6Skn.It Fn delete "@map[key]" 1245d3454a6SknDelete the pair indexed by 1255d3454a6Skn.Va key 1265d3454a6Sknfrom 1274417fdbbSjasper.Va @map . 1285d3454a6Skn.It Fn exit 1294417fdbbSjasperTerminate execution with exit code 0. 130*a4c6ec8cSchelohaThe 131*a4c6ec8cScheloha.Ic END 132*a4c6ec8cSchelohaprobe, 133*a4c6ec8cSchelohaif any, 134*a4c6ec8cSchelohais executed and the contents of all non-empty maps are printed. 1359c84395dSmpi.It Fn hist "value" 1369c84395dSmpiIncrement the bucket corresponding to 1379c84395dSmpi.Va value 1384417fdbbSjasperin a power-of-two histogram. 1399c84395dSmpi.It Fn lhist "value" "min" "max" "step" 1409c84395dSmpiIncrement the bucket corresponding to 1419c84395dSmpi.Va value 1429c84395dSmpiin the linear histogram spawning between the positive value 1439c84395dSmpi.Va min 1449c84395dSmpiand 1459c84395dSmpi.Va max 1469c84395dSmpiwith buckets of 1479c84395dSmpi.Va step 1489c84395dSmpisize. 149a378a2aaSmpi.It Fn print "@map" 1505d3454a6SknPrint all pairs from 1514417fdbbSjasper.Va @map . 1528c6b709bSanton.It Fn print "@map" n 1538c6b709bSantonPrint only the first 1548c6b709bSanton.Va n 1558c6b709bSantonentries in 1568c6b709bSanton.Va @map . 157a378a2aaSmpi.It Fn printf "fmt" ... 1584417fdbbSjasperPrint formatted string 1594417fdbbSjasper.Va fmt . 160b005393aSdv.It Fn str "$N" "[index]" 161b005393aSdvReturn the string from argument 162b005393aSdv.Va $N , 163b005393aSdvtruncated to 164b005393aSdv.Va index 165b005393aSdvcharacters (up to 64, the default) including a guaranteed NUL-terminator. 166fee6f174Skn.It Fn time timefmt 1674417fdbbSjasperPrint timestamps using 168b005393aSdv.Xr strftime 3 . 1695d3454a6Skn.It Fn zero "@map" 1705d3454a6SknSet all values from 1715d3454a6Skn.Va @map 1724417fdbbSjasperto 0. 173a378a2aaSmpi.El 1743fc75573Sclaudio.Pp 175fed5be9eSjsgThe following functions only work on a specific map entry. 1763fc75573Sclaudio.Bl -tag -width "lhist(value, min, max, step)" 1773fc75573Sclaudio.It "@map[key]" = Fn count 1783fc75573SclaudioIncrease the stored value for 1793fc75573Sclaudio.Va key 1803fc75573Sclaudioby one. 1813fc75573Sclaudio.It "@map[key]" = Fn max "value" 1823fc75573SclaudioStore the maximum recorded value for 1833fc75573Sclaudio.Va key . 1843fc75573Sclaudio.It "@map[key]" = Fn min "value" 1853fc75573SclaudioStore the minimum recorded value for 1863fc75573Sclaudio.Va key . 1873fc75573Sclaudio.It "@map[key]" = Fn sum "value" 1883fc75573SclaudioStore the sum of all recorded values for 1893fc75573Sclaudio.Va key . 1903fc75573Sclaudio.El 19123160851Smpi.Sh SEE ALSO 19223160851Smpi.Xr awk 1 , 19323160851Smpi.Xr dt 4 , 19423160851Smpi.Xr btrace 8 19523160851Smpi.Rs 19623160851Smpi.\"%A First Last 19723160851Smpi.%T BPFtrace reference guide 19823160851Smpi.%U https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md 19923160851Smpi.\"%D November 1, 1901 20023160851Smpi.Re 20123160851Smpi.Sh STANDARDS 20223160851SmpiThe dialect 20323160851Smpiof the 20423160851Smpi.Nm 20523160851Smpilanguage described in this manual and supported by 20623160851Smpi.Xr btrace 8 20723160851Smpiis compatible with BPFtrace. 20823160851SmpiThe syntax is similar to 20923160851Smpi.Xr awk 1 21023160851Smpiand dtrace. 211