Crate libtracecmd

source ·
Expand description

This library is a Rust wrapper of libtracecmd, which allows writing programs to analyze Linux’s ftrace data generated by trace-cmd.

Running a Sample Program

To get familiar with using this library, you can start by running a sample program.

Preliminary

First, make sure that CONFIG_FTRACE and CONFIG_FTRACE_SYSCALLS are enabled in your Linux kernel. Then, install a trace-cmd binary and libraries to analyze trace data files. If you use Debian or Ubuntu, they should be installed with the following command:

$ sudo apt install \
    trace-cmd \
    libtracefs-dev \
    libtraceevent-dev \
    libtracecmd-dev

Get tracing record

Run trace-cmd record along with your own workloads to record trace events.

# Trace all syscalls called on your system during 10 seconds.
$ trace-cmd record -e syscalls sleep 10
# Then, you can run your own workload to be traced.

Then, you’ll find trace.dat in the current directory.

Analyze trace.dat with a sample program

Now, you can run a sample code top_n_events to analyze the trace.dat.

$ git clone git@github.com:google/libtracecmd-rs.git
$ cd ./libtracecmd-rs
$ cargo run --example top_n_events -- --input ./trace.dat --n 10 --prefix sys_enter_

Then, you’ll get output like the followings:

Top 10 events:
#1: ioctl: 62424 times
#2: futex: 59074 times
#3: read: 30144 times
#4: write: 28361 times
#5: newfstatat: 22590 times
#6: close: 15893 times
#7: splice: 14650 times
#8: getuid: 13579 times
#9: epoll_pwait: 12298 times
#10: ppoll: 10523 times

Writing your own code with the library

See the documenation on Handler.

Structs

  • A wrapper of tep_event.
  • A wrapper of tep_handle, the main structure representing the trace event parser context.
  • A wrapper of tracecmd_input represnting a trace.dat file given as the input.
  • A wrapper of tep_record.

Enums

  • Errors that can happen while processing tracing data.

Traits

  • A trait to iterate over trace events and process them one by one.