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