xref: /freebsd/usr.sbin/pmcstat/pmcstat.8 (revision 9f8adcef84f37437d7a5af5fb821ef10a3715d95)
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.\"
261fdbf256SJoseph Koshy.Dd July 1, 2005
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
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
4515139246SJoseph Koshy.Op Fl k Ar kernelfile
4621ce09caSJoseph Koshy.Op Fl n Ar rate
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
5121ce09caSJoseph Koshy.Op Fl w Ar secs
5221ce09caSJoseph Koshy.Op Ar command Op Ar 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
8721ce09caSJoseph Koshyoverhead, may be configured to be printed in text form 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
12021ce09caSJoseph KoshySend logging output to file
121ebccf1e3SJoseph Koshy.Ar logfilename .
122f263522aSJoseph KoshyIf this option is not specified and one of the logging options
123f263522aSJoseph Koshyis requested, then
124f263522aSJoseph Koshy.Nm
12521ce09caSJoseph Koshywill print a textual form of the logged events 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
1561fdbf256SJoseph KoshyProduce flat execution profiles in a format compatible with
157f263522aSJoseph Koshy.Xr gprof 1 .
1581fdbf256SJoseph KoshyA separate profile file is generated for each executable object
1591fdbf256SJoseph Koshyencountered.
1601fdbf256SJoseph KoshyProfile files are placed in sub-directories named by their PMC
1611fdbf256SJoseph Koshyevent name.
16215139246SJoseph Koshy.It Fl k Ar kernelfile
16315139246SJoseph KoshySet the pathname of the kernel to argument
16415139246SJoseph Koshy.Ar kernelfile .
16515139246SJoseph KoshyThe default is
1661fdbf256SJoseph Koshy.Pa /boot/kernel/kernel .
167ebccf1e3SJoseph Koshy.It Fl n Ar rate
168ebccf1e3SJoseph KoshySet the default sampling rate for subsequent sampling mode
169ebccf1e3SJoseph KoshyPMCs specified on the command line.
170ebccf1e3SJoseph KoshyThe default is to configure PMCs to sample the CPU's instruction
171ebccf1e3SJoseph Koshypointer every 65536 events.
172ebccf1e3SJoseph Koshy.It Fl o Ar outputfile
17321ce09caSJoseph KoshySend counter readings and textual representations of logged data
174ebccf1e3SJoseph Koshyto file
175ebccf1e3SJoseph Koshy.Ar outputfile .
176ebccf1e3SJoseph KoshyThe default is to send output to
177ebccf1e3SJoseph Koshy.Pa stderr .
178ebccf1e3SJoseph Koshy.It Fl p Ar event-spec
179ebccf1e3SJoseph KoshyAllocate a process mode counting PMC measuring hardware events
180ebccf1e3SJoseph Koshyspecified in
181ebccf1e3SJoseph Koshy.Ar event-spec .
182ebccf1e3SJoseph Koshy.It Fl s Ar event-spec
183ebccf1e3SJoseph KoshyAllocate a system mode counting PMC measuring hardware events
184ebccf1e3SJoseph Koshyspecified in
185ebccf1e3SJoseph Koshy.Ar event-spec .
186ebccf1e3SJoseph Koshy.It Fl t Ar pid
187ebccf1e3SJoseph KoshyAttach all process mode PMCs allocated to the process with PID
188ebccf1e3SJoseph Koshy.Ar pid .
189ebccf1e3SJoseph KoshyThe option is not allowed in conjunction with specifying a
190ebccf1e3SJoseph Koshycommand using
191ebccf1e3SJoseph Koshy.Ar command .
192ebccf1e3SJoseph Koshy.It Fl w Ar secs
193ebccf1e3SJoseph KoshyPrint the values of all counting mode PMCs every
194ebccf1e3SJoseph Koshy.Ar secs
195ebccf1e3SJoseph Koshyseconds.
196ebccf1e3SJoseph KoshyThe argument
197ebccf1e3SJoseph Koshy.Ar secs
198ebccf1e3SJoseph Koshymay be a fractional value.
199ebccf1e3SJoseph KoshyThe default interval is 5 seconds.
200ebccf1e3SJoseph Koshy.El
201ebccf1e3SJoseph Koshy.Pp
202ebccf1e3SJoseph KoshyIf
203ebccf1e3SJoseph Koshy.Ar command
204ebccf1e3SJoseph Koshyis specified, it is executed using
205ebccf1e3SJoseph Koshy.Xr execvp 3 .
206ebccf1e3SJoseph Koshy.Sh EXAMPLES
207ebccf1e3SJoseph KoshyTo perform system-wide statistical sampling on an AMD Athlon CPU with
208ebccf1e3SJoseph Koshysamples taken every 32768 instruction retirals and data being sampled
209ebccf1e3SJoseph Koshyto file
21021ce09caSJoseph Koshy.Pa sample.stat ,
211ebccf1e3SJoseph Koshyuse:
21200028966SRobert Watson.Dl "pmcstat -O sample.stat -n 32768 -S k7-retired-instructions"
213ebccf1e3SJoseph Koshy.Pp
214ebccf1e3SJoseph KoshyTo execute
21521ce09caSJoseph Koshy.Nm mozilla
216ebccf1e3SJoseph Koshyand measure the number of data cache misses suffered
217ebccf1e3SJoseph Koshyby it and its children every 12 seconds on an AMD Athlon, use:
21821ce09caSJoseph Koshy.Dl "pmcstat -d -w 12 -p k7-dc-misses mozilla"
2191fdbf256SJoseph Koshy.Pp
2201fdbf256SJoseph KoshyTo collect a system-wide samples driven by processor instructions executed
2211fdbf256SJoseph Koshyuse:
2221fdbf256SJoseph Koshy.Dl "pmcstat -S instructions -O /tmp/sample.out"
2231fdbf256SJoseph Koshy.Pp
2241fdbf256SJoseph KoshyTo generate
2251fdbf256SJoseph Koshy.Xr gprof 1
2261fdbf256SJoseph Koshycompatible flat profiles from a sample file use:
2271fdbf256SJoseph Koshy.Dl "pmcstat -R /tmp/sample.out -g"
228ebccf1e3SJoseph Koshy.Sh DIAGNOSTICS
22921ce09caSJoseph Koshy.Ex -std
230ebccf1e3SJoseph Koshy.Sh SEE ALSO
231f263522aSJoseph Koshy.Xr gprof 1 ,
232ebccf1e3SJoseph Koshy.Xr execvp 3 ,
233ebccf1e3SJoseph Koshy.Xr pmc 3 ,
23421ce09caSJoseph Koshy.Xr pmclog 3 ,
235ebccf1e3SJoseph Koshy.Xr hwpmc 4 ,
236ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
237ebccf1e3SJoseph Koshy.Xr sysctl 8
23821ce09caSJoseph Koshy.Sh HISTORY
23921ce09caSJoseph KoshyThe
24021ce09caSJoseph Koshy.Nm
24121ce09caSJoseph Koshyutility first appeared in
24221ce09caSJoseph Koshy.Fx 6.0 .
2431fdbf256SJoseph KoshyIt is
2441fdbf256SJoseph Koshy.Ud
24521ce09caSJoseph Koshy.Sh AUTHORS
24621ce09caSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org
2479f8adcefSJoseph Koshy.Sh BUGS
2489f8adcefSJoseph KoshyOn AMD64 platforms
2499f8adcefSJoseph Koshy.Nm
2509f8adcefSJoseph Koshydoes not yet handle profiles with samples from 32 bit executables.
251