ark-api-ffi 0.16.0

Ark low-level Wasm FFI API
Documentation
define_api_id!(0x8459_b1a3_a7d6_4155, "profiler-v0");

use bytemuck::Pod;
use bytemuck::Zeroable;

/// `puffin::StreamInfo` minus the actual stream.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Pod, Zeroable)]
#[repr(C)]
pub struct StreamMeta {
    pub num_scopes: u64,
    pub depth: u64,
    pub range_ns_min: i64,
    pub range_ns_max: i64,
}

#[ark_api_macros::ark_bindgen(imports = "ark-profiler-v0")]
mod profiler {
    use super::StreamMeta;

    extern "C" {
        /// Returns the current time in nanoseconds
        ///
        /// Used for high precision profiling and is only supported for profiling. May return 0 if profiling is not enabled.
        /// Can't be used for absolute time determination, only relative difference between calls.
        #[deprecated_infallible]
        pub fn now_ns() -> i64;

        #[deprecated(note = "Use `report_thread_stream_info` instead")] // 2021-08-23
        #[deprecated_infallible]
        pub fn report_thread_stream(stream: &[u8]);

        /// Report Puffin profiler event stream.
        #[deprecated_infallible]
        pub fn report_thread_stream_info(meta: &StreamMeta, stream: &[u8]);

        /// Is the module-side profiler on?
        ///
        /// Call `puffin::set_scopes_on(ark::profiler::is_active());`
        /// at the top of each frame to heed this.
        pub fn is_active() -> bool;
    }
}

pub use profiler::*;