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