PMCSTAT(8)
π¦ pmcstat(8) π¦
okay bestie, this is the System Manager's Manual page for performance measurement with performance monitoring hardware, and it's lowkey iconic. no cap, it's giving "your CPU is a main character and I have receipts." π
πΈ NAME πΈ
pmcstat β performance measurement with performance monitoring hardware
β¨ SYNOPSIS β¨
pmcstat [-A] [-C] [-D pathname] [-E] [-F pathname] [-G pathname] [-I]
[-L] [-M mapfilename] [-N] [-O logfilename] [-P event-spec]
[-R logfilename] [-S event-spec] [-T] [-U] [-W] [-a pathname]
[-c cpu-spec] [-d] [-e] [-f pluginopt] [-g] [-i lwp] [-l secs]
[-m pathname] [-n rate] [-o outputfile] [-p event-spec] [-q]
[-r fsroot] [-s event-spec] [-t process-spec] [-u event-spec]
[-v] [-w secs] [-z graphdepth] [command [args]]
π DESCRIPTION π
okay so pmcstat measures system performance using the facilities provided by hwpmc(4). it can measure both hardware events seen by the system as a whole and those seen when a specified set of processes are executing on the system's CPUs.
if you're targeting a specific set of processes (for example, you passed -t process-spec, or you specified a command line using command), then measurement happens until command exits, or until all the target processes specified by the -t process-spec options exit, or until the user interrupts pmcstat. if you're not targeting a specific set of processes, pmcstat does system-wide measurements until the user interrupts it. π
a given invocation of pmcstat can mix allocations of system-mode and process-mode PMCs, of both counting and sampling flavors. the values of all counting PMCs are printed in human readable form at regular intervals by pmcstat. the format of pmcstat's human-readable textual output is not stable, and could change in the future β so don't get too attached to parsing it, bestie. the output of sampling PMCs may be configured to go to a log file for subsequent offline analysis, or β at the expense of greater overhead β may be configured to be printed in text form on the fly.
hardware events to measure are specified to pmcstat using event specifier strings event-spec. the syntax of these event specifiers is machine dependent and is documented in pmc(3).
a process-mode PMC may be configured to be inheritable by the target process' current and future children.
π OPTIONS π
the following options are available:
-Aβ skip symbol lookup and display address instead.-Cβ toggle between showing cumulative or incremental counts for subsequent counting mode PMCs specified on the command line. the default is to show incremental counts.-D pathnameβ create files with per-program samples in the directory named bypathname. the default is to create these files in the current directory.-Eβ toggle showing per-process counts at the time a tracked process exits for subsequent process-mode PMCs specified on the command line. this option is useful for mapping the performance characteristics of a complex pipeline of processes when used in conjunction with the-doption. the default is to not enable per-process tracking.-F pathnameβ print calltree (Kcachegrind) information to filepathname. if argumentpathnameis a-, this information is sent to the output file specified by the-ooption.-G pathnameβ print callchain information to filepathname. if argumentpathnameis a-, this information is sent to the output file specified by the-ooption.-Iβ show the offset of the instruction pointer into the symbol.-Lβ list all event names.-M mapfilenameβ write the mapping between executable objects encountered in the event log and the abbreviated pathnames used forgprof(1)profiles to filemapfilename. if this option is not specified, mapping information is not written. argumentmapfilenamemay be a-, in which case this mapping information is sent to the output file configured by the-ooption.-Nβ toggle capturing callchain information for subsequent sampling PMCs. the default is for sampling PMCs to capture callchain information.-O logfilenameβ send logging output to filelogfilename. iflogfilenameis of the formhostname:port, wherehostnamedoes not start with a.or a/, thenpmcstatwill open a network socket to hosthostnameon portport. also, if-Ois not specified and one of the logging options is requested, thenpmcstatwill print a textual form of the logged events to the configured output file.-P event-specβ allocate a process mode sampling PMC measuring hardware events specified inevent-spec.-R logfilenameβ perform offline analysis using sampling data in filelogfilename.-S event-specβ allocate a system mode sampling PMC measuring hardware events specified inevent-spec.-Tβ use atop(1)-like mode for sampling PMCs. the following hotkeys can be used:Aβ toggle symbol resolutionCtrl+aβ switch to accumulative modeCtrl+dβ switch to delta modefβ represent the βfβ cost under threshold as a dot (calltree only)Iβ toggle showing offsets into symbolsmβ merge PMCsnβ change viewpβ show next PMCqβ quitSpaceβ pause
-Uβ toggle capturing user-space call traces while in kernel mode. the default is for sampling PMCs to capture user-space callchain information while in user-space mode, and kernel callchain information while in kernel mode.-Wβ toggle logging the incremental counts seen by the threads of a tracked process each time they are scheduled on a CPU. this is an experimental feature intended to help analyse the dynamic behaviour of processes in the system. it may incur substantial overhead if enabled. the default is for this feature to be disabled.-a pathnameβ perform a symbol and file:line lookup for each address in each callgraph and save the output topathname. unlike-m, which only resolves the first symbol in the graph, this resolves every node in the callgraph, or prints out addresses if no lookup information is available. this option requires the-Roption to read in samples that were previously collected and saved with the-Ooption.-c cpu-specβ set the cpus for subsequent system mode PMCs specified on the command line tocpu-spec. argumentcpu-specis a comma separated list of CPU numbers, or the literal*denoting all available CPUs. the default is to allocate system mode PMCs on all available CPUs.-dβ toggle between process mode PMCs measuring events for the target process' current and future children or only measuring events for the target process. the default is to measure events for the target process alone. (it has to be passed in the command line prior to-p,-s,-P, or-S).-eβ specify that thegprofprofile files will use a wide history counter. these files are produced in a format compatible withgprof(1). however, other tools that cannot fully parse a BSD-style gmon header might be unable to correctly parse these files.-f pluginoptβ pass option string to the active plugin.threshold=<float>β do not display cost under specified value (Top).skiplink=0|1β replace node with cost under threshold by a dot (Top).
-gβ produce profiles in a format compatible withgprof(1). a separate profile file is generated for each executable object encountered. profile files are placed in sub-directories named by their PMC event name.-i lwpβ filter on thread IDlwp, which you can get fromps(1) -o lwp.-l secsβ set system-wide performance measurement duration forsecsseconds. the argumentsecsmay be a fractional value.-m pathnameβ print the sampled PCs with the name, the start and ending addresses of the function they live in. thepathnameargument is mandatory and indicates where the information will be stored. if argumentpathnameis a-, this information is sent to the output file specified by the-ooption. this option requires the-Roption to read in samples that were previously collected and saved with the-Ooption.-n rateβ set the default sampling rate for subsequent sampling mode PMCs specified on the command line. the default is to configure PMCs to sample the CPU's instruction pointer every65536events.-o outputfileβ send counter readings and textual representations of logged data to fileoutputfile. the default is to send output tostderrwhen collecting live data and tostdoutwhen processing a pre-existing logfile.-p event-specβ allocate a process mode counting PMC measuring hardware events specified inevent-spec.-qβ decrease verbosity.-r fsrootβ set the top of the filesystem hierarchy under which executables are located to argumentfsroot. the default is/.-s event-specβ allocate a system mode counting PMC measuring hardware events specified inevent-spec.-t process-specβ attach process mode PMCs to the processes named by argumentprocess-spec. argumentprocess-specmay be a non-negative integer denoting a specific process id, or a regular expression for selecting processes based on their command names.-u event-specβ provide short description of event.-vβ increase verbosity.-w secsβ print the values of all counting mode PMCs or sampling mode PMCs for top mode everysecsseconds. the argumentsecsmay be a fractional value. the default interval is5seconds.-z graphdepthβ when printing system-wide callgraphs, limit callgraphs to the depth specified by argumentgraphdepth.
if command is specified, it is executed using execvp(3).
π EXAMPLES π
Ok bestie, this is the part where it all clicks. These are the copy-paste-and-go recipes, and honestly? They're giving tutorial energy. π
To do a system-wide statistical sampling on an AMD Athlon CPU, with samples taken every 32768 instruction retirals, and the data dumped into the file sample.stat, you'd say:
pmcstat -O sample.stat -n 32768 -S k7-retired-instructions
To run firefox and measure how many data cache misses it (and its children, the little nepo babies) suffer through every 12 seconds, on an AMD Athlon, use:
pmcstat -d -w 12 -p k7-dc-misses firefox
To measure instructions retired for all processes named βemacsβ, do:
pmcstat -t '^emacs$' -p instructions
Same energy, but only for a period of 10 seconds? Easy:
pmcstat -t '^emacs$' -p instructions sleep 10
To count instruction tlb-misses on CPUs 0 and 2 on an Intel Pentium Pro/Pentium III SMP system, use:
pmcstat -c 0,2 -s p6-itlb-miss
To collect profiling info for one specific process, pid 1234, based on the instruction cache misses it's been seeing, use:
pmcstat -P ic-misses -t 1234 -O /tmp/sample.out
To do system-wide sampling across all configured processors, based on processor instructions retired, use:
pmcstat -S instructions -O /tmp/sample.out
And if callgraph capture is not the vibe for you, use:
pmcstat -N -S instructions -O /tmp/sample.out
To send the generated event log to a remote machine, use:
pmcstat -S instructions -O remotehost:port
Then on that remote machine, the sample log can be collected using nc(1):
nc -l remotehost port > /tmp/sample.out
To generate gprof(1)-compatible profiles from a sample file, use:
pmcstat -R /tmp/sample.out -g
And to print a system-wide profile with callgraphs out to the file foo.graph, use:
pmcstat -R /tmp/sample.out -G foo.graph
π DIAGNOSTICS π
If the option -v is specified, pmcstat may issue the following diagnostic messages β think of these as the receipts it hands you back. π§Ύ
#callchain/dubious-framesβ the number of callchain records that had an βimpossibleβ value for a return address. Like, ma'am, that address cannot exist. π#exec handling errorsβ the number ofexecve(2)events in the log file that named executables which could not be analyzed.#exec/elfβ the number ofexecve(2)events that named ELF executables.#exec/unknownβ the number ofexecve(2)events that named executables with unrecognized formats.#samples/totalβ the total number of samples in the log file.#samples/unclaimedβ the number of samples that could not be correlated to a known executable object (i.e., to an executable, shared library, the kernel or the runtime loader). These are the samples that ghosted us. π#samples/unknown-objectβ the number of samples that were associated with an executable with an unrecognized object format.
The pmcstat utility exits 0 on success, and >0 if an error occurs. Periodt. β¨
π COMPATIBILITY π
Real talk, there are some limits here. Because of the limitations of the gmon.out file format, gprof(1)-compatible profiles generated by the -g option do not contain information about calls that cross executable boundaries. Also, the generated gmon.out files are only meaningful for native executables. No cap, that's just how it is.
π¦ SEE ALSO π¦
gprof(1), nc(1), execvp(3), pmc(3), pmclog(3), hwpmc(4), pmccontrol(8), sysctl(8)
Go read them, bestie. iykyk. π
β HISTORY β
The pmcstat utility first appeared in FreeBSD 6.0. Iconic behavior from day one, honestly. π
π AUTHORS π
Joseph Koshy <jkoshy@FreeBSD.org> β thank you for your service, king. π«Ά
π BUGS π
The pmcstat utility cannot yet analyse hwpmc(4) logs generated by non-native architectures. She's doing her best, ok?? π
π That's the whole page, bestie β this Debian build is dated April 19, 2025, so go forth and profile like the main character you are. Stay slay, keep your callchains tidy, and remember: samples unclaimed are just samples that haven't found their people yet. β¨ππ¦
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 2003-2008 Joseph Koshy
- Copyright (c) 2007 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms