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