Search code examples
parsingawkftrace

How can I parse the output of trace-cmd report using awk?


The only thing I need to see in the output is which functions were called.

Input:

ibv_rc_pingpong-759367 [005] 8391981.416466: funcgraph_entry:                   |  ib_enum_all_devs() {
ibv_rc_pingpong-759367 [005] 8391981.416472: funcgraph_entry:      + 29.337 us  |    ib_get_device_fw_str();
ibv_rc_pingpong-759367 [005] 8391981.416504: funcgraph_exit:       + 38.787 us  |  }
ibv_rc_pingpong-759367 [005] 8391981.416543: funcgraph_entry:        1.191 us   |  ib_enum_all_devs();
ibv_rc_pingpong-759367 [005] 8391981.416621: funcgraph_entry:        1.371 us   |  ib_device_get_by_index();
ibv_rc_pingpong-759367 [005] 8391981.416624: funcgraph_entry:                   |  ib_get_client_nl_info() {
ibv_rc_pingpong-759367 [005] 8391981.416628: funcgraph_entry:        0.890 us   |    ib_uverbs_get_nl_info();
ibv_rc_pingpong-759367 [005] 8391981.416630: funcgraph_exit:         6.174 us   |  }

The output should look like this:

ib_enum_all_devs() {
 ib_get_device_fw_str();
}
ib_enum_all_devs();
ib_device_get_by_index();
ib_get_client_nl_info() {
 ib_uverbs_get_nl_info();
}

This is what I tried:

cat myfile.dat | awk '{print $7}'

However, this gives me garbage.


Solution

  • Why don't you use the pipe character as a field separator?

    cat myfile.dat | awk -F "|" '{print $2}'
    

    ... and as usual I've done a useless use of cat:

    awk -F "|" '{print $2}' file.txt