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