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