Hey,

Today I spotted something very interesting in my Twitter (I’m @cirowrc there, by the way):

That’s right, dtrace functionality for Linux via eBPF “superpowers”.

To be very honest, I know almost nothing about dtrace itself, but I’ve heard about it many times - it brings to the operator a framework that allows he/she to observe what’s going on throughout the stack: be it in the user space, or the kernel space.

I’ll be taking a deeper look at it soon, but meanwhile, bpftrace is out there, and you can check it out right now!

In this quick post, you can check a sample Ansible that’s able to install the dependencies of bpftrace as well as build and install it.

The bpftrace ansible role

The role is pretty much a follow up of the INSTALL guide from bpftrace, targetting at an Ubuntu Bionic (18.04) installation.

---
- name: 'add llvm apt key'
  apt_key:
    url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
    state: 'present'

- name: 'add llvm apt repo'
  apt_repository:
    repo: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-6.0 main'
    state: 'present'
    update_cache: 'yes'

- name: 'install bpftrace dependencies'
  apt:
    update_cache: 'yes'
    cache_valid_time: 3600
    name: '{{ item }}'
    state: 'present'
  with_items:
    - 'bison'
    - 'clang-6.0'
    - 'clang-6.0-doc'
    - 'clang-tools-6.0'
    - 'cmake'
    - 'flex'
    - 'g++'
    - 'git'
    - 'libclang-6.0-dev'
    - 'libclang-common-6.0-dev'
    - 'libclang1-6.0'
    - 'libelf-dev'
    - 'libfl-dev'
    - 'libllvm6.0'
    - 'llvm-6.0'
    - 'llvm-6.0-dev'
    - 'llvm-6.0-runtime'
    - 'zlib1g-dev'


- name: 'clone bpftrace repository'
  git:
    repo: 'https://github.com/iovisor/bpftrace'
    dest: '/usr/share/bpftrace'
    force: 'yes'

- name: 'create build directory'
  file:
    path: '/usr/share/bpftrace/build'
    state: 'directory'
    mode: 0755

- name: 'prepare makefile'
  command: 'cmake -DCMAKE_BUILD_TYPE=DEBUG ..'
  args:
    chdir: '/usr/share/bpftrace/build'

- name: 'build'
  command: 'make -j3'
  args:
    chdir: '/usr/share/bpftrace/build'

- name: 'install'
  command: 'make -j3'
  args:
    chdir: '/usr/share/bpftrace/build'

Run it against your machine (with privileges) and you should be good to go!

You can find related roles (like one for installing bcc) here: github.com/cirocosta/mylinux.

Please let me know if you need any help! I’m cirowrc on Twitter.

Have a good one!