xref: /freebsd/usr.sbin/pmcstat/pmcstat.8 (revision 49874f6ea3d305366e9e829e2b93832c99a9c40d)
149874f6eSJoseph Koshy.\" Copyright (c) 2003-2006 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.\"
2649874f6eSJoseph Koshy.Dd March 26, 2006
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
43ebccf1e3SJoseph Koshy.Op Fl c Ar cpu
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 .
141f263522aSJoseph KoshyIf this option is not specified and one of the logging options
142f263522aSJoseph Koshyis requested, then
143f263522aSJoseph Koshy.Nm
14421ce09caSJoseph Koshywill print a textual form of the logged events to the configured
145f263522aSJoseph Koshyoutput file.
146ebccf1e3SJoseph Koshy.It Fl P Ar event-spec
147ebccf1e3SJoseph KoshyAllocate a process mode sampling PMC measuring hardware events
148ebccf1e3SJoseph Koshyspecified in
149ebccf1e3SJoseph Koshy.Ar event-spec .
150f263522aSJoseph Koshy.It Fl R Ar logfilename
151f263522aSJoseph KoshyPerform offline analysis using sampling data in file
152f263522aSJoseph Koshy.Ar logfilename .
153ebccf1e3SJoseph Koshy.It Fl S Ar event-spec
154ebccf1e3SJoseph KoshyAllocate a system mode sampling PMC measuring hardware events
155ebccf1e3SJoseph Koshyspecified in
156ebccf1e3SJoseph Koshy.Ar event-spec .
157f263522aSJoseph Koshy.It Fl W
158f263522aSJoseph KoshyToggle logging the incremental counts seen by the threads of a
159f263522aSJoseph Koshytracked process each time they are scheduled on a CPU.
160f263522aSJoseph KoshyThis is an experimental feature intended to help analyse the
161f263522aSJoseph Koshydynamic behaviour of processes in the system.
162f263522aSJoseph KoshyIt may incur substantial overhead if enabled.
163f263522aSJoseph KoshyThe default is for this feature to be disabled.
164ebccf1e3SJoseph Koshy.It Fl c Ar cpu
165ebccf1e3SJoseph KoshySet the cpu for subsequent system mode PMCs specified on the
166ebccf1e3SJoseph Koshycommand line to
167ebccf1e3SJoseph Koshy.Ar cpu .
168ebccf1e3SJoseph KoshyThe default is to allocate system mode PMCs on CPU zero.
169ebccf1e3SJoseph Koshy.It Fl d
170ebccf1e3SJoseph KoshyToggle between process mode PMCs measuring events for the target
171ebccf1e3SJoseph Koshyprocess' current and future children or only measuring events for
172f263522aSJoseph Koshythe target process.
173ebccf1e3SJoseph KoshyThe default is to measure events for the target process alone.
174f263522aSJoseph Koshy.It Fl g
1751fdbf256SJoseph KoshyProduce flat execution profiles in a format compatible with
176f263522aSJoseph Koshy.Xr gprof 1 .
1771fdbf256SJoseph KoshyA separate profile file is generated for each executable object
1781fdbf256SJoseph Koshyencountered.
1791fdbf256SJoseph KoshyProfile files are placed in sub-directories named by their PMC
1801fdbf256SJoseph Koshyevent name.
18149874f6eSJoseph Koshy.It Fl k Ar kerneldir
18249874f6eSJoseph KoshySet the pathname of the kernel directory to argument
18349874f6eSJoseph Koshy.Ar kerneldir .
18449874f6eSJoseph KoshyThis directory specifies where
18549874f6eSJoseph Koshy.Nm
18649874f6eSJoseph Koshyshould look for the kernel and its modules.
18715139246SJoseph KoshyThe default is
18849874f6eSJoseph Koshy.Pa /boot/kernel .
189ebccf1e3SJoseph Koshy.It Fl n Ar rate
190ebccf1e3SJoseph KoshySet the default sampling rate for subsequent sampling mode
191ebccf1e3SJoseph KoshyPMCs specified on the command line.
192ebccf1e3SJoseph KoshyThe default is to configure PMCs to sample the CPU's instruction
193ebccf1e3SJoseph Koshypointer every 65536 events.
194ebccf1e3SJoseph Koshy.It Fl o Ar outputfile
19521ce09caSJoseph KoshySend counter readings and textual representations of logged data
196ebccf1e3SJoseph Koshyto file
197ebccf1e3SJoseph Koshy.Ar outputfile .
198ebccf1e3SJoseph KoshyThe default is to send output to
199ebccf1e3SJoseph Koshy.Pa stderr .
200ebccf1e3SJoseph Koshy.It Fl p Ar event-spec
201ebccf1e3SJoseph KoshyAllocate a process mode counting PMC measuring hardware events
202ebccf1e3SJoseph Koshyspecified in
203ebccf1e3SJoseph Koshy.Ar event-spec .
20449874f6eSJoseph Koshy.It Fl q
20549874f6eSJoseph KoshyDecrease verbosity.
20649874f6eSJoseph Koshy.It Fl r Ar fsroot
20749874f6eSJoseph KoshySet the top of the filesystem hierarchy under which executables
20849874f6eSJoseph Koshyare located to argument
20949874f6eSJoseph Koshy.Ar fsroot .
21049874f6eSJoseph KoshyThe default is
21149874f6eSJoseph Koshy.Pa / .
212ebccf1e3SJoseph Koshy.It Fl s Ar event-spec
213ebccf1e3SJoseph KoshyAllocate a system mode counting PMC measuring hardware events
214ebccf1e3SJoseph Koshyspecified in
215ebccf1e3SJoseph Koshy.Ar event-spec .
216ebccf1e3SJoseph Koshy.It Fl t Ar pid
217ebccf1e3SJoseph KoshyAttach all process mode PMCs allocated to the process with PID
218ebccf1e3SJoseph Koshy.Ar pid .
219ebccf1e3SJoseph KoshyThe option is not allowed in conjunction with specifying a
220ebccf1e3SJoseph Koshycommand using
221ebccf1e3SJoseph Koshy.Ar command .
22249874f6eSJoseph Koshy.It Fl v
22349874f6eSJoseph KoshyIncrease verbosity.
224ebccf1e3SJoseph Koshy.It Fl w Ar secs
225ebccf1e3SJoseph KoshyPrint the values of all counting mode PMCs every
226ebccf1e3SJoseph Koshy.Ar secs
227ebccf1e3SJoseph Koshyseconds.
228ebccf1e3SJoseph KoshyThe argument
229ebccf1e3SJoseph Koshy.Ar secs
230ebccf1e3SJoseph Koshymay be a fractional value.
231ebccf1e3SJoseph KoshyThe default interval is 5 seconds.
232ebccf1e3SJoseph Koshy.El
233ebccf1e3SJoseph Koshy.Pp
234ebccf1e3SJoseph KoshyIf
235ebccf1e3SJoseph Koshy.Ar command
236ebccf1e3SJoseph Koshyis specified, it is executed using
237ebccf1e3SJoseph Koshy.Xr execvp 3 .
238ebccf1e3SJoseph Koshy.Sh EXAMPLES
239ebccf1e3SJoseph KoshyTo perform system-wide statistical sampling on an AMD Athlon CPU with
240ebccf1e3SJoseph Koshysamples taken every 32768 instruction retirals and data being sampled
241ebccf1e3SJoseph Koshyto file
24221ce09caSJoseph Koshy.Pa sample.stat ,
243ebccf1e3SJoseph Koshyuse:
24400028966SRobert Watson.Dl "pmcstat -O sample.stat -n 32768 -S k7-retired-instructions"
245ebccf1e3SJoseph Koshy.Pp
246ebccf1e3SJoseph KoshyTo execute
24721ce09caSJoseph Koshy.Nm mozilla
248ebccf1e3SJoseph Koshyand measure the number of data cache misses suffered
249ebccf1e3SJoseph Koshyby it and its children every 12 seconds on an AMD Athlon, use:
25021ce09caSJoseph Koshy.Dl "pmcstat -d -w 12 -p k7-dc-misses mozilla"
2511fdbf256SJoseph Koshy.Pp
2521fdbf256SJoseph KoshyTo collect a system-wide samples driven by processor instructions executed
2531fdbf256SJoseph Koshyuse:
2541fdbf256SJoseph Koshy.Dl "pmcstat -S instructions -O /tmp/sample.out"
2551fdbf256SJoseph Koshy.Pp
2561fdbf256SJoseph KoshyTo generate
2571fdbf256SJoseph Koshy.Xr gprof 1
2581fdbf256SJoseph Koshycompatible flat profiles from a sample file use:
2591fdbf256SJoseph Koshy.Dl "pmcstat -R /tmp/sample.out -g"
260ebccf1e3SJoseph Koshy.Sh DIAGNOSTICS
26121ce09caSJoseph Koshy.Ex -std
262ebccf1e3SJoseph Koshy.Sh SEE ALSO
263f263522aSJoseph Koshy.Xr gprof 1 ,
264ebccf1e3SJoseph Koshy.Xr execvp 3 ,
265ebccf1e3SJoseph Koshy.Xr pmc 3 ,
26621ce09caSJoseph Koshy.Xr pmclog 3 ,
267ebccf1e3SJoseph Koshy.Xr hwpmc 4 ,
268ebccf1e3SJoseph Koshy.Xr pmccontrol 8 ,
269ebccf1e3SJoseph Koshy.Xr sysctl 8
27021ce09caSJoseph Koshy.Sh HISTORY
27121ce09caSJoseph KoshyThe
27221ce09caSJoseph Koshy.Nm
27321ce09caSJoseph Koshyutility first appeared in
27421ce09caSJoseph Koshy.Fx 6.0 .
2751fdbf256SJoseph KoshyIt is
2761fdbf256SJoseph Koshy.Ud
27721ce09caSJoseph Koshy.Sh AUTHORS
27821ce09caSJoseph Koshy.An Joseph Koshy Aq jkoshy@FreeBSD.org
2799f8adcefSJoseph Koshy.Sh BUGS
2809f8adcefSJoseph KoshyOn AMD64 platforms
2819f8adcefSJoseph Koshy.Nm
2829f8adcefSJoseph Koshydoes not yet handle profiles with samples from 32 bit executables.
283