# uftrace

### Get utility

{% code title="Ubuntu X86\_64" %}

```bash
sudo apt install uftrace
```

{% endcode %}

{% code title="ARM64 in Yocto" %}

```bash
IMAGE_INSTALL_append = " uftrace"
```

{% endcode %}

{% code title="app.c" %}

```c
#include<stdio.h>

int main(void) {
        printf("This is app\n");
        sample_lib();
        return 0;
}
```

{% endcode %}

{% code title="sample lib.c" %}

```c
#include <stdio.h>
#include <time.h>

void sample_lib(void) {
        sleep(10);
        printf("Inside Library\n");
}
```

{% endcode %}

```bash
// Compiling library dynamically
gcc -fpic -shared -pg sample.c -o libsample.so

// compile app
gcc -pg app.c libsample.so -o app
```

{% hint style="info" %}
"-pg" option should be used for compiling app/libraries
{% endhint %}

```bash
export LD_LIBRARY_PATH=<path to so>
# execute app using uftrace
uftrace record ./app
```

```c
uftrace replay
# DURATION     TID     FUNCTION
            [645920] | main() {
  19.924 us [645920] |   puts();
            [645920] |   sample_lib() {
  10.000  s [645920] |     sample_lib();
  10.000  s [645920] |   } /* sample_lib */
  10.000  s [645920] | } /* main */

```

```c
 uftrace graph
# Function Call Graph for 'a.out' (session: e29b6ce8fa6d7e63)
========== FUNCTION CALL GRAPH ==========
# TOTAL TIME   FUNCTION
   10.000  s : (1) a.out
   10.000  s : (1) main
   19.924 us :  +-(1) puts
             :  |
   10.000  s :  +-(1) sample_lib
   10.000  s :    (1) sample_lib

```

#### TBD

* Live C programming&#x20;
* Display each line while executing ( similar to -x in bash )


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://explore-vineeth.gitbook.io/mywiki/how-to/tracing-+-profiling/uftrace.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
