1ee4910b1SJoseph Koshy.\" Copyright (c) 2003-2007 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.\" 26ee4910b1SJoseph Koshy.Dd April 22, 2007 27ebccf1e3SJoseph Koshy.Os 28ebccf1e3SJoseph Koshy.Dt PMCSTAT 8 29ebccf1e3SJoseph Koshy.Sh NAME 30ebccf1e3SJoseph Koshy.Nm pmcstat 3121ce09caSJoseph Koshy.Nd "performance measurement with performance monitoring hardware" 32ebccf1e3SJoseph Koshy.Sh SYNOPSIS 33ebccf1e3SJoseph Koshy.Nm 34ebccf1e3SJoseph Koshy.Op Fl C 3515139246SJoseph Koshy.Op Fl D Ar pathname 36f263522aSJoseph Koshy.Op Fl E 3749874f6eSJoseph Koshy.Op Fl M Ar mapfilename 38ebccf1e3SJoseph Koshy.Op Fl O Ar logfilename 39ebccf1e3SJoseph Koshy.Op Fl P Ar event-spec 40f263522aSJoseph Koshy.Op Fl R Ar logfilename 41ebccf1e3SJoseph Koshy.Op Fl S Ar event-spec 42f263522aSJoseph Koshy.Op Fl W 43ee4910b1SJoseph Koshy.Op Fl c Ar cpu-spec 44ebccf1e3SJoseph Koshy.Op Fl d 45f263522aSJoseph Koshy.Op Fl g 4649874f6eSJoseph Koshy.Op Fl k Ar kerneldir 4721ce09caSJoseph Koshy.Op Fl n Ar rate 48ebccf1e3SJoseph Koshy.Op Fl o Ar outputfile 49ebccf1e3SJoseph Koshy.Op Fl p Ar event-spec 5049874f6eSJoseph Koshy.Op Fl q 5149874f6eSJoseph Koshy.Op Fl r Ar fsroot 52ebccf1e3SJoseph Koshy.Op Fl s Ar event-spec 53ebccf1e3SJoseph Koshy.Op Fl t Ar pid 5449874f6eSJoseph Koshy.Op Fl v 5521ce09caSJoseph Koshy.Op Fl w Ar secs 5621ce09caSJoseph Koshy.Op Ar command Op Ar args 57ebccf1e3SJoseph Koshy.Sh DESCRIPTION 58ebccf1e3SJoseph KoshyThe 59ebccf1e3SJoseph Koshy.Nm 60ebccf1e3SJoseph Koshyutility measures system performance using the facilities provided by 61ebccf1e3SJoseph Koshy.Xr hwpmc 4 . 62ebccf1e3SJoseph Koshy.Pp 63ebccf1e3SJoseph KoshyThe 64ebccf1e3SJoseph Koshy.Nm 65ebccf1e3SJoseph Koshyutility can measure both hardware events seen by the system as a 66ebccf1e3SJoseph Koshywhole, and those seen when a specified process is executing on the 67ebccf1e3SJoseph Koshysystem's CPUs. 68ebccf1e3SJoseph KoshyIf a specific process is being targeted (for example, 69ebccf1e3SJoseph Koshyif the 70ebccf1e3SJoseph Koshy.Fl t Ar pid 71ebccf1e3SJoseph Koshyoption is specified, or if a command line is specified using 72ebccf1e3SJoseph Koshy.Ar command ) , 73ebccf1e3SJoseph Koshythen measurement occurs till the target process exits or 74ebccf1e3SJoseph Koshythe 75ebccf1e3SJoseph Koshy.Nm 76ebccf1e3SJoseph Koshyutility is interrupted by the user. 77ebccf1e3SJoseph KoshyIf a specific process is not targeted for measurement, then 78ebccf1e3SJoseph Koshy.Nm 79ebccf1e3SJoseph Koshywill perform system-wide measurements till interrupted by the 80ebccf1e3SJoseph Koshyuser. 81ebccf1e3SJoseph Koshy.Pp 82ebccf1e3SJoseph KoshyA given invocation of 83ebccf1e3SJoseph Koshy.Nm 84ebccf1e3SJoseph Koshycan mix allocations of system-mode and process-mode PMCs, of both 85ebccf1e3SJoseph Koshycounting and sampling flavors. 86ebccf1e3SJoseph KoshyThe values of all counting PMCs are printed in human readable form 87ebccf1e3SJoseph Koshyat regular intervals by 88ebccf1e3SJoseph Koshy.Nm . 89f263522aSJoseph KoshyThe output of sampling PMCs may be configured to go to a log file for 90f263522aSJoseph Koshysubsequent offline analysis, or, at the expense of greater 9121ce09caSJoseph Koshyoverhead, may be configured to be printed in text form on the fly. 92ebccf1e3SJoseph Koshy.Pp 93ebccf1e3SJoseph KoshyHardware events to measure are specified to 94ebccf1e3SJoseph Koshy.Nm 95ebccf1e3SJoseph Koshyusing event specifier strings 96ebccf1e3SJoseph Koshy.Ar event-spec . 97ebccf1e3SJoseph KoshyThe syntax of these event specifiers is machine dependent and is 98ebccf1e3SJoseph Koshydocumented in 99ebccf1e3SJoseph Koshy.Xr pmc 3 . 100ebccf1e3SJoseph Koshy.Pp 101ebccf1e3SJoseph KoshyA process-mode PMC may be configured to be inheritable by the target 102ebccf1e3SJoseph Koshyprocess' current and future children. 103ebccf1e3SJoseph Koshy.Sh OPTIONS 104ebccf1e3SJoseph KoshyThe following options are available: 105ebccf1e3SJoseph Koshy.Bl -tag -width indent 106ebccf1e3SJoseph Koshy.It Fl C 107f263522aSJoseph KoshyToggle between showing cumulative or incremental counts for 108ebccf1e3SJoseph Koshysubsequent counting mode PMCs specified on the command line. 109ebccf1e3SJoseph KoshyThe default is to show incremental counts. 110f263522aSJoseph Koshy.It Fl D Ar pathname 111f263522aSJoseph KoshyCreate files with per-program samples in the directory named 112f263522aSJoseph Koshyby 113f263522aSJoseph Koshy.Ar pathname . 114f263522aSJoseph KoshyThe default is to create these files in the current directory. 115f263522aSJoseph Koshy.It Fl E 116f263522aSJoseph KoshyToggle showing per-process counts at the time a tracked process 117f263522aSJoseph Koshyexits for subsequent process-mode PMCs specified on the command line. 118f263522aSJoseph KoshyThis option is useful for mapping the performance characteristics of a 119f263522aSJoseph Koshycomplex pipeline of processes when used in conjunction with the 120f263522aSJoseph Koshy.Fl d 121f263522aSJoseph Koshyoption. 122f263522aSJoseph KoshyThe default is to not to enable per-process tracking. 12349874f6eSJoseph Koshy.It Fl M Ar mapfilename 12449874f6eSJoseph KoshyWrite the mapping between executable objects encountered in the event 12549874f6eSJoseph Koshylog and the abbreviated pathnames used for 12649874f6eSJoseph Koshy.Xr gprof 1 12749874f6eSJoseph Koshyprofiles to file 12849874f6eSJoseph Koshy.Ar mapfilename . 12949874f6eSJoseph KoshyIf this option is not specified, mapping information is not written. 13049874f6eSJoseph KoshyArgument 13149874f6eSJoseph Koshy.Ar mapfilename 13249874f6eSJoseph Koshymay be a 13349874f6eSJoseph Koshy.Dq Li - 13449874f6eSJoseph Koshyin which case this mapping information is sent to the output 13549874f6eSJoseph Koshyfile configured by the 13649874f6eSJoseph Koshy.Fl o 13749874f6eSJoseph Koshyoption. 138ebccf1e3SJoseph Koshy.It Fl O Ar logfilename 13921ce09caSJoseph KoshySend logging output to file 140ebccf1e3SJoseph Koshy.Ar logfilename . 141302cbb90SJoseph KoshyIf 142302cbb90SJoseph Koshy.Ar logfilename 143302cbb90SJoseph Koshyis of the form 144302cbb90SJoseph Koshy.Ar hostname Ns : Ns Ar port , 145302cbb90SJoseph Koshywhere 146302cbb90SJoseph Koshy.Ar hostname 147302cbb90SJoseph Koshydoes not start with a 148bc84aa4bSRuslan Ermilov.Ql \&. 149302cbb90SJoseph Koshyor a 150bc84aa4bSRuslan Ermilov.Ql / , 151302cbb90SJoseph Koshythen 152302cbb90SJoseph Koshy.Nm 153302cbb90SJoseph Koshywill open a network socket to host 154302cbb90SJoseph Koshy.Ar hostname 155302cbb90SJoseph Koshyon port 156302cbb90SJoseph Koshy.Ar port . 157302cbb90SJoseph Koshy.Pp 158302cbb90SJoseph KoshyIf the 159302cbb90SJoseph Koshy.Fl O 160302cbb90SJoseph Koshyoption is not specified and one of the logging options is requested, 161302cbb90SJoseph Koshythen 162f263522aSJoseph Koshy.Nm 16321ce09caSJoseph Koshywill print a textual form of the logged events to the configured 164f263522aSJoseph Koshyoutput file. 165ebccf1e3SJoseph Koshy.It Fl P Ar event-spec 166ebccf1e3SJoseph KoshyAllocate a process mode sampling PMC measuring hardware events 167ebccf1e3SJoseph Koshyspecified in 168ebccf1e3SJoseph Koshy.Ar event-spec . 169f263522aSJoseph Koshy.It Fl R Ar logfilename 170f263522aSJoseph KoshyPerform offline analysis using sampling data in file 171f263522aSJoseph Koshy.Ar logfilename . 172ebccf1e3SJoseph Koshy.It Fl S Ar event-spec 173ebccf1e3SJoseph KoshyAllocate a system mode sampling PMC measuring hardware events 174ebccf1e3SJoseph Koshyspecified in 175ebccf1e3SJoseph Koshy.Ar event-spec . 176f263522aSJoseph Koshy.It Fl W 177f263522aSJoseph KoshyToggle logging the incremental counts seen by the threads of a 178f263522aSJoseph Koshytracked process each time they are scheduled on a CPU. 179f263522aSJoseph KoshyThis is an experimental feature intended to help analyse the 180f263522aSJoseph Koshydynamic behaviour of processes in the system. 181f263522aSJoseph KoshyIt may incur substantial overhead if enabled. 182f263522aSJoseph KoshyThe default is for this feature to be disabled. 183ee4910b1SJoseph Koshy.It Fl c Ar cpu-spec 184ee4910b1SJoseph KoshySet the cpus for subsequent system mode PMCs specified on the 185ebccf1e3SJoseph Koshycommand line to 186ee4910b1SJoseph Koshy.Ar cpu-spec . 187ee4910b1SJoseph KoshyArgument 188ee4910b1SJoseph Koshy.Ar cpu-spec 189ee4910b1SJoseph Koshyis a comma separated list of CPU numbers, or the literal 190ee4910b1SJoseph Koshy.Sq * 191ee4910b1SJoseph Koshydenoting all CPUs. 192ee4910b1SJoseph KoshyThe default is to allocate system mode PMCs on all CPUs. 193ebccf1e3SJoseph Koshy.It Fl d 194ebccf1e3SJoseph KoshyToggle between process mode PMCs measuring events for the target 195ebccf1e3SJoseph Koshyprocess' current and future children or only measuring events for 196f263522aSJoseph Koshythe target process. 197ebccf1e3SJoseph KoshyThe default is to measure events for the target process alone. 198f263522aSJoseph Koshy.It Fl g 1991fdbf256SJoseph KoshyProduce flat execution profiles in a format compatible with 200f263522aSJoseph Koshy.Xr gprof 1 . 2011fdbf256SJoseph KoshyA separate profile file is generated for each executable object 2021fdbf256SJoseph Koshyencountered. 2031fdbf256SJoseph KoshyProfile files are placed in sub-directories named by their PMC 2041fdbf256SJoseph Koshyevent name. 20549874f6eSJoseph Koshy.It Fl k Ar kerneldir 20649874f6eSJoseph KoshySet the pathname of the kernel directory to argument 20749874f6eSJoseph Koshy.Ar kerneldir . 20849874f6eSJoseph KoshyThis directory specifies where 20949874f6eSJoseph Koshy.Nm 21049874f6eSJoseph Koshyshould look for the kernel and its modules. 21115139246SJoseph KoshyThe default is 21249874f6eSJoseph Koshy.Pa /boot/kernel . 213ebccf1e3SJoseph Koshy.It Fl n Ar rate 214ebccf1e3SJoseph KoshySet the default sampling rate for subsequent sampling mode 215ebccf1e3SJoseph KoshyPMCs specified on the command line. 216ebccf1e3SJoseph KoshyThe default is to configure PMCs to sample the CPU's instruction 217ebccf1e3SJoseph Koshypointer every 65536 events. 218ebccf1e3SJoseph Koshy.It Fl o Ar outputfile 21921ce09caSJoseph KoshySend counter readings and textual representations of logged data 220ebccf1e3SJoseph Koshyto file 221ebccf1e3SJoseph Koshy.Ar outputfile . 222ebccf1e3SJoseph KoshyThe default is to send output to 223ebccf1e3SJoseph Koshy.Pa stderr . 224ebccf1e3SJoseph Koshy.It Fl p Ar event-spec 225ebccf1e3SJoseph KoshyAllocate a process mode counting PMC measuring hardware events 226ebccf1e3SJoseph Koshyspecified in 227ebccf1e3SJoseph Koshy.Ar event-spec . 22849874f6eSJoseph Koshy.It Fl q 22949874f6eSJoseph KoshyDecrease verbosity. 23049874f6eSJoseph Koshy.It Fl r Ar fsroot 23149874f6eSJoseph KoshySet the top of the filesystem hierarchy under which executables 23249874f6eSJoseph Koshyare located to argument 23349874f6eSJoseph Koshy.Ar fsroot . 23449874f6eSJoseph KoshyThe default is 23549874f6eSJoseph Koshy.Pa / . 236ebccf1e3SJoseph Koshy.It Fl s Ar event-spec 237ebccf1e3SJoseph KoshyAllocate a system mode counting PMC measuring hardware events 238ebccf1e3SJoseph Koshyspecified in 239ebccf1e3SJoseph Koshy.Ar event-spec . 240ebccf1e3SJoseph Koshy.It Fl t Ar pid 241ebccf1e3SJoseph KoshyAttach all process mode PMCs allocated to the process with PID 242ebccf1e3SJoseph Koshy.Ar pid . 243ebccf1e3SJoseph KoshyThe option is not allowed in conjunction with specifying a 244ebccf1e3SJoseph Koshycommand using 245ebccf1e3SJoseph Koshy.Ar command . 24649874f6eSJoseph Koshy.It Fl v 24749874f6eSJoseph KoshyIncrease verbosity. 248ebccf1e3SJoseph Koshy.It Fl w Ar secs 249ebccf1e3SJoseph KoshyPrint the values of all counting mode PMCs every 250ebccf1e3SJoseph Koshy.Ar secs 251ebccf1e3SJoseph Koshyseconds. 252ebccf1e3SJoseph KoshyThe argument 253ebccf1e3SJoseph Koshy.Ar secs 254ebccf1e3SJoseph Koshymay be a fractional value. 255ebccf1e3SJoseph KoshyThe default interval is 5 seconds. 256ebccf1e3SJoseph Koshy.El 257ebccf1e3SJoseph Koshy.Pp 258ebccf1e3SJoseph KoshyIf 259ebccf1e3SJoseph Koshy.Ar command 260ebccf1e3SJoseph Koshyis specified, it is executed using 261ebccf1e3SJoseph Koshy.Xr execvp 3 . 262ebccf1e3SJoseph Koshy.Sh EXAMPLES 263ebccf1e3SJoseph KoshyTo perform system-wide statistical sampling on an AMD Athlon CPU with 264ebccf1e3SJoseph Koshysamples taken every 32768 instruction retirals and data being sampled 265ebccf1e3SJoseph Koshyto file 26621ce09caSJoseph Koshy.Pa sample.stat , 267ebccf1e3SJoseph Koshyuse: 26800028966SRobert Watson.Dl "pmcstat -O sample.stat -n 32768 -S k7-retired-instructions" 269ebccf1e3SJoseph Koshy.Pp 270ebccf1e3SJoseph KoshyTo execute 27121ce09caSJoseph Koshy.Nm mozilla 272ebccf1e3SJoseph Koshyand measure the number of data cache misses suffered 273ebccf1e3SJoseph Koshyby it and its children every 12 seconds on an AMD Athlon, use: 27421ce09caSJoseph Koshy.Dl "pmcstat -d -w 12 -p k7-dc-misses mozilla" 2751fdbf256SJoseph Koshy.Pp 276ee4910b1SJoseph KoshyTo count instruction tlb-misses on CPUs 0 and 2 on a Intel 277ee4910b1SJoseph KoshyPentium Pro/Pentium III SMP system use: 278ee4910b1SJoseph Koshy.Dl "pmcstat -c 0,2 -s p6-itlb-miss" 279ee4910b1SJoseph Koshy.Pp 280ee4910b1SJoseph KoshyTo perform system-wide sampling on all configured processors 281ee4910b1SJoseph Koshybased on processor instructions retired use: 2821fdbf256SJoseph Koshy.Dl "pmcstat -S instructions -O /tmp/sample.out" 2831fdbf256SJoseph Koshy.Pp 284302cbb90SJoseph KoshyTo send the generated event log to a remote machine use: 285302cbb90SJoseph Koshy.Dl "pmcstat -S instructions -O remotehost:port" 286302cbb90SJoseph KoshyOn the remote machine, the sample log can be collected using 287302cbb90SJoseph Koshy.Xr nc 1 : 288302cbb90SJoseph Koshy.Dl "nc -l remotehost port > /tmp/sample.out" 289302cbb90SJoseph Koshy.Pp 2901fdbf256SJoseph KoshyTo generate 2911fdbf256SJoseph Koshy.Xr gprof 1 2921fdbf256SJoseph Koshycompatible flat profiles from a sample file use: 2931fdbf256SJoseph Koshy.Dl "pmcstat -R /tmp/sample.out -g" 294ebccf1e3SJoseph Koshy.Sh DIAGNOSTICS 29521ce09caSJoseph Koshy.Ex -std 296ebccf1e3SJoseph Koshy.Sh SEE ALSO 297f263522aSJoseph Koshy.Xr gprof 1 , 298302cbb90SJoseph Koshy.Xr nc 1 , 299ebccf1e3SJoseph Koshy.Xr execvp 3 , 300ebccf1e3SJoseph Koshy.Xr pmc 3 , 30121ce09caSJoseph Koshy.Xr pmclog 3 , 302ebccf1e3SJoseph Koshy.Xr hwpmc 4 , 303ebccf1e3SJoseph Koshy.Xr pmccontrol 8 , 304ebccf1e3SJoseph Koshy.Xr sysctl 8 30521ce09caSJoseph Koshy.Sh HISTORY 30621ce09caSJoseph KoshyThe 30721ce09caSJoseph Koshy.Nm 30821ce09caSJoseph Koshyutility first appeared in 30921ce09caSJoseph Koshy.Fx 6.0 . 3101fdbf256SJoseph KoshyIt is 3111fdbf256SJoseph Koshy.Ud 31221ce09caSJoseph Koshy.Sh AUTHORS 31321ce09caSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org 3149f8adcefSJoseph Koshy.Sh BUGS 315bc84aa4bSRuslan ErmilovThe 3169f8adcefSJoseph Koshy.Nm 317bc84aa4bSRuslan Ermilovutility cannot yet analyse 318302cbb90SJoseph Koshy.Xr hwpmc 4 319302cbb90SJoseph Koshylogs generated by non-native architectures. 320