2 .\" Copyright (c) 2004, Sun Microsystems, Inc.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH CPUTRACK 1 "April 9, 2016"
8 cputrack \- monitor process and LWP behavior using CPU performance counters
12 \fBcputrack\fR \fB-c\fR \fIeventspec\fR [\fB-c\fR \fIeventspec\fR]... [\fB-efntvD\fR]
13 [\fB-N\fR \fIcount\fR] [\fB-o\fR \fIpathname\fR] [\fB-T\fR \fIinterval\fR] \fIcommand\fR [\fIargs\fR]
18 \fBcputrack\fR \fB-c\fR \fIeventspec\fR [\fB-c\fR \fIeventspec\fR]... \fB-p\fR \fIpid\fR [\fB-efntvD\fR]
19 [\fB-N\fR \fIcount\fR] [\fB-o\fR \fIpathname\fR] [\fB-T\fR \fIinterval\fR]
24 \fBcputrack\fR \fB-h\fR
29 The \fBcputrack\fR utility allows \fBCPU\fR performance counters to be used to
30 monitor the behavior of a process or family of processes running on the system.
31 If \fIinterval\fR is specified with the \fB-T\fR option, \fBcputrack\fR samples
32 activity every \fIinterval\fR seconds, repeating forever. If a \fIcount\fR is
33 specified with the \fB-N\fR option, the statistics are repeated \fIcount\fR
34 times for each process tracked. If neither are specified, an interval of one
35 second is used. If \fIcommand\fR and optional \fIargs\fR are specified,
36 \fBcputrack\fR runs the command with the arguments given while monitoring the
37 specified \fBCPU\fR performance events. Alternatively, the process \fBID\fR of
38 an existing process can be specified using the \fB-p\fR option.
41 Because \fBcputrack\fR is an unprivileged program, it is subject to the same
42 restrictions that apply to \fBtruss\fR(1). For example, \fBsetuid\fR(2)
43 executables cannot be tracked.
46 The following options are supported:
50 \fB\fB-c\fR \fIeventspec\fR\fR
53 Specifies a set of events for the \fBCPU\fR performance counters to monitor.
54 The syntax of these event specifications is:
58 [picn=]\fIeventn\fR[,attr[\fIn\fR][=\fIval\fR]][,[picn=]\fIeventn\fR
59 [,attr[n][=\fIval\fR]],...,]
64 You can use the \fB-h\fR option to obtain a list of available events and
65 attributes. This causes generation of the usage message. You can omit an
66 explicit counter assignment, in which case \fBcpustat\fR attempts to choose a
67 capable counter automatically.
69 Attribute values can be expressed in hexadecimal, octal, or decimal notation,
70 in a format suitable for \fBstrtoll\fR(3C). An attribute present in the event
71 specification without an explicit value receives a default value of \fB1\fR. An
72 attribute without a corresponding counter number is applied to all counters in
75 The semantics of these event specifications can be determined by reading the
76 \fBCPU\fR manufacturer's documentation for the events.
78 Multiple \fB-c\fR options can be specified, in which case \fBcputrack\fR cycles
79 between the different event settings on each sample.
97 Follows all \fBexec\fR(2), or \fBexecve\fR(2) system calls.
106 Follows all children created by \fBfork\fR(2), \fBfork1\fR(2), or
107 \fBvfork\fR(2) system calls.
116 Prints an extended help message on how to use the utility, how to program the
117 processor-dependent counters, and where to look for more detailed information.
126 Omits all header output (useful if \fBcputrack\fR is the beginning of a
133 \fB\fB-N\fR \fIcount\fR\fR
136 Specifies the maximum number of \fBCPU\fR performance counter samples to take
143 \fB\fB-o\fR \fIoutfile\fR\fR
146 Specifies file to be used for the \fBcputrack\fR output.
152 \fB\fB-p\fR \fIpid\fR\fR
155 Interprets the argument as the process \fBID\fR of an existing process to which
156 process counter context should be attached and monitored.
165 Prints an additional column of processor cycle counts, if available on the
166 current architecture.
172 \fB\fB-T\fR \fIinterval\fR\fR
175 Specifies the interval between \fBCPU\fR performance counter samples in
176 seconds. Very small intervals may cause some samples to be skipped. See
186 Enables more verbose output.
191 The operating system enforces certain restrictions on the tracing of processes.
192 In particular, a command whose object file cannot be read by a user cannot be
193 tracked by that user; set-uid and set-gid commands can only be tracked by a
194 privileged user. Unless it is run by a privileged user, \fBcputrack\fR loses
195 control of any process that performs an \fBexec()\fR of a set-id or unreadable
196 object file. Such processes continue normally, though independently of
197 \fBcputrack\fR, from the point of the \fBexec()\fR.
200 The system may run out of per-user process slots when the \fB-f\fR option is
201 used, since \fBcputrack\fR runs one controlling process for each process being
205 The times printed by \fBcputrack\fR correspond to the wallclock time when the
206 hardware counters were actually sample. The time is derived from the same
207 timebase as \fBgethrtime\fR(3C).
210 The \fBcputrack\fR utility attaches performance counter context to each process
211 that it examines. The presence of this context allows the performance counters
212 to be multiplexed between different processes on the system, but it cannot be
213 used at the same time as the \fBcpustat\fR(1M) utility.
216 Once an instance of the \fBcpustat\fR utility is running, further attempts to
217 run \fBcputrack\fR will fail until all instances of \fBcpustat\fR terminate.
220 Sometimes \fBcputrack\fR provides sufficient flexibility and prints sufficient
221 statistics to make adding the observation code to an application unnecessary.
222 However, more control is occasionally desired. Because the same performance
223 counter context is used by both the application itself and by the agent LWP
224 injected into the application by \fBcputrack\fR, it is possible for an
225 application to interact with the counter context to achieve some interesting
226 capabilities. See \fBcpc_enable\fR(3CPC).
229 The processor cycle counts enabled by the \fB-t\fR option always apply to both
230 user and system modes, regardless of the settings applied to the performance
234 The output of \fBcputrack\fR is designed to be readily parsable by
235 \fBnawk\fR(1) and \fBperl\fR(1), thereby allowing performance tools to be
236 composed by embedding \fBcputrack\fR in scripts. Alternatively, tools may be
237 constructed directly using the same \fBAPI\fRs that \fBcputrack\fR is built
238 upon, using the facilities of \fBlibcpc\fR(3LIB) and \fBlibpctx\fR(3LIB). See
242 Although \fBcputrack\fR uses performance counter context to maintain separate
243 performance counter values for each LWP, some of the events that can be counted
244 will inevitably be impacted by other activities occurring on the system,
245 particularly for limited resources that are shared between processes (for
246 example, cache miss rates). For such events, it may also be interesting to
247 observe overall system behavior with \fBcpustat\fR(1M).
250 For the \fB-T\fR \fIinterval\fR option, if \fIinterval\fR is specified as zero,
251 no periodic sampling is performed. The performance counters are only sampled
252 when the process creates or destroys an \fBLWP\fR, or it invokes \fBfork\fR(2),
253 \fBexec\fR(2), or \fBexit\fR(2).
257 \fBExample 1 \fRUsing Performance Counters to Count Clock Cycles
260 In this example, the utility is being used on a machine containing an
261 UltraSPARC-III+ processor. The counters are set to count processor clock cycles
262 and instructions dispatched in user mode while running the \fBsleep\fR(1)
268 example% \fBcputrack -c pic0=Cycle_cnt,pic1=Instr_cnt sleep 10\fR
271 time lwp event pic0 pic1
272 1.007 1 tick 765308 219233
278 10.017 1 exit 844703 228058
285 \fBExample 2 \fRCounting External Cache References and Misses
288 This example shows more verbose output while following the \fBfork()\fR and
289 \fBexec()\fR of a simple shell script on an UltraSPARC machine. The counters
290 are measuring the number of external cache references and external cache
291 misses. Notice that the explicit \fBpic0\fR and \fBpic1\fR names can be omitted
292 where there are no ambiguities.
297 example% \fBcputrack -fev -c EC_ref,EC_hit /bin/ulimit -c\fR
300 time pid lwp event pic0 pic1
301 0.007 101142 1 init_lwp 805286 20023
302 0.023 101142 1 fork # 101143
303 0.026 101143 1 init_lwp 1015382 24461
304 0.029 101143 1 fini_lwp 1025546 25074
305 0.029 101143 1 exec 1025546 25074
306 0.000 101143 1 exec \e
307 # '/usr/bin/sh /usr/bin/basename\e
309 0.039 101143 1 init_lwp 1025546 25074
310 0.050 101143 1 fini_lwp 1140482 27806
311 0.050 101143 1 exec 1140482 27806
312 0.000 101143 1 exec # '/usr/bin/expr \e
313 //bin/ulimit : \(.*[^/]\)/*$ : .*/\(..*\) : \(.*\)$ | //bin/ulimi'
314 0.059 101143 1 init_lwp 1140482 27806
315 0.075 101143 1 fini_lwp 1237647 30207
316 0.075 101143 1 exit 1237647 30207
318 0.081 101142 1 fini_lwp 953383 23814
319 0.081 101142 1 exit 953383 23814
326 \fBExample 3 \fRCounting Instructions
329 This example shows how many instructions were executed in the application and
330 in the kernel to print the date on a Pentium III machine:
335 example% \fBcputrack -c inst_retired,inst_retired,nouser1,sys1 date\fR
338 time lwp event pic0 pic1
339 Fri Aug 20 20:03:08 PDT 1999
340 0.072 1 exit 246725 339666
346 \fBExample 4 \fRCounting TLB Hits
349 This example shows how to use processor-specific attributes to count TLB hits
350 on a Pentium 4 machine:
355 example% \fBcputrack -c ITLB_reference,emask=1 date\fR
359 Fri Aug 20 20:03:08 PDT 1999
367 By running any instance of the \fBcpustat\fR(1M) utility, all existing
368 performance counter context is forcibly invalidated across the machine. This
369 may in turn cause all invocations of the \fBcputrack\fR command to exit
370 prematurely with unspecified errors.
373 If \fBcpustat\fR is invoked on a system that has \fBCPU\fR performance counters
374 which are not supported by Solaris, the following message appears:
378 cputrack: cannot access performance counters - Operation not applicable
385 This error message implies that \fBcpc_open()\fR has failed and is documented
386 in \fBcpc_open\fR(3CPC). Review this documentation for more information about
387 the problem and possible solutions.
390 If a short interval is requested, \fBcputrack\fR may not be able to keep up
391 with the desired sample rate. In this case, some samples may be dropped.
394 See \fBattributes\fR(5) for descriptions of the following attributes:
402 ATTRIBUTE TYPE ATTRIBUTE VALUE
403 Interface Stability Evolving
408 \fBnawk\fR(1), \fBperl\fR(1), \fBproc\fR(1), \fBtruss\fR(1), \fBprstat\fR(1M),
409 \fBcpustat\fR(1M), \fBexec\fR(2), \fBexit\fR(2), \fBfork\fR(2),
410 \fBsetuid\fR(2), \fBvfork\fR(2), \fBgethrtime\fR(3C), \fBstrtoll\fR(3C),
411 \fBcpc\fR(3CPC), \fBcpc_bind_pctx\fR(3CPC), \fBcpc_enable\fR(3CPC),
412 \fBcpc_open\fR(3CPC), \fBlibcpc\fR(3LIB), \fBlibpctx\fR(3LIB), \fBproc\fR(4),