1.\" $OpenBSD: bt.5,v 1.6 2020/07/11 14:52:14 mpi Exp $ 2.\" 3.\" Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org> 4.\" 5.\" Permission to use, copy, modify, and distribute this software for any 6.\" purpose with or without fee is hereby granted, provided that the above 7.\" copyright notice and this permission notice appear in all copies. 8.\" 9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16.\" 17.Dd $Mdocdate: July 11 2020 $ 18.Dt BT 5 19.Os 20.Sh NAME 21.Nm BT 22.Nd Bug Tracing language 23.Sh SYNTAX 24.D1 Ar probe Ic \&/ Ar filter Ic \&/ \&{ Ar action Ic \&} 25.Sh DESCRIPTION 26The 27.Nm 28language, also known as BPFtrace syntax, describes how to format and display 29information gathered from specified 30.Ar probe 31events. 32.Pp 33Events are generated by the dynamic tracer 34.Xr dt 4 35when an enabled 36.Ar probe 37is triggered. 38They are periodically collected by 39.Xr btrace 8 40which formats them using the corresponding 41.Ar action . 42If a recorded event doesn't match the optional 43.Ar filter 44it will be silently ignored. 45.Pp 46A valid 47.Nm 48source file contains at least one 49.Ar probe 50clause associated with an 51.Ar action 52statement. 53.Sh PROBE 54The list of available probes may vary from system to system and can be queried 55with 56.Xr btrace 8 . 57.Pp 58The special probes 59.Ic BEGIN 60and 61.Ic END 62may be used to manipulate states before the first event is recorded and after 63the last. 64They cannot be combined with any 65.Ar filter . 66.Sh FILTER 67Define under with condition an event should be recorded when its related 68.Ar probe 69is executed. 70An empty 71.Ar filter 72means record all events. 73.Pp 74Variable names available in filters: 75.Pp 76.Bl -tag -width "pid " -compact 77.It Va pid 78Process ID of the current thread 79.It Va tid 80Thread ID of the current thread 81.El 82.Sh ACTION 83An action is a sequence of statements that are evaluated for each event recorded 84by the associated 85.Ar probe . 86.Pp 87Variable names with special meaning: 88.Pp 89.Bl -tag -width "kstack " -compact 90.It Va argN 91Argument 92.Va N 93of the corresponding probe 94.It Va comm 95Command name of the current process 96.It Va cpu 97ID of the processor that recorded the event 98.It Va kstack 99Kernel stack of the current thread 100.It Va nsecs 101Timestamp of the event in nanoseconds 102.It Va pid 103Process ID of the current thread 104.It Va retval 105Return value of the traced syscall 106.It Va tid 107Thread ID of the current thread 108.\".It Va ustack 109.\"Userland stack of the current thread 110.El 111.Pp 112Functions: 113.Pp 114.Bl -tag -width "lhist(value, min, max, step)" 115.It Fn clear "@map" 116Delete all (key, value) pairs from 117.Va @map 118.It Fn delete "@map[key]" 119Delete the pair indexed by 120.Va key 121from 122.Va @map 123.It Fn exit 124Terminate execution with exit code 0 125.It Fn hist "value" 126Increment the bucket corresponding to 127.Va value 128in a power-of-two histogram 129.It Fn lhist "value" "min" "max" "step" 130Increment the bucket corresponding to 131.Va value 132in the linear histogram spawning between the positive value 133.Va min 134and 135.Va max 136with buckets of 137.Va step 138size. 139.It Fn print "@map" 140Print all pairs from 141.Va @map 142.It Fn printf "fmt" ... 143print formatted string 144.Va fmt 145.It Fn time timefmt 146print timestamps using 147.Xr strftime 3 148.It Fn zero "@map" 149Set all values from 150.Va @map 151to 0 152.El 153.Sh SEE ALSO 154.Xr awk 1 , 155.Xr dt 4 , 156.Xr btrace 8 157.Rs 158.\"%A First Last 159.%T BPFtrace reference guide 160.%U https://github.com/iovisor/bpftrace/blob/master/docs/reference_guide.md 161.\"%D November 1, 1901 162.Re 163.Sh STANDARDS 164The dialect 165of the 166.Nm 167language described in this manual and supported by 168.Xr btrace 8 169is compatible with BPFtrace. 170The syntax is similar to 171.Xr awk 1 172and dtrace. 173