Table of Contents
- 1. uftrace
- 1.1. uftrace -vv
- 1.2. example "-pg -g"
- 1.3. example
- 1.4. when stuck: ctrl-c
- 1.5. unit test
- 1.6. tui search
- 1.7. config
- 1.8. option
- 1.9. attach
- 1.10. github issue c++ exception
- 1.11. github issue: dynamic trace
- 1.12. library
- 1.13. library
- 1.14. install from scratch
- 1.15. tui (broken output)
- 1.16. vcs
1 uftrace
uftrace -V uftrace v0.9.4 ( dwarf tui perf sched ) uftrace -V uftrace v0.9.4-35-gfa1e ( dwarf tui dynamic )
1.1 uftrace -vv
uftrace graph --task
task level graph
1.2 example "-pg -g"
https://github.com/namhyung/uftrace/wiki/uftrace-for-Clang-LLVM
$ nm clang | grep mcount U mcount@@GLIBC2.2.5
$ uftrace -F main -D 2 –no-libcall – ./clang $ uftrace -F main -D 2 –no-event ./git -version $ uftrace -F main -D 3 – ./gcc
1.3 example
uftrace record -P . --nest-libcall --libname -vv ./testbench_4_dut
uftrace record --force --nest-libcall --libname -vv ./testbench_4_dut
uftrace replay -C arrow::stl::TupleRangeFromTable -t 200ns uftrace record ./testbench_4_dut -t 100us
1.4 when stuck: ctrl-c
When stcuck, enter ctrl-c it will flush data into disk
uftrace: flushing /uftrace-5ec03d2ae60aaae6-22950-001
^Cuftrace: cannot find build-id section uftrace: reading uftrace.data/task.txt file uftrace: flushing /uftrace-ea0ee3e57ac7eb43-374218-000 uftrace: flushing /uftrace-c4c98c486cc409c9-374287-000 uftrace: flushing /uftrace-28729e03df431737-374298-000 uftrace: flushing /uftrace-28729e03df431737-374299-000 uftrace: flushing /uftrace-28729e03df431737-374301-000
1.5 unit test
t136_dynamic.py ./runtest.py 136 t223_dynamic_full.py /depot/Python-3.6.2/bin/python runtest.py 223
~/home200G/opt/_uftrace/bin/uftrace -L ~/home200G/opt/src/uftrace $@
-L option when tracing in other languages (e.g. Python) #926 https://github.com/namhyung/uftrace/issues/926
git clone https://github.com/namhyung/uftrace ./configure make -j13 cd uftrace/test python runtest.py 223 -p -v python runtest.py 136 -p -v python runtest.py -p python runtest.py -p -O0 -v
-v show build and test command
1.6 tui search
tui search when expend G/g
1.7 config
Arguments Detection with Debug Info libdw: [ on ] -a/--auto-args uses debug info to detect type info of user functions
capstone: [on] full dynamic tracing uftrace -P . a.out
1.8 option
https://github.com/namhyung/uftrace/blob/master/doc/uftrace-record.md
-l, –nest-libcall :
Trace function calls between libraries. By default, uftrace only record library call from the main executable. Implies –force.
–force :
Allow running uftrace even if some problems occur. When uftrace record finds no mcount symbol (which is generated by compiler) in the executable, it quits with an error message since uftrace can not trace the program. However, it is possible that the user is only interested in functions within a dynamically-linked library, in which case this option can be used to cause uftrace to run the program regardless. Also, the -A/–argument and -R/–retval options work only for binaries built with -pg, so uftrace will normally exit when it tries to run binaries built without that option. This option ignores the warning and goes on tracing without the argument and/or return value.
–no-libcall :
Do not record library function invocations. Library calls are normally traced by hooking calls to the resolver function of dynamic linker in the PLT. One can disable it with this option.
–tid=TID[,TID,…] : Only print functions called by the given tasks. To see the list of tasks in the data file, you can use uftrace report –task or uftrace info. This option can also be used more than once.
uftrace report –task
1.9 attach
attaching to a running process. #360 https://github.com/namhyung/uftrace/pull/360
slide https://uftrace.github.io/slide/#174
Full Dynamic Tracing uftrace patches mcount call at runtime without compiler support.
1.10 github issue c++ exception
Exception catched in function still throw out causing the program terminating #31 https://github.com/namhyung/uftrace/issues/31 (2017)
The C++ exception handling involves stack unwinding and it conflicts to the uftrace which also does some tricks with the return address on the stack.
To avoid this conflict you can build your application with -finstrument-functions instead of -pg and run uftrace with –no-libcall not to hook return address of library functions too.
1.11 github issue: dynamic trace
feature dynamic tracing support (on x8664) #37 https://github.com/namhyung/uftrace/issues/37
dynamic tracing without compiler support #281 https://github.com/namhyung/uftrace/issues/281
dynamic tracing with existing `-pg -mfentry -mnop-mcount` #814 https://github.com/namhyung/uftrace/issues/814
Full dynamic tracing using capstone disasm #588 https://github.com/namhyung/uftrace/pull/588
1.12 library
-L option when tracing in other languages (e.g. Python) #926 https://github.com/namhyung/uftrace/issues/926
I know that uftrace finds libmcount in a sequence of ./libmcount/libmcount.so -> ./libmcount.so -> system, so it terminates when libpath == NULL.
1.13 library
libncurses, so adding -ltinfo to the link line, after -lncurses, solved the problem.
1.14 install from scratch
cat hello.diff diff --git a/check-deps/Makefile b/check-deps/Makefile index 7bc062c..58971af 100644 --- a/check-deps/Makefile +++ b/check-deps/Makefile @@ -30,11 +30,11 @@ LDFLAGS_have_libpython3 = $(shell python3-config --libs 2> /dev/null) CFLAGS_have_libluajit = $(shell pkg-config --cflags luajit 2> /dev/null) LDFLAGS_have_libluajit = $(shell pkg-config --libs luajit 2> /dev/null) CFLAGS_have_libncurses = $(shell pkg-config --cflags ncursesw 2> /dev/null) -LDFLAGS_have_libncurses = $(shell pkg-config --libs ncursesw 2> /dev/null) +LDFLAGS_have_libncurses = $(shell pkg-config --libs ncursesw 2> /dev/null) -ltinfo CFLAGS_have_libdw = $(shell pkg-config --cflags libdw 2> /dev/null) LDFLAGS_have_libdw = $(shell pkg-config --libs libdw 2> /dev/null || echo "-ldw") -CFLAGS_have_libcapstone = $(shell pkg-config --cflags capstone 2> /dev/null) -LDFLAGS_have_libcapstone = $(shell pkg-config --libs capstone 2> /dev/null) +CFLAGS_have_libcapstone = -I/remote/vgrnd101/jianmin/opt/_capstone/include +LDFLAGS_have_libcapstone = -L-I/remote/vgrnd101/jianmin/opt/_capstone check-build: check-tstamp $(CHECK_LIST) diff --git a/check-deps/Makefile.check b/check-deps/Makefile.check index ea1edbd..9352c3a 100644 --- a/check-deps/Makefile.check +++ b/check-deps/Makefile.check @@ -43,7 +43,7 @@ endif ifneq ($(wildcard $(srcdir)/check-deps/have_libncurses),) COMMON_CFLAGS += -DHAVE_LIBNCURSES $(shell pkg-config --cflags ncursesw) - UFTRACE_LDFLAGS += $(shell pkg-config --libs ncursesw) + UFTRACE_LDFLAGS += $(shell pkg-config --libs ncursesw) -ltinfo TEST_LDFLAGS += $(shell pkg-config --libs ncursesw) endif @@ -60,6 +60,6 @@ endif ifneq ($(wildcard $(srcdir)/check-deps/have_libcapstone),) COMMON_CFLAGS += -DHAVE_LIBCAPSTONE - COMMON_CFLAGS += $(shell pkg-config --cflags capstone 2> /dev/null) - COMMON_LDFLAGS += $(shell pkg-config --libs capstone 2> /dev/null) + COMMON_CFLAGS += -I/remote/vgrnd101/jianmin/opt/_capstone/include + COMMON_LDFLAGS += -L/remote/vgrnd101/jianmin/opt/_capstone -lcapstone -Wl,-rpath /remote/vgrnd101/jianmin/opt/_capstone endif
./configure –prefix=~/home200G/opt/uftrace make V=1 make install
git clone https://github.com/namhyung/uftrace cd uftrace git apply hello.diff ./configure --prefix=/path/to/opt/_uftrace make install
1.14.1 capstonw
mkdir lib ln -s libcapstone.so libcapstone.so.5
git clone https://github.com/aquynh/capstone cd capstone ./make.sh
cp libcapstone.so.5 /path/to/lib cp include /path/to/lib
See COMPILE.TXT file for how to compile and install Capstone
1.14.2 run
record -P. ../simv
1.14.3 uftrace puzzle
ldd ~/uftrace/uftrace_/bin/uftrace (with capstone) why this binary does not need LDLIBRARYPATH
-L option when tracing in other languages (e.g. Python) #926 https://github.com/namhyung/uftrace/issues/926
cat ~/bin/uftrace #!/bin/sh LD_LIBRARY_PATH=~/home200G/opt/_uftrace/lib:$LD_LIBRARY_PATH ~/home200G/opt/_uftrace/bin/uftrace $@
1.15 tui (broken output)
1.585 us : ~T~\ ~T~@(1) __monstartup : ~T~B 0.875 us : ~T~\ ~T~@(1) __cxa_atexit : ~T~B 3.005 us : ~T~T ~T~@(1) main 2.563 us : (1) a 2.287 us : (1) b 1.962 us : (1) c 1.252 us : (1) getpid
$ locale -a C C.utf8 POSIX
export LC_CTYPE="C.utf8"
After updating LCCTYPE
1.585 us : ├─(1) __monstartup : │ 0.875 us : ├─(1) __cxa_atexit : │ 3.005 us : └─(1) main 2.563 us : (1) a 2.287 us : (1) b 1.962 us : (1) c 1.252 us : (1) getpid
https://github.com/namhyung/uftrace/issues/326 https://github.com/namhyung/uftrace/issues/740
1.16 vcs
vcs -CFLAGS '-pg' ...