1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! This crate provides simple bindings for Rust to the Sightglass API. The primary intent is to
//! make it easy to instrument Rust code that will be compiled to Wasm and measured with Sightglass.
//!
//! For example:
//! ```
//! use sightglass_api as bench;
//! bench::start();
//! let work = 42 * 42;
//! bench::end();
//! ```
//!
//! See [benchmarks-next/README.md] for more details.

mod ffi {
    #[link(wasm_import_module = "bench")]
    extern "C" {
        pub fn start();
        pub fn end();
    }
}

/// Call this once to end sightglass recording. When compiled to Wasm, the import will look
/// like `(import "bench" "end" (...))`.
pub fn start() {
    unsafe {
        ffi::start();
    }
}

/// Call this once to start sightglass recording. When compiled to Wasm, the import will look
/// like `(import "bench" "start" (...))`.
pub fn end() {
    unsafe {
        ffi::end();
    }
}