Open atwufei opened 6 years ago
…, is it possible to capture traces for only a short time instead of the application's whole lifecycle?
I imagine that this is generally possible. But such an action would depend on your willingness to invest further software development efforts.
The tool “uftrace” is constructed in the way so far that tracing is performed for a specific command exeution.
strace -p
” supports tracing of a running process. Would you like to get similar functionality from the other tool?Another approach is to query only the desired data from a previous recording. Would you dare to convert the available data collection into another database?
@atwufei you can use trace-on
/-off
trigger (using -T
option) to enable/disable tracing during execution. The trigger works on a specific function specified on the command line. Also uftrace can be started tracing-disabled using the --disable
option.
For example, if the init fuctions is mysql_init()
and some other function you know is mysql_foo
, following will record trace between the two functions:
$ uftrace --disable -T mysql_init@trace-on -T mysql_foo@trace-off mysql <options>...
Currently trigger actions are processed at function entry.
@namhyung thank you very much. Is it possible to trace the only function like: -T func_entry@trace-on -T func_exit@trace-off
Do you mean single function? uftrace also provides function filters so if you want to trace only specific functions, please try -F
option:
$ uftrace -F mysql_foo mysql <options>...
Hi @atwufei,
If you want to trace only a specific single function, you can use -F
option as @namhyung said. But it shows the target function and its children functions as well.
Please see the below example,
$ uftrace tests/t-abc
# DURATION TID FUNCTION
1.326 us [ 24505] | __monstartup();
0.926 us [ 24505] | __cxa_atexit();
[ 24505] | main() {
[ 24505] | a() {
[ 24505] | b() {
[ 24505] | c() {
0.640 us [ 24505] | getpid();
1.534 us [ 24505] | } /* c */
1.944 us [ 24505] | } /* b */
2.211 us [ 24505] | } /* a */
2.717 us [ 24505] | } /* main */
In this case, if you use -F b
to trace b
function, the output looks like below:
$ uftrace -F b tests/t-abc
# DURATION TID FUNCTION
[ 24518] | b() {
[ 24518] | c() {
0.640 us [ 24518] | getpid();
2.324 us [ 24518] | } /* c */
3.145 us [ 24518] | } /* b */
If you want to trace only b
function without its children, you can run it as follows:
$ uftrace -F b -D 1 tests/t-abc
# DURATION TID FUNCTION
1.283 us [ 24534] | b();
Here is another way:
$ uftrace -F b@depth=1 tests/t-abc
# DURATION TID FUNCTION
1.206 us [ 24562] | b();
Please refer to the man page for -D
option and @depth
trigger.
@atwufei you might be interested in the signal trigger #340.
Cool, thank you very much.
Firstly, this tool looks great.
I want to use uftrace to trace MySQL. As I only care about how a specific SQL is executed in MySQL, I want to start tracing only after initialization of MySQL, and finish tracing after that SQL, is it possible to capture traces for only a short time instead of the application's whole lifecycle?