---
# System prepended metadata

title: Uftrace Note
tags: [uftrace, wsl, C, analysis]

---

First of all, download the latest version of `uftrace` from github. Since the version in WSL2 is 0.9.4 which haven't fix the **Segmentation Fault** bug.

## How to use?

1. Prepare the executable file
2. Record it
3. Report it

### Prepare the executable file

When compiling the project, must have the `-pg` flag in every `gcc` command if it contain the source file.

### Record
This command aims to execute the program and record it. You have to use record to further investigate.
```shell=
uftrace record a.out
```
You can trace specific functions using the `-F` option. In the following example, will trace the `main` function along with its associated child functions.
```shell=
uftrace record -F main a.out
```

After the record done, it may generate a folder `uftrace.data`

### Report
This command aims to calculate the statistical information of each function.
```shell=
uftrace report
```
Here is a example output
```
  Total time   Self time       Calls  Function
  ==========  ==========  ==========  ====================
   16.810 ms    2.055 us           1  main
   12.161 ms    0.267 us           1  parse
   12.085 ms   17.183 us           1  parse_internal
   12.046 ms   71.888 us         133  read_global_statement
   11.792 ms   97.457 us         124  read_global_decl
   10.174 ms   19.556 us         121  read_func_body
   10.146 ms  128.598 us         166  read_code_block
    9.099 ms  367.475 us         393  read_body_statement
    5.913 ms    2.447 ms        3283  get_next_token
    4.702 ms  139.796 us         427  read_expr
    3.268 ms  823.877 us       17001  lex_accept
    3.008 ms  521.614 us         619  read_expr_operand
    2.597 ms  143.835 us        1563  lex_expect
    2.583 ms  435.389 us           1  code_generate
    1.964 ms  981.237 us           1  elf_generate
    1.778 ms   91.470 us         100  read_body_assignment
    1.772 ms  327.819 us         323  read_lvalue
    1.706 ms  750.418 us         607  get_operator
    1.465 ms    1.465 ms       26738  strcmp
    1.197 ms   41.958 us         200  read_full_var_decl
    1.185 ms  127.270 us         693  lex_ident
    1.122 ms  438.821 us        8301  read_char
```