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