Skip to content

Commit 4ea6651

Browse files
committed
doc: Update documentation for dynamic tracing
Fixed: #760 Signed-off-by: Namhyung Kim <[email protected]>
1 parent 757d187 commit 4ea6651

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

doc/uftrace-live.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,23 @@ normally you need to build the target program with `-pg` (or
627627
funtions call `mcount()`.
628628

629629
With dynamic tracing, you can trace specific functions only given by the
630-
`-P`/`--patch` option. However you need to add some more compiler (gcc) options
631-
when building the target program. The gcc 5.1 or more recent versions provide
632-
`-mfentry` and `-mnop-mcount` options which add instrumentation code (i.e.
633-
calling `mcount()` function) at the very beginning of a function and convert
634-
the instruction to a NOP. Then it has almost zero performance overhead when
635-
running in a normal condition. The uftrace can convert it back to call
636-
`mcount()` if users want to (using `-P` option).
637-
638-
The following example shows a error message when normally running uftrace with
639-
the excutable built with `-pg -mfentry -mnop-mcount`. Because the binary doesn't
640-
call any instrumentation code (i.e. 'mcount').
630+
`-P`/`--patch` option. With capstone disassembly engine you even don't need to
631+
(re)compile the target with the option above. Now uftrace can analyze the
632+
instructions and (if possible) it can copy them to a different place and rewrite
633+
it to call `mcount()` function) so that it can be traced by uftrace. After that
634+
the control is passed to the copied instructions and then returned back to the
635+
remaining instructions.
636+
637+
If the capstone is not available, you need to add some more compiler (gcc)
638+
options when building the target program. The gcc 5.1 or more recent versions
639+
provide `-mfentry` and `-mnop-mcount` options which add instrumentation code
640+
(i.e. calling `mcount()` function) at the very beginning of a function and
641+
convert the instruction to a NOP. Then it has almost zero performance overhead
642+
when running in a normal condition. The uftrace can selectively convert it
643+
back to call `mcount()` using `-P` option.
644+
645+
The following example shows an error message when normally running uftrace.
646+
Because the binary doesn't call any instrumentation code (i.e. 'mcount').
641647

642648
$ gcc -o abc -pg -mfentry -mnop-mcount tests/s-abc.c
643649
$ uftrace abc
@@ -653,8 +659,8 @@ trace `a()`.
653659
# DURATION TID FUNCTION
654660
0.923 us [19379] | a();
655661

656-
In addition, you can enable all functions at load time using '.' that matches to
657-
any character in a regex pattern with `P` option.
662+
In addition, you can enable all functions using '.' (for glob, '*') that
663+
matches to any character in a regex pattern with `P` option.
658664

659665
$ uftrace --no-libcall -P . abc
660666
# DURATION TID FUNCTION

doc/uftrace-record.md

+26-18
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ RECORD OPTIONS
3232
Implies \--srcline. See *ARGUMENTS*.
3333

3434
-P *FUNC*, \--patch=*FUNC*
35-
: Patch FUNC dynamically. This is only applicable binaries built by
36-
gcc with `-pg -mfentry -mnop-mcount` or clang with `-fxray-instrument`.
37-
This option can be used more than once. See *DYNAMIC TRACING*.
35+
: Patch FUNC dynamically. This option can be used more than once.
36+
See *DYNAMIC TRACING*.
37+
38+
-Z *SIZE*, \--size-filter=*SIZE*
39+
: Patch functions bigger than SIZE bytes dynamically. See *DYNAMIC TRACING*.
3840

3941
-E *EVENT*, \--event=*EVENT*
4042
: Enable event tracing. The event should be available on the system.
@@ -541,19 +543,25 @@ normally you need to build the target program with `-pg` (or
541543
funtions call `mcount()`.
542544

543545
With dynamic tracing, you can trace specific functions only given by the
544-
`-P`/`--patch` option. However you need to add some more compiler (gcc) options
545-
when building the target program. The gcc 5.1 or more recent versions provide
546-
`-mfentry` and `-mnop-mcount` options which add instrumentation code (i.e.
547-
calling `mcount()` function) at the very beginning of a function and convert
548-
the instruction to a NOP. Then it has almost zero performance overhead when
549-
running in a normal condition. The uftrace can convert it back to call
550-
`mcount()` if users want to (using `-P` option).
551-
552-
The following example shows a error message when normally running uftrace with
553-
the excutable built with `-pg -mfentry -mnop-mcount`. Because the binary doesn't
554-
call any instrumentation code (i.e. 'mcount').
555-
556-
$ gcc -o abc -pg -mfentry -mnop-mcount tests/s-abc.c
546+
`-P`/`--patch` option. With capstone disassembly engine you even don't need to
547+
(re)compile the target with the option above. Now uftrace can analyze the
548+
instructions and (if possible) it can copy them to a different place and rewrite
549+
it to call `mcount()` function) so that it can be traced by uftrace. After that
550+
the control is passed to the copied instructions and then returned back to the
551+
remaining instructions.
552+
553+
If the capstone is not available, you need to add some more compiler (gcc)
554+
options when building the target program. The gcc 5.1 or more recent versions
555+
provide `-mfentry` and `-mnop-mcount` options which add instrumentation code
556+
(i.e. calling `mcount()` function) at the very beginning of a function and
557+
convert the instruction to a NOP. Then it has almost zero performance overhead
558+
when running in a normal condition. The uftrace can selectively convert it
559+
back to call `mcount()` using `-P` option.
560+
561+
The following example shows an error message when normally running uftrace.
562+
Because the binary doesn't call any instrumentation code (i.e. 'mcount').
563+
564+
$ gcc -o abc tests/s-abc.c
557565
$ uftrace abc
558566
uftrace: /home/namhyung/project/uftrace/cmd-record.c:1305:check_binary
559567
ERROR: Can't find 'mcount' symbol in the 'abc'.
@@ -568,8 +576,8 @@ trace `a()`.
568576
# DURATION TID FUNCTION
569577
0.923 us [19379] | a();
570578

571-
In addition, you can enable all functions at load time using '.' that matches to
572-
any character in a regex pattern with `P` option.
579+
In addition, you can enable all functions using '.' (for glob, '*') that
580+
matches to any character in a regex pattern with `P` option.
573581

574582
$ uftrace record --no-libcall -P . abc
575583
$ uftrace replay

0 commit comments

Comments
 (0)