1ebccf1e3SJoseph Koshy.\" Copyright (c) 2003 Joseph Koshy. All rights reserved. 2ebccf1e3SJoseph Koshy.\" 3ebccf1e3SJoseph Koshy.\" Redistribution and use in source and binary forms, with or without 4ebccf1e3SJoseph Koshy.\" modification, are permitted provided that the following conditions 5ebccf1e3SJoseph Koshy.\" are met: 6ebccf1e3SJoseph Koshy.\" 1. Redistributions of source code must retain the above copyright 7ebccf1e3SJoseph Koshy.\" notice, this list of conditions and the following disclaimer. 8ebccf1e3SJoseph Koshy.\" 2. Redistributions in binary form must reproduce the above copyright 9ebccf1e3SJoseph Koshy.\" notice, this list of conditions and the following disclaimer in the 10ebccf1e3SJoseph Koshy.\" documentation and/or other materials provided with the distribution. 11ebccf1e3SJoseph Koshy.\" 12ebccf1e3SJoseph Koshy.\" This software is provided by Joseph Koshy ``as is'' and 13ebccf1e3SJoseph Koshy.\" any express or implied warranties, including, but not limited to, the 14ebccf1e3SJoseph Koshy.\" implied warranties of merchantability and fitness for a particular purpose 15ebccf1e3SJoseph Koshy.\" are disclaimed. in no event shall Joseph Koshy be liable 16ebccf1e3SJoseph Koshy.\" for any direct, indirect, incidental, special, exemplary, or consequential 17ebccf1e3SJoseph Koshy.\" damages (including, but not limited to, procurement of substitute goods 18ebccf1e3SJoseph Koshy.\" or services; loss of use, data, or profits; or business interruption) 19ebccf1e3SJoseph Koshy.\" however caused and on any theory of liability, whether in contract, strict 20ebccf1e3SJoseph Koshy.\" liability, or tort (including negligence or otherwise) arising in any way 21ebccf1e3SJoseph Koshy.\" out of the use of this software, even if advised of the possibility of 22ebccf1e3SJoseph Koshy.\" such damage. 23ebccf1e3SJoseph Koshy.\" 24ebccf1e3SJoseph Koshy.\" $FreeBSD$ 25ebccf1e3SJoseph Koshy.\" 26ebccf1e3SJoseph Koshy.Dd Dec 15, 2003 27ebccf1e3SJoseph Koshy.Os 28ebccf1e3SJoseph Koshy.Dt PMCSTAT 8 29ebccf1e3SJoseph Koshy.Sh NAME 30ebccf1e3SJoseph Koshy.Nm pmcstat 31ebccf1e3SJoseph Koshy.Nd performance measurement with performance monitoring hardware 32ebccf1e3SJoseph Koshy.Sh SYNOPSIS 33ebccf1e3SJoseph Koshy.Nm 34f263522aSJoseph Koshy.Op Fl D Ar pathname 35ebccf1e3SJoseph Koshy.Op Fl C 36f263522aSJoseph Koshy.Op Fl E 37ebccf1e3SJoseph Koshy.Op Fl O Ar logfilename 38ebccf1e3SJoseph Koshy.Op Fl P Ar event-spec 39f263522aSJoseph Koshy.Op Fl R Ar logfilename 40ebccf1e3SJoseph Koshy.Op Fl S Ar event-spec 41f263522aSJoseph Koshy.Op Fl W 42ebccf1e3SJoseph Koshy.Op Fl c Ar cpu 43ebccf1e3SJoseph Koshy.Op Fl d 44f263522aSJoseph Koshy.Op Fl g 45f263522aSJoseph Koshy.Op Fl m 46ebccf1e3SJoseph Koshy.Op Fl n Ar count 47ebccf1e3SJoseph Koshy.Op Fl o Ar outputfile 48ebccf1e3SJoseph Koshy.Op Fl p Ar event-spec 49ebccf1e3SJoseph Koshy.Op Fl s Ar event-spec 50ebccf1e3SJoseph Koshy.Op Fl t Ar pid 51ebccf1e3SJoseph Koshy.Op Fl w Ar interval 52ebccf1e3SJoseph Koshy.Op command Op args 53ebccf1e3SJoseph Koshy.Sh DESCRIPTION 54ebccf1e3SJoseph KoshyThe 55ebccf1e3SJoseph Koshy.Nm 56ebccf1e3SJoseph Koshyutility measures system performance using the facilities provided by 57ebccf1e3SJoseph Koshy.Xr hwpmc 4 . 58ebccf1e3SJoseph Koshy.Pp 59ebccf1e3SJoseph KoshyThe 60ebccf1e3SJoseph Koshy.Nm 61ebccf1e3SJoseph Koshyutility can measure both hardware events seen by the system as a 62ebccf1e3SJoseph Koshywhole, and those seen when a specified process is executing on the 63ebccf1e3SJoseph Koshysystem's CPUs. 64ebccf1e3SJoseph KoshyIf a specific process is being targeted (for example, 65ebccf1e3SJoseph Koshyif the 66ebccf1e3SJoseph Koshy.Fl t Ar pid 67ebccf1e3SJoseph Koshyoption is specified, or if a command line is specified using 68ebccf1e3SJoseph Koshy.Ar command ) , 69ebccf1e3SJoseph Koshythen measurement occurs till the target process exits or 70ebccf1e3SJoseph Koshythe 71ebccf1e3SJoseph Koshy.Nm 72ebccf1e3SJoseph Koshyutility is interrupted by the user. 73ebccf1e3SJoseph KoshyIf a specific process is not targeted for measurement, then 74ebccf1e3SJoseph Koshy.Nm 75ebccf1e3SJoseph Koshywill perform system-wide measurements till interrupted by the 76ebccf1e3SJoseph Koshyuser. 77ebccf1e3SJoseph Koshy.Pp 78ebccf1e3SJoseph KoshyA given invocation of 79ebccf1e3SJoseph Koshy.Nm 80ebccf1e3SJoseph Koshycan mix allocations of system-mode and process-mode PMCs, of both 81ebccf1e3SJoseph Koshycounting and sampling flavors. 82ebccf1e3SJoseph KoshyThe values of all counting PMCs are printed in human readable form 83ebccf1e3SJoseph Koshyat regular intervals by 84ebccf1e3SJoseph Koshy.Nm . 85f263522aSJoseph KoshyThe output of sampling PMCs may be configured to go to a log file for 86f263522aSJoseph Koshysubsequent offline analysis, or, at the expense of greater 87f263522aSJoseph Koshyoverhead, may be configured to be processed on the fly. 88ebccf1e3SJoseph Koshy.Pp 89ebccf1e3SJoseph KoshyHardware events to measure are specified to 90ebccf1e3SJoseph Koshy.Nm 91ebccf1e3SJoseph Koshyusing event specifier strings 92ebccf1e3SJoseph Koshy.Ar event-spec . 93ebccf1e3SJoseph KoshyThe syntax of these event specifiers is machine dependent and is 94ebccf1e3SJoseph Koshydocumented in 95ebccf1e3SJoseph Koshy.Xr pmc 3 . 96ebccf1e3SJoseph Koshy.Pp 97ebccf1e3SJoseph KoshyA process-mode PMC may be configured to be inheritable by the target 98ebccf1e3SJoseph Koshyprocess' current and future children. 99ebccf1e3SJoseph Koshy.Sh OPTIONS 100ebccf1e3SJoseph KoshyThe following options are available: 101ebccf1e3SJoseph Koshy.Bl -tag -width indent 102ebccf1e3SJoseph Koshy.It Fl C 103f263522aSJoseph KoshyToggle between showing cumulative or incremental counts for 104ebccf1e3SJoseph Koshysubsequent counting mode PMCs specified on the command line. 105ebccf1e3SJoseph KoshyThe default is to show incremental counts. 106f263522aSJoseph Koshy.It Fl D Ar pathname 107f263522aSJoseph KoshyCreate files with per-program samples in the directory named 108f263522aSJoseph Koshyby 109f263522aSJoseph Koshy.Ar pathname . 110f263522aSJoseph KoshyThe default is to create these files in the current directory. 111f263522aSJoseph Koshy.It Fl E 112f263522aSJoseph KoshyToggle showing per-process counts at the time a tracked process 113f263522aSJoseph Koshyexits for subsequent process-mode PMCs specified on the command line. 114f263522aSJoseph KoshyThis option is useful for mapping the performance characteristics of a 115f263522aSJoseph Koshycomplex pipeline of processes when used in conjunction with the 116f263522aSJoseph Koshy.Fl d 117f263522aSJoseph Koshyoption. 118f263522aSJoseph KoshyThe default is to not to enable per-process tracking. 119ebccf1e3SJoseph Koshy.It Fl O Ar logfilename 120ebccf1e3SJoseph KoshySend the output of sampling mode PMCs to 121ebccf1e3SJoseph Koshy.Ar logfilename . 122f263522aSJoseph KoshyIf this option is not specified and one of the logging options 123f263522aSJoseph Koshyis requested, then 124f263522aSJoseph Koshy.Nm 125f263522aSJoseph Koshywill print a human-readable version of the log to the configured 126f263522aSJoseph Koshyoutput file. 127ebccf1e3SJoseph Koshy.It Fl P Ar event-spec 128ebccf1e3SJoseph KoshyAllocate a process mode sampling PMC measuring hardware events 129ebccf1e3SJoseph Koshyspecified in 130ebccf1e3SJoseph Koshy.Ar event-spec . 131f263522aSJoseph Koshy.It Fl R Ar logfilename 132f263522aSJoseph KoshyPerform offline analysis using sampling data in file 133f263522aSJoseph Koshy.Ar logfilename . 134ebccf1e3SJoseph Koshy.It Fl S Ar event-spec 135ebccf1e3SJoseph KoshyAllocate a system mode sampling PMC measuring hardware events 136ebccf1e3SJoseph Koshyspecified in 137ebccf1e3SJoseph Koshy.Ar event-spec . 138f263522aSJoseph Koshy.It Fl W 139f263522aSJoseph KoshyToggle logging the incremental counts seen by the threads of a 140f263522aSJoseph Koshytracked process each time they are scheduled on a CPU. 141f263522aSJoseph KoshyThis is an experimental feature intended to help analyse the 142f263522aSJoseph Koshydynamic behaviour of processes in the system. 143f263522aSJoseph KoshyIt may incur substantial overhead if enabled. 144f263522aSJoseph KoshyThe default is for this feature to be disabled. 145ebccf1e3SJoseph Koshy.It Fl c Ar cpu 146ebccf1e3SJoseph KoshySet the cpu for subsequent system mode PMCs specified on the 147ebccf1e3SJoseph Koshycommand line to 148ebccf1e3SJoseph Koshy.Ar cpu . 149ebccf1e3SJoseph KoshyThe default is to allocate system mode PMCs on CPU zero. 150ebccf1e3SJoseph Koshy.It Fl d 151ebccf1e3SJoseph KoshyToggle between process mode PMCs measuring events for the target 152ebccf1e3SJoseph Koshyprocess' current and future children or only measuring events for 153f263522aSJoseph Koshythe target process. 154ebccf1e3SJoseph KoshyThe default is to measure events for the target process alone. 155f263522aSJoseph Koshy.It Fl g 156f263522aSJoseph KoshyProduce execution profiles in a format compatible with 157f263522aSJoseph Koshy.Xr gprof 1 . 158f263522aSJoseph Koshy.It Fl m 159f263522aSJoseph KoshyWhen producing 160f263522aSJoseph Koshy.Xr gprof 1 161f263522aSJoseph Koshycompatible execution profiles, merge profiles across multiple 162f263522aSJoseph Koshyinvocations of the same executable. 163ebccf1e3SJoseph Koshy.It Fl n Ar rate 164ebccf1e3SJoseph KoshySet the default sampling rate for subsequent sampling mode 165ebccf1e3SJoseph KoshyPMCs specified on the command line. 166ebccf1e3SJoseph KoshyThe default is to configure PMCs to sample the CPU's instruction 167ebccf1e3SJoseph Koshypointer every 65536 events. 168ebccf1e3SJoseph Koshy.It Fl o Ar outputfile 169f263522aSJoseph KoshySend counter readings and printed representations of logged data 170ebccf1e3SJoseph Koshyto file 171ebccf1e3SJoseph Koshy.Ar outputfile . 172ebccf1e3SJoseph KoshyThe default is to send output to 173ebccf1e3SJoseph Koshy.Pa stderr . 174ebccf1e3SJoseph Koshy.It Fl p Ar event-spec 175ebccf1e3SJoseph KoshyAllocate a process mode counting PMC measuring hardware events 176ebccf1e3SJoseph Koshyspecified in 177ebccf1e3SJoseph Koshy.Ar event-spec . 178ebccf1e3SJoseph Koshy.It Fl s Ar event-spec 179ebccf1e3SJoseph KoshyAllocate a system mode counting PMC measuring hardware events 180ebccf1e3SJoseph Koshyspecified in 181ebccf1e3SJoseph Koshy.Ar event-spec . 182ebccf1e3SJoseph Koshy.It Fl t Ar pid 183ebccf1e3SJoseph KoshyAttach all process mode PMCs allocated to the process with PID 184ebccf1e3SJoseph Koshy.Ar pid . 185ebccf1e3SJoseph KoshyThe option is not allowed in conjunction with specifying a 186ebccf1e3SJoseph Koshycommand using 187ebccf1e3SJoseph Koshy.Ar command . 188ebccf1e3SJoseph Koshy.It Fl w Ar secs 189ebccf1e3SJoseph KoshyPrint the values of all counting mode PMCs every 190ebccf1e3SJoseph Koshy.Ar secs 191ebccf1e3SJoseph Koshyseconds. 192ebccf1e3SJoseph KoshyThe argument 193ebccf1e3SJoseph Koshy.Ar secs 194ebccf1e3SJoseph Koshymay be a fractional value. 195ebccf1e3SJoseph KoshyThe default interval is 5 seconds. 196ebccf1e3SJoseph Koshy.El 197ebccf1e3SJoseph Koshy.Pp 198ebccf1e3SJoseph KoshyIf 199ebccf1e3SJoseph Koshy.Ar command 200ebccf1e3SJoseph Koshyis specified, it is executed using 201ebccf1e3SJoseph Koshy.Xr execvp 3 . 202ebccf1e3SJoseph Koshy.Sh EXAMPLES 203ebccf1e3SJoseph KoshyTo perform system-wide statistical sampling on an AMD Athlon CPU with 204ebccf1e3SJoseph Koshysamples taken every 32768 instruction retirals and data being sampled 205ebccf1e3SJoseph Koshyto file 206ebccf1e3SJoseph Koshy.Dq sample.stat , 207ebccf1e3SJoseph Koshyuse: 208ebccf1e3SJoseph Koshy.Dl pmccstat -O sample.stat -n 32768 -S k7-retired-instructions 209ebccf1e3SJoseph Koshy.Pp 210ebccf1e3SJoseph KoshyTo execute 211ebccf1e3SJoseph Koshy.Dq mozilla 212ebccf1e3SJoseph Koshyand measure the number of data cache misses suffered 213ebccf1e3SJoseph Koshyby it and its children every 12 seconds on an AMD Athlon, use: 214ebccf1e3SJoseph Koshy.Dl pmcstat -d -w 12 -p k7-dc-misses mozilla 215ebccf1e3SJoseph Koshy.Sh DIAGNOSTICS 216ebccf1e3SJoseph Koshy.Ex -std pmcstat 217ebccf1e3SJoseph Koshy.Sh HISTORY 218ebccf1e3SJoseph KoshyThe 219ebccf1e3SJoseph Koshy.Nm 220ebccf1e3SJoseph Koshyutility is proposed to be integrated into 221ebccf1e3SJoseph Koshy.Fx 222ebccf1e3SJoseph Koshysometime after 223ebccf1e3SJoseph Koshy.Fx 5.2 . 224ebccf1e3SJoseph Koshy.Nm 225ebccf1e3SJoseph Koshy.Bt 226ebccf1e3SJoseph Koshy.Sh AUTHORS 227ebccf1e3SJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org 228ebccf1e3SJoseph Koshy.Sh SEE ALSO 229f263522aSJoseph Koshy.Xr gprof 1 , 230ebccf1e3SJoseph Koshy.Xr execvp 3 , 231ebccf1e3SJoseph Koshy.Xr pmc 3 , 232ebccf1e3SJoseph Koshy.Xr hwpmc 4 , 233ebccf1e3SJoseph Koshy.Xr pmccontrol 8 , 234ebccf1e3SJoseph Koshy.Xr sysctl 8 235