• This repository has been archived on 08/Oct/2019
  • Stars
    star
    211
  • Rank 186,867 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust support for the coz Causal profiler, code now lives upstream -- https://github.com/plasma-umass/coz

coz-rs

Note: the official source of this crate now lives upstream in the main coz repository, it's recommended to use that instead of this repository, and file issues/changes there instead of here.

Rust support for the coz Causal Profiler

Documentation

Usage

First, follow the instructions in coz to install the coz command.

Next, coz is a profiler that, for the best results, typically requires source-level modifications of your code. To do this first add this to your Cargo.toml

[dependencies]
coz = "0.1"

Then you'll want to either at throughput or latency tracepoints. More information on this can be found upstream. If you have something you'd wish whould execute more often, you can add:

fn main() {
    loop {
        // ...

        // For example you wish this `loop` executed more iterations
        coz::progress!(); // equivalent of `COZ_PROGRESS`
    }
}

Note that coz::progress!("name") is the equivalent of COZ_PROGRESS_NAMED as well.

If you'd like to profile the latency of an operation you can instead use:

// Boy I wish this function executed more quickly...
fn foo() {
    coz::begin!("foo");

    // ...

    coz::end!("foo");
}

If you have a lexical scope, you can also use the coz::scope!(name) macro to place begin and end markers for you:

// Boy I wish this function executed more quickly...
fn scope_me() {
    coz::scope!("foo");

    // ...
}

This has the added benefit that it will place the end marker even on early exit, such as return, ? or panic!.

After you've instrumented your code, you need to also ensure that you're compiling with DWARF debug information. To do this you'll want to configure Cargo.toml again:

[profile.release]
debug = 1

Next up you'll build your application with cargo build --release, and then finally you can run it with coz run --- ./target/release/$your_binary.

Caveats

Known caveats so far to generate a report that collects information are:

  • Rust programs by default segfault when run with coz with an issue related to plasma-umass/coz#110. Rust programs set up a sigaltstack to run segfault handlers to print "you ran out of stack", but this alternate stack is too small to run the SIGPROF handler that coz installs. To handle this this crate provides a coz::thread_init() function which will increase the sigaltstack size that Rust installs by default to something large enough to run coz. If you see segfaults, or corrupt reports, you may wish to manually call coz::thread_init() instead of waiting for this crate to automatically call it for you.

  • Debug information looks to be critical to get a report from coz. Make sure that your program is compiled with at least line-table information (debug = 1) to ensure you get the best experience using coz.

  • Currently coz only works on Linux, and while this crate should compile on all platforms it only actually does something on Linux.

Examples

You can find an example toy program at examples/toy.rs in this repository, and we can execute it with coz:

$ cargo build --release
$ coz run --- ./target/release/examples/toy
...
[profiler.cpp:75] Starting profiler thread
$

That should generate profile.coz in the current directory, which if you plot that should look something like this:

plot of toy.rs

Note that I'm still learning myself the best sorts of applications to run on as well as the best sorts of questions to ask coz and where to put latency/throughput points. If you've got ideas or good examples, please feel free to add them here!

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

More Repositories

1

rust-ffi-examples

FFI examples written in Rust
Makefile
1,160
star
2

curl-rust

Rust bindings to libcurl
Rust
1,015
star
3

toml-rs

A TOML encoding/decoding library for Rust
Rust
994
star
4

futures-await

Rust
733
star
5

tar-rs

Tar file reading/writing for Rust
Rust
551
star
6

ssh2-rs

Rust bindings for libssh2
Rust
479
star
7

cargo-vendor

Archived as subcommand is now part of Cargo itself
Rust
260
star
8

wasm-gc

gc-sections for wasm
Rust
247
star
9

tokio-process

Asynchronous process management for tokio
Rust
146
star
10

tokio-curl

Asynchronous HTTP client built on libcurl
Rust
108
star
11

filetime

Accessing file timestamps in a platform-agnostic fashion in Rust
Rust
108
star
12

tokio-signal

Unix signal handling for tokio
Rust
87
star
13

rlibc

77
star
14

bzip2-rs

libbz2 (bzip2 compression) bindings for Rust
C
77
star
15

dlmalloc-rs

dlmalloc ported into Rust
C
75
star
16

openssl-src-rs

Source code and logic to build OpenSSL from source
Rust
71
star
17

xz2-rs

Bindings to liblzma in Rust (xz streams in Rust)
Rust
65
star
18

wait-timeout

Waiting on a child process with a timeout in Rust
Rust
57
star
19

green-rs

Green Tasks for Rust
Rust
54
star
20

openssl-probe

Rust
51
star
21

socks5-rs

Implementation of a socks5 proxy server in Rust
Rust
49
star
22

jba

Javascript Gameboy
JavaScript
42
star
23

bufstream

A buffered I/O stream for Rust
Rust
30
star
24

wasm-interface-types-polyfill

Polyfill for WebAssembly Interface Types
Rust
25
star
25

wasm-sodium

PoC of libsodium being used in Rust on wasm32-unknown-unknown
Rust
25
star
26

port-of-rust

Docker images for Rust projects
Shell
24
star
27

splay-rs

A splay tree implementation written in Rust
Rust
24
star
28

talks

Talks I've given at various conferences
18
star
29

debug-cell

Debug RefCell which keeps track of stack traces in debug mode
Rust
18
star
30

link-config

Rust
17
star
31

nghttp2-rs

Rust
17
star
32

rack-shibboleth

Shibboleth meets Ruby and Rack
Ruby
17
star
33

rust-wasm-benchmark

JavaScript
14
star
34

cargo-fancy

Fancy output for Cargo
Rust
13
star
35

wbg-rand

Random numbers for wasm32-unknown-unknown in Rust
Rust
12
star
36

ipc-rs

IPC primitives for Rust
Rust
11
star
37

rustfmt-wasm

Dockerfile
9
star
38

oa-pubcookie

OmniAuth strategy when using Pubcookie or CMU's WebISO
Ruby
8
star
39

homebrew-formula

Ruby
7
star
40

paste

JS + CSS dependency managament for Rails 3
Ruby
7
star
41

rack-pubcookie

Pubcookie finally isn't tied to Apache, now it's in Ruby!
Ruby
7
star
42

cfg-specialize

Rust
7
star
43

rustc-auto-publish

Rust
6
star
44

tokio-named-pipes

Windows named pipes bindings for tokio
Rust
6
star
45

l4c

Rust
6
star
46

memset-nt

Non-temporal memset for RUst
Rust
6
star
47

wasm-cross-lang-lto-example

Shell
6
star
48

glimmer-experiments

Rust
6
star
49

witx-async-demo

Rust
5
star
50

xxhash2-rs

Rust bindings to libxxhash
Rust
5
star
51

hacku

hacku
JavaScript
4
star
52

socparse

Ruby
4
star
53

example-wasi-tools

Rust
4
star
54

differential-wasmtime-v8

Rust
4
star
55

golden-circle

The Golden Circle website registration and grading application
JavaScript
4
star
56

openssl-sys

Rust
4
star
57

futures-await-syn

futures-await temporary fork of dtolnay/syn
Rust
3
star
58

oddit

Oddit - Auditing application for CMU students
Ruby
3
star
59

rust-fannkuch-js-and-wasm

Rust
3
star
60

my-awesome-wasi-proposal

3
star
61

futures-spsc

Single-producer, single-consumer queues for Rust futures
Rust
3
star
62

rust-travis-deploy

Moved to https://github.com/rust-lang/simpleinfra
Rust
3
star
63

fargo

A DC protocol implementation in Ruby
Ruby
2
star
64

stamp-rs

Rust
2
star
65

twocan

Collaborative Crosswords!
Ruby
2
star
66

www

HTML
2
star
67

eeyore

Label tagging bot
Rust
2
star
68

io2

Rust
2
star
69

complicated-linkage-example

Rust
2
star
70

cpu-usage-over-time

Rust
2
star
71

conduit-git-http-backend

Conduit handler for running `git http-backend`
Rust
2
star
72

rustjob

Rust
2
star
73

tls-rs

Thread-Local-Storage (TLS) for Rust
2
star
74

movies

A proposed solution to the Movie Chain Runner problem
C
2
star
75

rbindgen

Rust
2
star
76

rustc-compile-time-analyze

Rust
1
star
77

dcfs

A FUSE filesystem over the DC protocol
Ruby
1
star
78

example-wasi-abi-up-to-date

JavaScript
1
star
79

wasmtime-unwinding-timings

Rust
1
star
80

crates.io-index-2018-09-20-squashed

Shell
1
star
81

futures-await-quote

futures-await temporary fork of dtolnay/quote
Rust
1
star
82

futures-tools

1
star
83

longjmp-repro

Rust
1
star
84

ars

ar in Rust
Rust
1
star
85

weird-proc-macro-spans

Rust
1
star
86

cargo-apply

Rust
1
star
87

recipe_box

Recipe Box as a web application
Ruby
1
star
88

bors2

WIP
Rust
1
star
89

webpush-server-proof-of-concept

Rust
1
star
90

rustc-test

Extraction of libtest from rustc
Rust
1
star
91

cohort_radio

The best radio ever
Ruby
1
star
92

wasm64-timings

Rust
1
star