#profiling

sys rust_hawktracer

Rust bindings for hawktracer profiling library

2 releases

0.1.1 Sep 16, 2018
0.1.0 Sep 15, 2018

#30 in Profiling

Download history 16/week @ 2018-09-17

5 downloads per month

MIT/Apache

357KB
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_hawktracer

Rust bindings for Amazon's Hawktracer profiler. This offers simple, minimal bindings to help you profile your programs.

alt text

Warning

You need an external tool in order to transform bindings from a binary format to something that can be interpreted by chrome:://tracing This tool can be build for now from the main hawktracer repo (client/hawktracer-to-json). I recommend taking the binaries from the official rust_hawktracer releases: https://github.com/amzn/hawktracer/releases/tag/v0.6.0

How to use

In Cargo.toml:

[dependencies.rust_hawktracer]
version = "0.3.0"
features=["profiling_enabled"]

In your main.rs:

#[macro_use]
extern crate rust_hawktracer;
use rust_hawktracer::*;
use std::{thread, time};

fn main() {
    let mut 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!");
    {
        scoped_tracepoint!(_test);
        thread::sleep(time::Duration::from_millis(10));

        {
            for _ in 0..10 {
                scoped_tracepoint!(_second_tracepoint);
                thread::sleep(time::Duration::from_millis(10));
            }
        }
    }
}

Visualization

Download hawktracer-converter.exe and use it like this:
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 127.0.0.1:12345 --output trace_12345.json

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

For the program above you should see the following trace:

alt text

Things to watch out for.

In rust macros I can't create new variable names right now, this means that if you want to avoid warnings, the tracepoint variable names have to start with a leading _, as in scoped_tracepoint!(_second_tracepoint). If you figure out a way to do this, feel free to raise a PR / issue.

License

Licensed under either of

at your option.

Dependencies

~269KB

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