9070 Remove wanboot from gate
[unleashed.git] / usr / src / man / man1 / prex.1
blobee598efd43283a4a94fbf84aa26b166a01984ed4
1 '\" te
2 .\"  Copyright (c) 2004, Sun Microsystems, Inc.  All Rights Reserved.
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 PREX 1 "Mar 1, 2004"
7 .SH NAME
8 prex \- control tracing and manipulate probe points in a process or the kernel
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBprex\fR [\fB-o\fR \fItrace_file_name\fR] [\fB-l\fR \fIlibraries\fR] [\fB-s\fR \fIkbytes_size\fR] \fIcmd\fR
13      [\fIcmd-args\fR]...
14 .fi
16 .LP
17 .nf
18 \fBprex\fR [\fB-o\fR \fItrace_file_name\fR] [\fB-l\fR \fIlibraries\fR] [\fB-s\fR \fIkbytes_size\fR] \fB-p\fR \fIpid\fR
19 .fi
21 .LP
22 .nf
23 \fBprex\fR \fB-k\fR [\fB-s\fR \fIkbytes_size\fR]
24 .fi
26 .SH DESCRIPTION
27 .sp
28 .LP
29 The \fBprex\fR command is the part of the Solaris tracing architecture that
30 controls probes in a process or the kernel. See \fBtracing\fR(3TNF) for an
31 overview of this tracing architecture, including example source code using it.
32 .sp
33 .LP
34 \fBprex\fR is the application used for external control of probes. It
35 automatically preloads the \fBlibtnfprobe\fR library. \fBprex\fR locates all
36 the probes in a target executable or the kernel and provides an interface for
37 the user to manipulate them. It allows a probe to be turned on for tracing,
38 debugging, or both. Tracing generates a \fBTNF\fR (Trace Normal Form) trace
39 file that can be converted to \fBASCII\fR by \fBtnfdump\fR(1) and used for
40 performance analysis. Debugging generates a line to standard error whenever the
41 probe is hit at run time.
42 .sp
43 .LP
44 \fBprex\fR does not work on static executables. It only works on dynamic
45 executables.
46 .SS "Invoking prex"
47 .sp
48 .LP
49 There are three ways to invoke \fBprex\fR:
50 .RS +4
51 .TP
53 Use \fBprex\fR to start the target application \fIcmd\fR. In this case, the
54 target application need not be built with a dependency on \fBlibtnfprobe\fR.
55 See \fBTNF_PROBE\fR(3TNF). \fBprex\fR sets the environment variable
56 \fBLD_PRELOAD\fR to load \fBlibtnfprobe\fR into the target process. See
57 \fBld\fR(1). \fBprex\fR then uses the environment variable \fBPATH\fR to find
58 the target application.
59 .RE
60 .RS +4
61 .TP
63 Attach \fBprex\fR to a running application. In this case, the running target
64 application should have \fBlibtnfprobe\fR already linked in. Alternatively, the
65 user may manually set \fBLD_PRELOAD\fR to include \fBlibtnfprobe.so.1\fR prior
66 to invoking the target.
67 .RE
68 .RS +4
69 .TP
71 Use \fBprex\fR with the \fB-k\fR option to set \fBprex\fR to \fBkernel
72 mode\fR. \fBprex\fR can then be used to control probes in the Solaris kernel.
73 In kernel mode, additional commands are defined, and some commands that are
74 valid in other modes are invalid. See \fBKernel\fR \fBMode\fR below.
75 .RE
76 .SS "Control File Format and Command Language"
77 .sp
78 .LP
79 In a future release of \fBprex\fR, the command language may be moved to a
80 syntax that is supported by an existing scripting language like \fBksh\fR(1).
81 In the meantime, the interface to \fBprex\fR is uncommitted.
82 .RS +4
83 .TP
84 .ie t \(bu
85 .el o
86 Commands should be in \fBASCII\fR.
87 .RE
88 .RS +4
89 .TP
90 .ie t \(bu
91 .el o
92 Each command is terminated with the NEWLINE character.
93 .RE
94 .RS +4
95 .TP
96 .ie t \(bu
97 .el o
98 A command can be continued onto the next line by ending the previous line with
99 the backslash ("\fB\e\fR") character.
101 .RS +4
103 .ie t \(bu
104 .el o
105 Tokens in a command must be separated by whitespace (one or more spaces or
106 tabs).
108 .RS +4
110 .ie t \(bu
111 .el o
112 The "\fB#\fR" character implies that the rest of the line is a comment.
114 .SS "Basic prex Commands"
119 c c
120 l l .
121 Command Result
123 % \fBprex a.out\fR      T{
124 Attaches \fBprex\fR to your program and starts \fBprex\fR.
126 prex> \fBenable $all\fR Enables all the probes.
127 prex> \fBquit resume\fR T{
128 Quits \fBprex\fR and resumes execution of program.
132 .SS "Control File Search Path"
135 There are two different methods of communicating with \fBprex\fR:
136 .RS +4
138 .ie t \(bu
139 .el o
140 By specifications in a control file. During start-up, \fBprex\fR searches for a
141 file named  \fB\&.prexrc\fR in the directories specified below. \fBprex\fR does
142 not stop at the first one it finds. This way a user can override any defaults
143 that are set up. The search order is:
145 .in +2
147 $HOME/
148 \&./
150 .in -2
154 .RS +4
156 .ie t \(bu
157 .el o
158 By typing commands at the \fBprex\fR prompt.
162 The command language for both methods is the same and is specified in USAGE.
163 The commands that return output will not make sense in a control file. The
164 output will go to standard output.
167 When using \fBprex\fR on a target process, the target will be in one of two
168 states, running or stopped. This can be detected by the presence or absence of
169 the \fBprex>\fR prompt. If the prompt is absent, it means that the target
170 process is running. Typing Control-C will stop the target pr ocess and return
171 the user to the prompt. There is no guarantee that Control-C will return to a
172 \fBprex\fR prompt immediately. For example, if the target process is stopped on
173 a job control stop (\fBSIGSTOP\fR), then Control-C in \fBprex\fR will wait
174 until the target has been continued (\fBSIGCONT\fR). See \fBSignals to Target
175 Program\fR below for more information on signals and the target process.
176 .SH OPTIONS
179 The following options are supported:
181 .ne 2
183 \fB\fB-k\fR\fR
185 .RS 22n
186 \fBkernel mode\fR: \fBprex\fR is used to control probes in the Solaris kernel.
187 In kernel mode, additional commands are defined, and some commands valid in
188 other modes are invalid. See \fBKernel Mode\fR  below.
192 .ne 2
194 \fB\fB-l\fR \fIlibraries\fR\fR
196 .RS 22n
197 The \fIlibraries\fR mentioned are linked in to the target application using
198 \fBLD_PRELOAD\fR (see \fBld\fR(1)). This option cannot be used when attaching
199 to a running process. The argument to the \fB-l\fR option should be a
200 space-separated string enclosed in double quotes. Each token in the string is a
201 library name. It follows the \fBLD_PRELOAD\fR rules on how libraries should be
202 specified and where they will be found.
206 .ne 2
208 \fB\fB-o\fR \fItrace_file_name\fR\fR
210 .RS 22n
211 File to be used for the trace output. \fItrace_file_name\fR is assumed to be
212 relative to the current working directory of \fBprex\fR (that is, the directory
213 that the user was in when \fBprex\fR was started).
215 If \fBprex\fR attaches to a process that is already tracing, the new
216 \fItrace_file_name\fR (if provided) will not be used. If no
217 \fItrace_file_name\fR is specified, the default is
218 \fB/$TMPDIR/trace-\fR\fIpid\fR where \fIpid\fR is the process id of the target
219 program. If \fBTMPDIR\fR is not set, \fB/tmp\fR is used.
223 .ne 2
225 \fB\fB-s\fR \fIkbytes_size\fR\fR
227 .RS 22n
228 Maximum size of the output trace file in Kbytes. The default size of the trace
229 \fIkbytes_size\fR is \fB4096\fR (2^10) bytes or \fB4\fR Mbytes for normal
230 usage, and \fB384\fR or \fB384\fR kbytes in kernel mode. The minimum size that
231 can be specified is \fB128\fR Kbytes. The trace file can be thought of as a
232 least recently used circular buffer. Once the file has been filled, newer
233 events will overwrite the older ones.
236 .SH USAGE
239 This section describes the usage of the \fBprex\fR utility.
240 .SS "Grammar"
243 Probes are specified by a list of space-separated selectors. Selectors are of
244 the form:
246 .in +2
248 \fIattribute\fR=\fIvalue\fR
250 .in -2
254 (See \fBTNF_PROBE\fR(3TNF)). The "\fIattribute\fR=" is optional. If it is not
255 specified, it defaults to "\fBkeys=\fR".
258 The \fIattribute\fR or \fIvalue\fR (generically called "spec") can be any of
259 the following:
261 .ne 2
263 \fB\fBIDENT\fR\fR
265 .RS 14n
266 Any sequence of letters, digits, _\|, \e\|, ., % not beginning with a digit.
267 \fBIDENT\fR implies an exact match.
271 .ne 2
273 \fB\fBQUOTED_STR\fR\fR
275 .RS 14n
276 Usually used to escape reserved words (any commands in the command language).
277 \fBQUOTED_STR\fR implies an exact match and has to be enclosed in single quotes
278 (' ').
282 .ne 2
284 \fB\fBREGEXP\fR\fR
286 .RS 14n
287 An \fBed\fR(1) regular expression pattern match. \fBREGEXP\fR has to be
288 enclosed in slashes (/ /), A / can be included in a \fBREGEXP\fR by escaping it
289 with a backslash \e\|.
294 The following grammar explains the syntax.
296 .in +2
298 selector_list ::=   |                /* empty */
299                     \fIselector_list\fR \fIselector\fR
300 selector ::=        \fIspec\fR=\fIspec\fR |  /* whitespace around `=' opt */
301                     \fIspec\fR
302 spec ::=            IDENT |
303                     QUOTED_STR |
304                     REGEXP
306 .in -2
310 The terminals in the above grammar are:
312 .in +2
314 IDENT =       [a-zA-Z_\e.%]{[a-zA-Z0-9_\e.%]}+
315 QUOTED_STR =  '[^\en']*'   /* any string in single quotes */
316 REGEXP =      /[^\en/]*/   /* regexp's have to be in / / */
318 .in -2
322 This is a list of the remaining grammar that is needed to understand the syntax
323 of the command language (defined in next subsection):
325 .in +2
327 filename ::=     QUOTED_STR    /* QUOTED_STR defined above */
328 spec_list ::=    /* empty */ |
329                  \fIspec_list\fR \fIspec\fR  /* \fIspec\fR defined above */
330 fcn_handle ::=   &IDENT        /* IDENT defined above */
331 set_name ::=     $IDENT        /* IDENT defined above */
333 .in -2
335 .SS "Command Language"
336 .RS +4
339 Set Creation and Set Listing
341 .in +2
343 \fBcreate $\fIset_name\fR \fIselector_list\fR
344 list     sets          # list the defined sets\fR
346 .in -2
349 \fBcreate\fR can be used to define a set which contains probes that match the
350 \fIselector_list\fR. The set \fB$all\fR is pre-defined as /.*/ and it matches
351 all the probes.
353 .RS +4
356 Function Listing
358 .in +2
360 \fBlist     fcns        # list the available \fIfcn_handle\fR\fR
362 .in -2
365 The user can list the different functions that can be connected to probe
366 points. Currently, only the debug function called \fB&debug\fR is available.
368 .RS +4
371 Commands to Connect and Disconnect Probe Functions
373 .in +2
375 \fBconnect &\fIfcn_handle\fR $\fIset_name\fR
376 connect &\fIfcn_handle\fR \fIselector_list\fR
377 clear $\fIset_name\fR
378 clear \fIselector_list\fR\fR
380 .in -2
383 The \fBconnect\fR command is used to connect probe functions (which must be
384 prefixed by `\fB&\fR\&') to probes. The probes are specified either as a single
385 set (with a `\fB$\fR'), or by explicitly listing the probe selectors in the
386 command. The probe function has to be one that is listed by the \fBlist fcns\fR
387 command. This command does not enable the probes.
389 The \fBclear\fR command is used to disconnect all connected probe functions
390 from the specified probes.
392 .RS +4
395 Commands to Toggle the Tracing Mode
397 .in +2
399 \fBtrace $\fIset_name\fR
400 trace \fIselector_list\fR
401 untrace $\fIset_name\fR
402 untrace \fIselector_list\fR\fR
404 .in -2
407 The \fBtrace\fR and \fBuntrace\fR commands are used to toggle the tracing
408 action of a probe point (that is, whether a probe will emit a trace record or
409 not if it is hit). This command does not enable the probes specified. Probes
410 have tracing on by default. The most efficient way to turn off tracing is by
411 using the \fBdisable\fR command. \fBuntrace\fR is useful if you want debug
412 output but no tracing.  If so, set the state of the probe to enabled, untraced,
413 and the debug function connected.
415 .RS +4
418 Commands to Enable and Disable Probes
420 .in +2
422 \fBenable $\fIset_name\fR
423 enable \fIselector_list\fR
424 disable $\fIset_name\fR
425 disable \fIselector_list\fR\fR
427 .in -2
430 The \fBenable\fR and \fBdisable\fR commands are used to control whether the
431 probes perform the action that they have been set up for. To trace a probe, it
432 has to be both enabled and traced (using the \fBtrace\fR command). Probes are
433 disabled by default. The \fBlist history\fR command is used to list the probe
434 control commands issued: \fBconnect\fR, \fBclear\fR, \fBtrace\fR,
435 \fBuntrace\fR, \fBenable\fR, and  \fBdisable\fR. These are the commands that
436 are executed whenever a new shared object is brought in to the target program
437 by \fBdlopen\fR(3C). See the subsection, \fBdlopen'ed Libraries\fR, below for
438 more information.
440 The following table shows the actions that result from specific combinations of
441 tracing, enabling, and connecting:
443 .in +2
445 Enabled or   Tracing State     Debug State        Results
446 Disabled       (On/Off)     (Connected/Cleared)    In
447 ------------------------------------------------------------
448 Enabled          On             Connected        Tracing and
449                                                  Debugging
451 Enabled          On             Cleared          Tracing only
453 Enabled          Off            Connected        Debugging only
455 Enabled          Off            Cleared          Nothing
457 Disabled         On             Connected        Nothing
459 Disabled         On             Cleared          Nothing
461 Disabled         Off            Connected        Nothing
463 Disabled         Off            Cleared          Nothing
465 .in -2
469 .RS +4
472 List History
474 .in +2
476 \fBlist history    # lists probe control command history\fR
478 .in -2
481 The \fBlist history\fR command displays a list of the probe control commands
482 previously issued in the tracing session, for example, \fBconnect\fR,
483 \fBclear\fR, \fBtrace\fR, \fBdisable\fR. Commands in the history list are
484 executed wherever a new shared object is  brought into the target program by
485 \fBdlopen\fR(3C).
487 .RS +4
490 Commands to List Probes, List Values, or List Trace File Name
492 .in +2
494 \fBlist \fIspec_list\fR probes $\fIset_name\fR  # list probes $all
495 list \fIspec_list\fR probes \fIselector_list\fR   # list name probes file=test.c
496 list values \fIspec_list\fR  # list values keys given in \fIspec_list\fR
497 list tracefile  # list tracefile\fR
499 .in -2
502 The first two commands list the selected attributes and values of the specified
503 probes. They can be used to check the state of a probe. The third command lists
504 the various values associated with the selected attributes. The fourth command
505 lists the current tracefile.
507 .RS +4
510 Help Command
512 .in +2
514 \fBhelp \fItopic\fR\fR
516 .in -2
519 To get a list of the help topics that are available, invoke the \fBhelp\fR
520 command with no arguments. If a \fItopic\fR argument is specified, help is
521 printed for that topic.
523 .RS +4
526 Source a File
528 .in +2
530 \fBsource \fIfilename\fR\fR
532 .in -2
535 The \fBsource\fR command can be used to source a file of \fBprex\fR commands.
536 \fBsource\fR can be nested (that is, a file can source another file).
537 \fIfilename\fR is a quoted string.
539 .RS +4
542 Process Control
544 .in +2
546 \fBcontinue           # resumes the target process
547 quit kill          # quit prex, kill target
548 quit resume        # quit prex, continue target
549 quit suspend       # quit prex, leave target suspended
550 quit               # quit prex (continue or kill target)\fR
552 .in -2
555 The default \fBquit\fR will continue the target process if \fBprex\fR attached
556 to it. Instead, if \fBprex\fR had started the target program, \fBquit\fR will
557 kill the target process.
559 .SS "dlopen'ed Libraries"
562 Probes in shared objects that are brought in by \fBdlopen\fR(3C) are
563 automatically set up according to the command history of \fBprex\fR. When a
564 shared object is removed by a \fBdlclose\fR(3C), \fBprex\fR again needs to
565 refresh its understanding of the probes in the target program. This implies
566 that there is more work to do for \fBdlopen\fR(3C) and \fBdlclose\fR(3C) \(emso
567 they will take slightly longer. If a user is not interested in this feature and
568 doesn't want to interfere with \fBdlopen\fR(3C) and \fBdlclose\fR(3C), detach
569 \fBprex\fR from the target to inhibit this feature.
570 .SS "Signals to Target Program"
573 \fBprex\fR does not interfere with signals that are delivered directly to the
574 target program. However, \fBprex\fR receives all signals normally generated
575 from the terminal, for example, Control-C (\fBSIGINT\fR), and Control-Z
576 (\fBSIGSTOP\fR), and does not forward them to the target program. To signal the
577 target program, use the \fBkill\fR(1) command from a shell.
578 .SS "Interactions with Other Applications"
581 Process managing applications like \fBdbx\fR, \fBtruss\fR(1), and \fBprex\fR
582 cannot operate on the same target program simultaneously. \fBprex\fR will not
583 be able to attach to a target which is being controlled by another application.
584 A user can trace and debug a program serially by the following method: first
585 attach \fBprex\fR to target (or start target through \fBprex\fR), set up the
586 probes using the command language, and then type \fBquit suspend\fR. The user
587 can then attach \fBdbx\fR to the suspended process and debug it. A user can
588 also suspend the target by sending it a \fBSIGSTOP\fR signal, and then by
589 typing \fBquit resume\fR to \fBprex\fR. In this case, the user should also send
590 a \fBSIGCONT\fR signal after invoking \fBdbx\fR on the stopped process (else
591 \fBdbx\fR will be hung).
592 .SS "Failure of Event Writing Operations"
595 There are a few failure points that are possible when writing out events to a
596 trace file, for example, system call failures. These failures result in a
597 failure code being set in the target process. The target process continues
598 normally, but no trace records are written. Whenever a user enters Control-C to
599 \fBprex\fR to get to a \fBprex\fR prompt, \fBprex\fR will check the failure
600 code in the target and inform the user if there was a tracing failure.
601 .SS "Target Executing a Fork or exec"
604 If the target program does a \fBfork\fR(2), any probes that the child
605 encounters will cause events to be logged to the same trace file. Events are
606 annotated with a process id, so it will be possible to determine which process
607 a particular event came from. In multi-threaded programs, there is a race
608 condition with a thread doing a fork while the other threads are still running.
609 For the trace file not to get corrupted, the user should either use
610 \fBfork1\fR(2), or make sure that all other threads are quiescent when doing a
611 \fBfork\fR(2),
614 If the target program itself (not any children it may \fBfork\fR(2)) does an
615 \fBexec\fR(2), \fBprex\fR detaches from the target and exits. The user can
616 reconnect \fBprex\fR with \fBprex\fR \fB-p\fR \fIpid\fR.
619 A \fBvfork\fR(2) is generally followed quickly by an  \fBexec\fR(2) in the
620 child, and in the interim, the child borrows the parent's process while the
621 parent waits for the \fBexec\fR(2). Any events logged by the child from the
622 parent process will appear to have been logged by the parent.
623 .SS "Kernel Mode"
626 Invoking \fBprex\fR with the \fB-k\fR flag causes \fBprex\fR to run in
627 \fBkernel mode\fR. In kernel mode, \fBprex\fR controls probes in the Solaris
628 kernel. See \fBtnf_kernel_probes\fR(4) for a list of available probes in the
629 Solaris kernel. A few \fBprex\fR commands are unavailable in kernel mode; many
630 other commands are valid in kernel mode only.
633 The \fB-l\fR, \fB-o\fR, and \fB-p\fR command-line options are not valid in
634 kernel mode (that is, they may not be combined with the \fB-k\fR flag).
637 The rest of this section describes the differences in the \fBprex\fR command
638 language when running \fBprex\fR in kernel mode.
639 .RS +4
642 \fBprex\fR will not stop the kernel
644 When \fBprex\fR attaches to a running user program, it stops the user program.
645 Obviously, it cannot do this when attaching to the kernel.  Instead, \fBprex\fR
646 provides a ``tracing master switch'': no probes will have any effect unless the
647 tracing master switch is on.  This allows the user to iteratively select probes
648 to enable, then enable them all at once by turning on the master switch.
650 The command
652 .in +2
654 \fBktrace [ on | off ]\fR
656 .in -2
659 is used to inspect and set the value of the master switch. Without an argument,
660 \fBprex\fR reports the current state of the master switch.
662 Since \fBprex\fR will not stop or kill the kernel, the
664 .in +2
666 \fBquit resume\fR
668 .in -2
673 .in +2
675 \fBquit kill\fR
677 .in -2
680 commands are not valid in kernel mode.
682 .RS +4
685 No functions may be attached to probes in the kernel
687 In particular, the debug function is unavailable in kernel mode.
689 .RS +4
692 Trace output is written to an in-core buffer
694 In kernel mode, a trace output file is not generated directly, in order to
695 allow probes to be placed in time-critical code. Instead, trace output is
696 written to an in-core buffer, and copied out by a separate program,
697 \fBtnfxtract\fR(1).
699 The in-core buffer is not automatically created. The following \fBprex\fR
700 command controls buffer allocation and deallocation:
702 .in +2
704 \fBbuffer [  alloc [  \fIsize\fR ] |  dealloc ]\fR
706 .in -2
709 Without an argument, the \fBbuffer\fR command reports the size of the currently
710 allocated buffer, if any. With an argument of \fBalloc\fR [\fIsize\fR],
711 \fBprex\fR allocates a buffer of the given size. \fIsize\fR is in bytes, with
712 an optional suffix of '\fBk\fR' or '\fBm\fR' specifying a multiplier of
713 \fB1024\fR or \fB1048576\fR, respectively. If no  \fIsize\fR is specified, the
714 \fIsize\fR specified on the command line with the \fB-s\fR option is used as a
715 default. If the \fB-s\fR command line option was not used, the ``default
716 default'' is 384 kilobytes.
718 With an argument of \fBdealloc\fR, \fBprex\fR deallocates the trace buffer in
719 the kernel.
721 \fBprex\fR will reject attempts to turn the tracing master switch on when no
722 buffer is allocated, and to deallocate the buffer when the tracing master
723 switch is on. \fBprex\fR will refuse to allocate a buffer when one is already
724 allocated; use \fBbuffer dealloc\fR first.
726 \fBprex\fR will not allocate a buffer larger than one-half of a machine's
727 physical memory.
729 .RS +4
732 \fBprex\fR supports per-process probe enabling in the kernel
734 In kernel mode, it is possible to select a set of processes for which probes
735 are enabled. No trace output will be written when other processes traverse
736 these probe points. This is called "process filter mode". By default, process
737 filter mode is off, and all processes cause the generation of trace records
738 when they hit an enabled probe.
740 Some kernel events such as interrupts cannot be associated with a particular
741 user process.  By convention, these events are considered to be generated by
742 process id 0.
744 \fBprex\fR provides commands to turn process filter mode on and off, to get the
745 current status of the process filter mode switch, to add and delete processes
746 (by process id) from the process filter set, and to list the current process
747 filter set.
749 The process filter set is maintained even when process filter mode is off, but
750 has no effect unless process filter mode is on.
752 When a process in the process filter set exits, its process id is automatically
753 deleted from the process filter set.
755 The command:
757 .in +2
759 \fBpfilter [ on | off | add \fIpidlist\fR | delete \fIpidlist\fR ]\fR
761 .in -2
764 controls the process filter switch, and process filter set membership. With no
765 arguments, \fBpfilter\fR prints the current process filter set and the state of
766 the process filter mode switch:
768 .ne 2
770 \fB\fBon\fR or \fBoff\fR\fR
772 .RS 18n
773 set the state of the process filter mode switch.
777 .ne 2
779 \fB\fBadd\fR \fIpidlist\fR\fR
783 \fB\fBdelete\fR \fIpidlist\fR\fR
785 .RS 18n
786 add or delete processes from the process filter set. \fIpidlist\fR is a
787 comma-separated list of one or more process ids.
791 .SH EXAMPLES
794 See \fBtracing\fR(3TNF) for complete examples showing, among other things, the
795 use of \fBprex\fR to do simple probe control.
798 When either the process or kernel is started, all probes are disabled.
800 \fBExample 1 \fRSet creation and set listing
802 .in +2
804 \fBcreate $out name=/out/     # $out = probes with "out" in
805                            #   value of "name" attribute
806 create $foo /page/ name=biodone   # $foo = union of
807        # probes with "page" in value of keys attribute
808        # probes with "biodone" as value of "name" attribute
809 list sets                  # list the defined sets
810 list fcns                  # list the defined probe fcns\fR
812 .in -2
816 \fBExample 2 \fRCommands to trace and connect probe functions
818 .in +2
820 \fBtrace foobar='on'          # exact match on foobar attribute
821 trace $all                 # trace all probes (predefined set $all)
822 connect &debug $foo        # connect debug func to probes in $foo\fR
824 .in -2
828 \fBExample 3 \fRCommands to enable and disable probes
830 .in +2
832 \fBenable  $all               # enable all probes
833 enable /vm/ name=alloc     # enable the specified probes
834 disable $foo               # disable probes in set $foo
835 list history               # list probe control commands issued\fR
837 .in -2
841 \fBExample 4 \fRProcess control
843 .in +2
845 \fBcontinue                   # resumes the target process
846 ^C                         # stop target; give control to prex
847 quit resume                # exit prex, leave process running
848                                 # and resume execution of program\fR
850 .in -2
854 \fBExample 5 \fRKernel mode
856 .in +2
858 \fBbuffer alloc 2m            # allocate a 2 Megabyte buffer
859 enable $all                # enable all probes
860 trace $all                 # trace all probes
861 ktrace on                  # turn tracing on
862 ktrace off                 # turn tracing back off
863 pfilter on                 # turn process filter mode on
864 pfilter add 1379           # add pid 1379 to process filter
865 ktrace on                  # turn tracing on
866                            # (only pid 1379 will be traced)\fR
868 .in -2
871 .SH FILES
873 .ne 2
875 \fB\fB\&.prexrc\fR\fR
877 .RS 15n
878 local \fBprex\fR initialization file
882 .ne 2
884 \fB\fB~/.prexrc\fR\fR
886 .RS 15n
887 user's \fBprex\fR initialization file
891 .ne 2
893 \fB\fB/proc/\fInnnnn\fR\fR\fR
895 .RS 15n
896 process files
899 .SH SEE ALSO
902 \fBed\fR(1), \fBkill\fR(1), \fBksh\fR(1), \fBld\fR(1), \fBtnfdump\fR(1),
903 \fBtnfxtract\fR(1), \fBtruss\fR(1), \fBexec\fR(2), \fBfork\fR(2),
904 \fBfork1\fR(2), \fBvfork\fR(2), \fBTNF_DECLARE_RECORD\fR(3TNF),
905 \fBTNF_PROBE\fR(3TNF), \fBdlclose\fR(3C), \fBdlopen\fR(3C),
906 \fBgethrtime\fR(3C), \fBlibtnfctl\fR(3TNF), \fBtnf_process_disable\fR(3TNF),
907 \fBtracing\fR(3TNF), \fBtnf_kernel_probes\fR(4), \fBattributes\fR(5)
908 .SH NOTES
911 Currently, the only probe function that is available is the \fB&debug\fR
912 function. When this function is executed, it prints out the arguments sent in
913 to the probe as well as the value associated with the \fBsunw%debug\fR
914 attribute in the detail field (if any) to \fBstderr\fR.
917 For example, for the following probe point:
919 .in +2
921 TNF_PROBE_2(input_values, "testapp main",
922                 "sunw%debug 'have read input values successfully'",
923                 tnf_long, int_input, x,
924                 tnf_string, string_input, input);
926 .in -2
931 If \fIx\fR was 100 and \fIinput\fR was the string "success", then the output of
932 the debug probe function would be:
934 .in +2
936 probe input_values; sunw%debug "have read input values successfully";
937 int_input=100; string_input="success";
939 .in -2
944 Some non-SPARC hardware lacks a true high-resolution timer, causing
945 \fBgethrtime()\fR to return the same value multiple times in succession. This
946 can lead to problems in how some tools interpret the trace file. This situation
947 can be improved by interposing a version of \fBgethrtime()\fR, which causes
948 these successive values to be artificially incremented by one nanosecond:
950 .in +2
952 hrtime_t
953 gethrtime()
955     static mutex_t lock;
956     static hrtime_t (*real_gethrtime)(void) = NULL;
957     static hrtime_t last_time = 0;
959     hrtime_t this_time;
961     if (real_gethrtime == NULL) {
962         real_gethrtime =
963              (hrtime_t (*)(void)) dlsym(RTLD_NEXT, "gethrtime");
964     }
965     this_time = real_gethrtime();
967     mutex_lock(&lock);
968     if (this_time <= last_time)
969         this_time = ++last_time;
970     else
971         last_time = this_time;
972     mutex_unlock(&lock);
974     return (this_time);
977 .in -2
982 Of course, this does not increase the resolution of the timer, so timestamps
983 for individual events are still relatively inaccurate. But this technique
984 maintains ordering, so that if event A causes event B, B never appears to
985 happen before or at the same time as A.
988 \fBdbx\fR is available with the Sun Workshop Products.
989 .SH BUGS
992 \fBprex\fR should issue a notification when a process id has been automatically
993 deleted from the filter set.
996 There is a known bug in \fBprex\fR which can result in this message:
998 .in +2
1000 Tracing shut down in target program due to an internal
1001 error - Please restart prex and target
1003 .in -2
1008 When \fBprex\fR runs as root, and the target process is not root, and the
1009 tracefile is placed in a directory where it cannot be removed and re-created (a
1010 directory with the sticky bit on, like \fB/tmp\fR),mm then the target process
1011 will not be able to open the tracefile when it needs to. This results in
1012 tracing being disabled.
1015 Changing any of the circumstances listed above should fix the problem. Either
1016 don't run \fBprex\fR as root, or run the target process as root, or specify the
1017 tracefile in a directory other than \fB/tmp\fR.