sys rust_hawktracer

Rust bindings for hawktracer profiling library

2 releases

0.1.1 Sep 16, 2018
0.1.0 Sep 15, 2018

#36 in Profiling

Download history 22/week @ 2018-09-18 2/week @ 2018-09-25 11/week @ 2018-10-02 4/week @ 2018-10-09 16/week @ 2018-10-16 27/week @ 2018-10-23 8/week @ 2018-10-30 37/week @ 2018-11-06 15/week @ 2018-11-13 10/week @ 2018-11-20 11/week @ 2018-11-27 26/week @ 2018-12-04 12/week @ 2018-12-11

5 downloads per month


6.5K SLoC

C++ 4.5K SLoC // 0.1% comments C 1.5K SLoC // 0.0% comments Python 410 SLoC Rust 335 SLoC // 0.4% comments Shell 41 SLoC

Crates.io Build Status Build status


Rust bindings for the Hawktracer profiler.
This crate offers simple, minimal bindings to help you profile your rust programs.
If profiling is not enabled by specifying features=["profiling_enabled"], having tracepoints in your code has absolutely no overhead (everything gets removed at compile time).

alt text

Tools needed

You need an external tool in order to transform captured profiling data from a binary format to something that can be interpreted by chrome:://tracing (or other clients).

I recommend downloading the binaries from the official hawktracer release.

For platforms that don't have a binary release you can build it from the main hawktracer repo.

Profiling code

In Cargo.toml:

version = "0.3.1"

If the bindings that come with it don't match what your platform expects change it to:

features=["profiling_enabled", "generate_bindings"]

In your main.rs:

extern crate rust_hawktracer;
use rust_hawktracer::*;
use std::{thread, time};

fn main() {
    let instance = HawktracerInstance::new();
    let _listener = instance.create_listener(HawktracerListenerType::ToFile {
        file_path: "trace.bin".into(),
        buffer_size: 4096,

    // For a networked listner
    // let _listener = instance.create_listener(HawktracerListenerType::TCP {
    //     port: 12345,
    //     buffer_size: 4096,
    // });

    println!("Hello, world!");

            for _ in 0..10 {


If you use HawktracerListenerType::ToFile:

.\hawktracer-converter.exe --source trace.bin --output trace.json

If you use HawktracerListenerType::TCP you can listen and capture traces by specifying the IP:port as the --source parameter:

.\hawktracer-converter.exe --source --output trace.json

Open a chrome browser and go to this address: chrome://tracing/

By opening the trace.json for the program above you should see something like:

alt text

Things to watch out for

In rust macros I can't create new identifier names. This means that if you want to avoid warnings, the tracepoint names have to start with a leading _, as in scoped_tracepoint!(_my_tracepoint_name).


Licensed under either of

at your option.



  • links hawktracer
  • build build.rs
  • build cmake 0.1
  • build optional bindgen 0.37