1.\" $NetBSD: tprof.8,v 1.15 2019/10/11 20:18:20 jmcneill Exp $ 2.\" 3.\" Copyright (c)2011 YAMAMOTO Takashi, 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 15.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25.\" SUCH DAMAGE. 26.\" 27.Dd October 11, 2019 28.Dt TPROF 8 29.Os 30.Sh NAME 31.Nm tprof 32.Nd record tprof profiling samples 33.Sh SYNOPSIS 34.Nm 35.Ar op 36.Op Ar arguments 37.Sh DESCRIPTION 38The 39.Nm 40tool can be used to monitor hardware events (PMCs) during the execution of 41certain commands. 42.Pp 43The 44.Nm 45utility makes the kernel driver start profiling, 46executes the specified command, 47keeps recording samples from the kernel driver until the command finishes, 48and reports statistics to the standard error. 49.Pp 50The 51.Nm tprof 52pseudo driver and a suitable backend should be loaded beforehand. 53.Pp 54The 55.Nm 56utility accepts the following options. 57The first argument, 58.Ar op , 59specifies the action to take. 60Valid actions are: 61.Bl -tag -width offline -offset indent 62.It list 63Display a list of performance counter events available on the system. 64.It monitor Xo 65.Fl e 66.Ar name:option 67.Op Fl o Ar outfile 68.Ar command 69.Xc 70Monitor the execution of command 71.Ar command . 72.Ar name 73specifies the name of the event to count; it must be taken from the list of 74available events. 75.Ar option 76specifies the source of the event; it must be a combination of 77.Ar u 78(userland) and 79.Ar k 80(kernel). 81The collected samples are written into the file 82.Ar outfile 83if specified. 84The default is 85.Dq Pa tprof.out . 86.It analyze Xo 87.Op Fl CkLPs 88.Op Fl p Ar pid 89.Ar file 90.Xc 91Analyze the samples produced by a previous run of 92.Nm tprof , 93stored in 94.Ar file , 95and generate a plain text representation of them. 96.Bl -tag -width XPXpidXX -offset indent 97.It Fl C 98Don't distinguish CPUs. 99All samples are treated as its CPU number is 0. 100.It Fl k 101Kernel only. 102Ignore samples for userland code. 103.It Fl L 104Don't distinguish LWPs. 105All samples are treated as its LWP ID is 0. 106.It Fl P 107Don't distinguish processes. 108All samples are treated as its PID is 0. 109.It Fl p Ar pid 110Process only samples for the process with PID 111.Ar pid 112and ignore the rest. 113.It Fl s 114Per symbol. 115.El 116.El 117.Sh EXAMPLES 118The following command profiles the system during 20 seconds and writes the 119samples into the file myfile.out. 120.Dl # tprof monitor -e llc-misses:k -o myfile.out sleep 20 121The following command displays the results of the sampling. 122.Dl # tprof analyze myfile.out 123.Sh SUPPORT 124The following CPU models are supported: 125.Bl -hyphen -compact -offset indent 126.It 127ARMv7 128.It 129ARMv8 130.It 131x86 AMD Family 10h 132.It 133x86 AMD Family 15h 134.It 135x86 AMD Family 17h 136.It 137x86 Intel Generic (all Intel CPUs) 138.It 139x86 Intel Skylake/Kabylake 140.It 141x86 Intel Silvermont/Airmont 142.It 143x86 Intel Goldmont 144.It 145x86 Intel Goldmont Plus 146.El 147.Sh DIAGNOSTICS 148The 149.Nm 150utility reports the following statistics about the activities of the 151.Nm tprof 152pseudo driver. 153.Bl -tag -width dropbuf_samples 154.It sample 155The number of samples collected and prepared for userland consumption. 156.It overflow 157The number of samples dropped because the per-CPU buffer was full. 158.It buf 159The number of buffers successfully prepared for userland consumption. 160.It emptybuf 161The number of buffers which have been dropped because they were empty. 162.It dropbuf 163The number of buffers dropped because the number of buffers kept in the kernel 164exceeds the limit. 165.It dropbuf_samples 166The number of samples dropped because the buffers containing the samples 167were dropped. 168.El 169.Sh SEE ALSO 170.Xr tprof 4 171.Sh AUTHORS 172.An -nosplit 173The 174.Nm 175utility was written by 176.An YAMAMOTO Takashi . 177It was revamped by 178.An Maxime Villard 179in 2018. 180.Sh CAVEATS 181The contents and representation of recorded samples are undocumented and 182will likely be changed for future releases of 183.Nx 184in an incompatible way. 185