.\" Automatically generated by Pandoc 2.9.2.1 .\" .TH "UFTRACE-GRAPH" "1" "Sep, 2018" "Uftrace User Manuals" "" .hy .SH NAME .PP uftrace-graph - Show function call graph .SH SYNOPSIS .PP uftrace graph [\f[I]options\f[R]] [\f[I]FUNCTION\f[R]] .SH DESCRIPTION .PP This command shows a function call graph for the binary or the given function in a uftrace record datafile. If the function name is omitted, whole function call graph will be shown. If user gives a function name it will show backtrace and calling functions. Each function in the output is annotated with a hit count and the total time spent running that function. .SH GRAPH OPTIONS .TP -f \f[I]FIELD\f[R], --output-fields=\f[I]FIELD\f[R] Customize field in the output. Possible values are: total, self and addr. Multiple fields can be set by using comma. Special field of `none' can be used (solely) to hide all fields. Default is `total'. See \f[I]FIELDS\f[R]. .TP \[en]task Print task graph instead of normal function graph. The each node in the output shows process or thread(printed in green color). .TP --srcline Show source location of each function if available. .TP --format=\f[I]TYPE\f[R] Show format style output. Currently, normal and html styles are supported. .SH COMMON OPTIONS .TP -F \f[I]FUNC\f[R], --filter=\f[I]FUNC\f[R] Set filter to trace selected functions and their children functions. This option can be used more than once. See \f[C]uftrace-replay\f[R](1) for an explanation of filters. .TP -N \f[I]FUNC\f[R], --notrace=\f[I]FUNC\f[R] Set filter not to trace selected functions and their children functions. This option can be used more than once. See \f[C]uftrace-replay\f[R](1) for an explanation of filters. .TP -C \f[I]FUNC\f[R], --caller-filter=\f[I]FUNC\f[R] Set filter to trace callers of selected functions only. This option can be used more than once. See \f[C]uftrace-replay\f[R](1) for an explanation of filters. .TP -T \f[I]TRG\f[R], --trigger=\f[I]TRG\f[R] Set trigger on selected functions. This option can be used more than once. See \f[C]uftrace-replay\f[R](1) for an explanation of triggers. .TP -D \f[I]DEPTH\f[R], --depth \f[I]DEPTH\f[R] Set trace limit in nesting level. .TP -t \f[I]TIME\f[R], --time-filter=\f[I]TIME\f[R] Do not show functions which run under the time threshold. If some functions explicitly have the `trace' trigger applied, those are always traced regardless of execution time. .TP --no-libcall Do not show library calls. .TP --no-event Do not show any events. Implies \f[C]--no-sched\f[R]. .TP --no-sched Do not show schedule events. .TP --match=\f[I]TYPE\f[R] Use pattern match using TYPE. Possible types are \f[C]regex\f[R] and \f[C]glob\f[R]. Default is \f[C]regex\f[R]. .SH COMMON ANALYSIS OPTIONS .TP -H \f[I]FUNC\f[R], --hide=\f[I]FUNC\f[R] Set filter not to trace selected functions. It doesn\[cq]t affect their subtrees, but hides only the given functions. This option can be used more than once. See \f[C]uftrace-replay\f[R](1) for an explanation of filters. .TP --kernel-full Show all kernel functions called outside of user functions. .TP --kernel-only Show kernel functions only without user functions. .TP --event-full Show all (user) events outside of user functions. .TP --tid=\f[I]TID\f[R][,\f[I]TID\f[R],\&...] Only print functions called by the given tasks. To see the list of tasks in the data file, you can use \f[C]uftrace report --task\f[R] or \f[C]uftrace info\f[R]. This option can also be used more than once. .TP --demangle=\f[I]TYPE\f[R] Use demangled C++ symbol names for filters, triggers, arguments and/or return values. Possible values are \[lq]full\[rq], \[lq]simple\[rq] and \[lq]no\[rq]. Default is \[lq]simple\[rq] which ignores function arguments and template parameters. .TP -r \f[I]RANGE\f[R], --time-range=\f[I]RANGE\f[R] Only show functions executed within the time RANGE. The RANGE can be \[ti] (separated by \[lq]\[ti]\[rq]) and one of and can be omitted. The and are timestamp or elapsed time if they have postfix, for example `100us'. The timestamp or elapsed time can be shown with \f[C]-f time\f[R] or \f[C]-f elapsed\f[R] option respectively in \f[C]uftrace replay\f[R](1). .SH EXAMPLES .PP This command show data like below: .IP .nf \f[C] $ uftrace record loop $ uftrace replay # DURATION TID FUNCTION [24447] | main() { [24447] | foo() { 8.134 us [24447] | loop(); 7.296 us [24447] | loop(); 7.234 us [24447] | loop(); 24.324 us [24447] | } /* foo */ [24447] | foo() { 7.234 us [24447] | loop(); 7.231 us [24447] | loop(); 7.231 us [24447] | loop(); 22.302 us [24447] | } /* foo */ [24447] | bar() { 10.100 ms [24447] | usleep(); 10.138 ms [24447] | } /* bar */ 10.293 ms [24447] | } /* main */ \f[R] .fi .PP Running the \f[C]graph\f[R] command shows function call graph like below: .IP .nf \f[C] $ uftrace graph # Function Call Graph for \[aq]loop\[aq] (session: 073f1e84aa8b09d3) ========== FUNCTION CALL GRAPH ========== 10.293 ms : (1) loop 10.293 ms : (1) main 46.626 us : +-(2) foo 44.360 us : | (6) loop : | 10.138 ms : +-(1) bar 10.100 ms : (1) usleep \f[R] .fi .PP The topmost node is not for function but for the executable. The left side shows total time running the function on the right side. The number in parentheses before the function name is the invocation count. As you can see, \f[C]main\f[R] was called once and ran around 10 msec. It called \f[C]foo\f[R] twice and then \f[C]foo\f[R] called \f[C]loop\f[R] 6 times in total. The time is the sum of all execution time of the function. .PP It can also be seen that \f[C]main\f[R] called \f[C]bar\f[R] once and that \f[C]bar\f[R] then called \f[C]usleep\f[R] once. To avoid too deep nesting level, it shows calls that have only a single call path at the same level. So \f[C]usleep\f[R] is not called from \f[C]main\f[R] directly. .PP Running the \f[C]graph\f[R] command on the \f[C]main\f[R] function shows called functions and backtrace like below: .IP .nf \f[C] $ uftrace graph main # Function Call Graph for \[aq]main\[aq] (session: 073f1e84aa8b09d3) =============== BACKTRACE =============== backtrace #0: hit 1, time 10.293 ms [0] main (0x4004f0) ========== FUNCTION CALL GRAPH ========== # TOTAL TIME FUNCTION 10.293 ms : (1) main 46.626 us : +-(2) foo 44.360 us : | (6) loop : | 10.138 ms : +-(1) bar 10.100 ms : (1) usleep \f[R] .fi .PP Note that the `main' is the top-level function so it has no backtrace above itself. Running graph command on a leaf function looks like below. .IP .nf \f[C] $ uftrace graph loop # Function Call Graph for \[aq]loop\[aq] (session: 073f1e84aa8b09d3) =============== BACKTRACE =============== backtrace #0: hit 6, time 44.360 us [0] main (0x4004b0) [1] foo (0x400622) [2] loop (0x400f5f6) ========== FUNCTION CALL GRAPH ========== # TOTAL TIME FUNCTION 44.360 us : (6) loop \f[R] .fi .PP The backtrace shows that loop is called from \f[C]foo\f[R] and that \f[C]foo\f[R] is called from \f[C]main\f[R]. Since \f[C]loop\f[R] is a leaf function, it didn\[cq]t call any other function. In this case, \f[C]loop\f[R] was called only from a single path so backtrace #0 is hit 6 times. .PP While graph command shows function-level call graph, \[en]task option makes the output in task-level graph which shows how processes and threads are created. The term here \f[C]task\f[R] includes process and thread. .PP For example, the task graph of GCC compiler can be shown as follows: .IP .nf \f[C] $ uftrace record --force /usr/bin/gcc hello.c $ uftrace graph --task ========== TASK GRAPH ========== # TOTAL TIME SELF TIME TID TASK NAME 159.854 ms 4.440 ms [ 82723] : gcc : | 90.951 ms 90.951 ms [ 82734] : +----cc1 : | 17.150 ms 17.150 ms [ 82735] : +----as : | 45.183 ms 6.076 ms [ 82736] : +----collect2 : | 38.880 ms 38.880 ms [ 82737] : +----ld \f[R] .fi .PP The above output shows \f[C]gcc\f[R] created \f[C]cc1\f[R], \f[C]as\f[R], and \f[C]collect2\f[R] processes then \f[C]collect2\f[R] created \f[C]ld\f[R] process. .PP \f[C]TOTAL TIME\f[R] is the lifetime of the task from its creation to termination, and \f[C]SELF TIME\f[R] is also lifetime, but it excludes internal idle time. \f[C]TID\f[R] is the thread id of the task. .PP The following shows task graph of uftrace recording itself. It shows uftrace created \f[C]t-abc\f[R] process, and also created many threads whose names are all \f[C]WriterThread\f[R]. .IP .nf \f[C] $ uftrace record -P. ./uftrace record -d uftrace.data.abc t-abc $ uftrace graph --task ========== TASK GRAPH ========== # TOTAL TIME SELF TIME TID TASK NAME 404.929 ms 321.692 ms [ 4230] : uftrace : | 278.662 us 278.662 us [ 4241] : +----t-abc : | 33.754 ms 4.061 ms [ 4242] : +-WriterThread 27.415 ms 120.992 us [ 4244] : +-WriterThread 27.212 ms 8.119 ms [ 4245] : +-WriterThread 26.754 ms 6.616 ms [ 4248] : +-WriterThread 26.859 ms 8.154 ms [ 4247] : +-WriterThread 26.509 ms 1.645 ms [ 4243] : +-WriterThread 25.320 ms 57.350 us [ 4246] : +-WriterThread 24.757 ms 4.391 ms [ 4249] : +-WriterThread 26.040 ms 3.707 ms [ 4250] : +-WriterThread 24.004 ms 3.999 ms [ 4251] : +-WriterThread \f[R] .fi .PP Please note that the indentation depth of thread is different from process. .PP Running the \f[C]graph\f[R] command with \f[C]--srcline\f[R] option shows source location in call graph like below: .IP .nf \f[C] $ uftrace record --srcline t-abc $ uftrace graph --srcline # Function Call Graph for \[aq]t-abc\[aq] (session: 60195bac953d8736) ========== FUNCTION CALL GRAPH ========== # TOTAL TIME FUNCTION [SOURCE] 8.909 us : (1) t-abc 1.260 us : +-(1) __monstartup : | 0.179 us : +-(1) __cxa_atexit : | 7.470 us : +-(1) main [tests/s-abc.c:26] 5.522 us : (1) a [tests/s-abc.c:11] 4.912 us : (1) b [tests/s-abc.c:16] 4.176 us : (1) c [tests/s-abc.c:21] 0.794 us : (1) getpid \f[R] .fi .SH FIELDS .PP The uftrace allows for user to customize the graph output with some of fields. Here the field means info on the left side of the colon (:) character. By default it uses time only, but you can use other fields in any order like: .IP .nf \f[C] $ uftrace record tests/t-abc $ uftrace graph -f total,self,addr # Function Call Graph for \[aq]t-sort\[aq] (session: b007f4b7cf792878) ========== FUNCTION CALL GRAPH ========== # TOTAL TIME SELF TIME ADDRESS FUNCTION 10.145 ms 561f652cd610 : (1) t-sort 10.145 ms 39.890 us 561f652cd610 : (1) main 16.773 us 0.734 us 561f652cd7ce : +-(2) foo 16.039 us 16.039 us 561f652cd7a0 : | (6) loop : | 10.088 ms 14.740 us 561f652cd802 : +-(1) bar 10.073 ms 10.073 ms 561f652cd608 : (1) usleep \f[R] .fi .PP Each field has following meaning: .IP \[bu] 2 total: function execution time in total .IP \[bu] 2 self : function execution time excluding its children\[cq]s .IP \[bu] 2 addr : address of the function .PP The default value is `total'. If given field name starts with \[lq]+\[rq], then it\[cq]ll be appended to the default fields. So \[lq]-f +addr\[rq] is as same as \[lq]-f total,addr\[rq]. And it also accepts a special field name of `none' which disables the field display and shows function output only. .IP .nf \f[C] $ uftrace graph -f none # Function Call Graph for \[aq]t-sort\[aq] (session: b007f4b7cf792878) ========== FUNCTION CALL GRAPH ========== (1) t-sort (1) main +-(2) foo | (6) loop | +-(1) bar (1) usleep \f[R] .fi .PP This output can be useful when comparing two different call graph outputs using diff tool. .PP It also supports field customization for task graph. The default field is set to \f[C]total,self,tid\f[R], but the field option can also be used as follows: .IP .nf \f[C] $ uftrace graph --task -f tid,self ========== TASK GRAPH ========== # TID SELF TIME TASK NAME [ 82723] 4.440 ms : gcc : | [ 82734] 90.951 ms : +----cc1 : | [ 82735] 17.150 ms : +----as : | [ 82736] 6.076 ms : +----collect2 : | [ 82737] 38.880 ms : +----ld \f[R] .fi .PP Each field has following meaning: .IP \[bu] 2 total: total task lifetime from its creation to termination .IP \[bu] 2 self : task execution time excluding its idle time .IP \[bu] 2 tid : task id (obtained by gettid(2)) .PP It also accepts a special field \f[C]none\f[R], which hides all the fields on the left. .IP .nf \f[C] $ uftrace graph --task -f none ========== TASK GRAPH ========== gcc | +----cc1 | +----as | +----collect2 | +----ld \f[R] .fi .SH SEE ALSO .PP \f[C]uftrace\f[R](1), \f[C]uftrace-record\f[R](1), \f[C]uftrace-replay\f[R](1), \f[C]uftrace-tui\f[R](1) .SH AUTHORS Namhyung Kim .