1.\" Copyright (c) 2003-2008 Joseph Koshy 2.\" Copyright (c) 2007 The FreeBSD Foundation 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" This software is provided by Joseph Koshy ``as is'' and 15.\" any express or implied warranties, including, but not limited to, the 16.\" implied warranties of merchantability and fitness for a particular purpose 17.\" are disclaimed. in no event shall Joseph Koshy be liable 18.\" for any direct, indirect, incidental, special, exemplary, or consequential 19.\" damages (including, but not limited to, procurement of substitute goods 20.\" or services; loss of use, data, or profits; or business interruption) 21.\" however caused and on any theory of liability, whether in contract, strict 22.\" liability, or tort (including negligence or otherwise) arising in any way 23.\" out of the use of this software, even if advised of the possibility of 24.\" such damage. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd September 19, 2008 29.Dt PMCSTAT 8 30.Os 31.Sh NAME 32.Nm pmcstat 33.Nd "performance measurement with performance monitoring hardware" 34.Sh SYNOPSIS 35.Nm 36.Op Fl C 37.Op Fl D Ar pathname 38.Op Fl E 39.Op Fl F Ar pathname 40.Op Fl G Ar pathname 41.Op Fl M Ar mapfilename 42.Op Fl N 43.Op Fl O Ar logfilename 44.Op Fl P Ar event-spec 45.Op Fl R Ar logfilename 46.Op Fl S Ar event-spec 47.Op Fl T 48.Op Fl W 49.Op Fl c Ar cpu-spec 50.Op Fl d 51.Op Fl f Ar pluginopt 52.Op Fl g 53.Op Fl k Ar kerneldir 54.Op Fl m Ar pathname 55.Op Fl n Ar rate 56.Op Fl o Ar outputfile 57.Op Fl p Ar event-spec 58.Op Fl q 59.Op Fl r Ar fsroot 60.Op Fl s Ar event-spec 61.Op Fl t Ar process-spec 62.Op Fl v 63.Op Fl w Ar secs 64.Op Fl z Ar graphdepth 65.Op Ar command Op Ar args 66.Sh DESCRIPTION 67The 68.Nm 69utility measures system performance using the facilities provided by 70.Xr hwpmc 4 . 71.Pp 72The 73.Nm 74utility can measure both hardware events seen by the system as a 75whole, and those seen when a specified set of processes are executing 76on the system's CPUs. 77If a specific set of processes is being targeted (for example, 78if the 79.Fl t Ar process-spec 80option is specified, or if a command line is specified using 81.Ar command ) , 82then measurement occurs till 83.Ar command 84exits, or till all target processes specified by the 85.Fl t Ar process-spec 86options exit, or till the 87.Nm 88utility is interrupted by the user. 89If a specific set of processes is not targeted for measurement, then 90.Nm 91will perform system-wide measurements till interrupted by the 92user. 93.Pp 94A given invocation of 95.Nm 96can mix allocations of system-mode and process-mode PMCs, of both 97counting and sampling flavors. 98The values of all counting PMCs are printed in human readable form 99at regular intervals by 100.Nm . 101The output of sampling PMCs may be configured to go to a log file for 102subsequent offline analysis, or, at the expense of greater 103overhead, may be configured to be printed in text form on the fly. 104.Pp 105Hardware events to measure are specified to 106.Nm 107using event specifier strings 108.Ar event-spec . 109The syntax of these event specifiers is machine dependent and is 110documented in 111.Xr pmc 3 . 112.Pp 113A process-mode PMC may be configured to be inheritable by the target 114process' current and future children. 115.Sh OPTIONS 116The following options are available: 117.Bl -tag -width indent 118.It Fl C 119Toggle between showing cumulative or incremental counts for 120subsequent counting mode PMCs specified on the command line. 121The default is to show incremental counts. 122.It Fl D Ar pathname 123Create files with per-program samples in the directory named 124by 125.Ar pathname . 126The default is to create these files in the current directory. 127.It Fl E 128Toggle showing per-process counts at the time a tracked process 129exits for subsequent process-mode PMCs specified on the command line. 130This option is useful for mapping the performance characteristics of a 131complex pipeline of processes when used in conjunction with the 132.Fl d 133option. 134The default is to not to enable per-process tracking. 135.It Fl F Ar pathname 136Print calltree (Kcachegrind) information to file 137.Ar pathname . 138If argument 139.Ar pathname 140is a 141.Dq Li - 142this information is sent to the output file specified by the 143.Fl o 144option. 145.It Fl G Ar pathname 146Print callchain information to file 147.Ar pathname . 148If argument 149.Ar pathname 150is a 151.Dq Li - 152this information is sent to the output file specified by the 153.Fl o 154option. 155.It Fl M Ar mapfilename 156Write the mapping between executable objects encountered in the event 157log and the abbreviated pathnames used for 158.Xr gprof 1 159profiles to file 160.Ar mapfilename . 161If this option is not specified, mapping information is not written. 162Argument 163.Ar mapfilename 164may be a 165.Dq Li - 166in which case this mapping information is sent to the output 167file configured by the 168.Fl o 169option. 170.It Fl N 171Toggle capturing callchain information for subsequent sampling PMCs. 172The default is for sampling PMCs to capture callchain information. 173.It Fl O Ar logfilename 174Send logging output to file 175.Ar logfilename . 176If 177.Ar logfilename 178is of the form 179.Ar hostname Ns : Ns Ar port , 180where 181.Ar hostname 182does not start with a 183.Ql \&. 184or a 185.Ql / , 186then 187.Nm 188will open a network socket to host 189.Ar hostname 190on port 191.Ar port . 192.Pp 193If the 194.Fl O 195option is not specified and one of the logging options is requested, 196then 197.Nm 198will print a textual form of the logged events to the configured 199output file. 200.It Fl P Ar event-spec 201Allocate a process mode sampling PMC measuring hardware events 202specified in 203.Ar event-spec . 204.It Fl R Ar logfilename 205Perform offline analysis using sampling data in file 206.Ar logfilename . 207.It Fl S Ar event-spec 208Allocate a system mode sampling PMC measuring hardware events 209specified in 210.Ar event-spec . 211.It Fl T 212Use a top like mode for sampling PMCs. The following hotkeys 213can be used: 'c+a' switch to accumulative mode, 'c+d' switch 214to delta mode, 'm' merge PMCs, 'n' change view, 'p' show next 215PMC, ' ' pause, 'q' quit. calltree only: 'f' cost under threshold 216is seen as a dot. 217.It Fl W 218Toggle logging the incremental counts seen by the threads of a 219tracked process each time they are scheduled on a CPU. 220This is an experimental feature intended to help analyse the 221dynamic behaviour of processes in the system. 222It may incur substantial overhead if enabled. 223The default is for this feature to be disabled. 224.It Fl c Ar cpu-spec 225Set the cpus for subsequent system mode PMCs specified on the 226command line to 227.Ar cpu-spec . 228Argument 229.Ar cpu-spec 230is a comma separated list of CPU numbers, or the literal 231.Sq * 232denoting all unhalted CPUs. 233The default is to allocate system mode PMCs on all unhalted 234CPUs. 235.It Fl d 236Toggle between process mode PMCs measuring events for the target 237process' current and future children or only measuring events for 238the target process. 239The default is to measure events for the target process alone. 240.It Fl f Ar pluginopt 241Pass option string to the active plugin. 242.br 243threshold=<float> do not display cost under specified value (Top). 244.br 245skiplink=0|1 replace node with cost under threshold by a dot (Top). 246.It Fl g 247Produce profiles in a format compatible with 248.Xr gprof 1 . 249A separate profile file is generated for each executable object 250encountered. 251Profile files are placed in sub-directories named by their PMC 252event name. 253.It Fl k Ar kerneldir 254Set the pathname of the kernel directory to argument 255.Ar kerneldir . 256This directory specifies where 257.Nm 258should look for the kernel and its modules. 259The default is 260.Pa /boot/kernel . 261.It Fl m Ar pathname 262Print the sampled PCs with the name, the start and ending addresses 263of the function within they live. 264The 265.Ar pathname 266argument is mandatory and indicates where the information will be stored. 267If argument 268.Ar pathname 269is a 270.Dq Li - 271this information is sent to the output file specified by the 272.Fl o 273option. 274.It Fl n Ar rate 275Set the default sampling rate for subsequent sampling mode 276PMCs specified on the command line. 277The default is to configure PMCs to sample the CPU's instruction 278pointer every 65536 events. 279.It Fl o Ar outputfile 280Send counter readings and textual representations of logged data 281to file 282.Ar outputfile . 283The default is to send output to 284.Pa stderr 285when collecting live data and to 286.Pa stdout 287when processing a pre-existing logfile. 288.It Fl p Ar event-spec 289Allocate a process mode counting PMC measuring hardware events 290specified in 291.Ar event-spec . 292.It Fl q 293Decrease verbosity. 294.It Fl r Ar fsroot 295Set the top of the filesystem hierarchy under which executables 296are located to argument 297.Ar fsroot . 298The default is 299.Pa / . 300.It Fl s Ar event-spec 301Allocate a system mode counting PMC measuring hardware events 302specified in 303.Ar event-spec . 304.It Fl t Ar process-spec 305Attach process mode PMCs to the processes named by argument 306.Ar process-spec . 307Argument 308.Ar process-spec 309may be a non-negative integer denoting a specific process id, or a 310regular expression for selecting processes based on their command names. 311.It Fl v 312Increase verbosity. 313.It Fl w Ar secs 314Print the values of all counting mode PMCs or sampling mode PMCs 315for top mode every 316.Ar secs 317seconds. 318The argument 319.Ar secs 320may be a fractional value. 321The default interval is 5 seconds. 322.It Fl z Ar graphdepth 323When printing system-wide callgraphs, limit callgraphs to the depth 324specified by argument 325.Ar graphdepth . 326.El 327.Pp 328If 329.Ar command 330is specified, it is executed using 331.Xr execvp 3 . 332.Sh EXAMPLES 333To perform system-wide statistical sampling on an AMD Athlon CPU with 334samples taken every 32768 instruction retirals and data being sampled 335to file 336.Pa sample.stat , 337use: 338.Dl "pmcstat -O sample.stat -n 32768 -S k7-retired-instructions" 339.Pp 340To execute 341.Nm firefox 342and measure the number of data cache misses suffered 343by it and its children every 12 seconds on an AMD Athlon, use: 344.Dl "pmcstat -d -w 12 -p k7-dc-misses firefox" 345.Pp 346To measure instructions retired for all processes named 347.Dq emacs 348use: 349.Dl "pmcstat -t '^emacs$' -p instructions" 350.Pp 351To measure instructions retired for processes named 352.Dq emacs 353for a period of 10 seconds use: 354.Dl "pmcstat -t '^emacs$' -p instructions sleep 10" 355.Pp 356To count instruction tlb-misses on CPUs 0 and 2 on a Intel 357Pentium Pro/Pentium III SMP system use: 358.Dl "pmcstat -c 0,2 -s p6-itlb-miss" 359.Pp 360To collect profiling information for a specific process with pid 1234 361based on instruction cache misses seen by it use: 362.Dl "pmcstat -P ic-misses -t 1234 -O /tmp/sample.out" 363.Pp 364To perform system-wide sampling on all configured processors 365based on processor instructions retired use: 366.Dl "pmcstat -S instructions -O /tmp/sample.out" 367If callgraph capture is not desired use: 368.Dl "pmcstat -N -S instructions -O /tmp/sample.out" 369.Pp 370To send the generated event log to a remote machine use: 371.Dl "pmcstat -S instructions -O remotehost:port" 372On the remote machine, the sample log can be collected using 373.Xr nc 1 : 374.Dl "nc -l remotehost port > /tmp/sample.out" 375.Pp 376To generate 377.Xr gprof 1 378compatible profiles from a sample file use: 379.Dl "pmcstat -R /tmp/sample.out -g" 380.Pp 381To print a system-wide profile with callgraphs to file 382.Pa "foo.graph" 383use: 384.Dl "pmcstat -R /tmp/sample.out -G foo.graph" 385.Sh DIAGNOSTICS 386If option 387.Fl v 388is specified, 389.Nm 390may issue the following diagnostic messages: 391.Bl -diag 392.It "#callchain/dubious-frames" 393The number of callchain records that had an 394.Dq impossible 395value for a return address. 396.It "#exec handling errors" 397The number of 398.Xr exec 2 399events in the log file that named executables that could not be 400analyzed. 401.It "#exec/elf" 402The number of 403.Xr exec 2 404events that named ELF executables. 405.It "#exec/unknown" 406The number of 407.Xr exec 2 408events that named executables with unrecognized formats. 409.It "#samples/total" 410The total number of samples in the log file. 411.It "#samples/unclaimed" 412The number of samples that could not be correlated to a known 413executable object (i.e., to an executable, shared library, the 414kernel or the runtime loader). 415.It "#samples/unknown-object" 416The number of samples that were associated with an executable 417with an unrecognized object format. 418.El 419.Pp 420.Ex -std 421.Sh COMPATIBILITY 422Due to the limitations of the 423.Pa gmon.out 424file format, 425.Xr gprof 1 426compatible profiles generated by the 427.Fl g 428option do not contain information about calls that cross executable 429boundaries. 430The generated 431.Pa gmon.out 432files are also only meaningful for native executables. 433.Sh SEE ALSO 434.Xr gprof 1 , 435.Xr nc 1 , 436.Xr execvp 3 , 437.Xr pmc 3 , 438.Xr pmclog 3 , 439.Xr hwpmc 4 , 440.Xr pmccontrol 8 , 441.Xr sysctl 8 442.Sh HISTORY 443The 444.Nm 445utility first appeared in 446.Fx 6.0 . 447It is 448.Ud 449.Sh AUTHORS 450.An Joseph Koshy Aq jkoshy@FreeBSD.org 451.Sh BUGS 452The 453.Nm 454utility cannot yet analyse 455.Xr hwpmc 4 456logs generated by non-native architectures. 457