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
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use std::os::raw::{c_char, c_int};
use std::ffi::c_void;

#[repr(C)]
#[derive(Copy, Clone)]
pub struct ___tracy_source_location_data {
    pub name: *const c_char,
    pub function: *const c_char,
    pub file: *const c_char,
    pub line: u32,
    pub color: u32,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct TracyCZoneCtx {
    pub id: u32,
    pub active: c_int,
}

#[cfg(feature="enable")]
macro_rules! enabled_fn {
    (pub $($tokens: tt)*) => {
        extern "C" { pub $($tokens)*; }
    };
}

#[cfg(not(feature="enable"))]
macro_rules! enabled_fn {
    (pub $($tokens: tt)*) => {
        #[allow(non_snake_case, unused_variables)]
        #[inline(always)]
        pub unsafe extern "C" $($tokens)* { std::mem::zeroed() }
    };
}

enabled_fn! { pub fn ___tracy_init_thread() }
enabled_fn! { pub fn ___tracy_alloc_srcloc(
    line: u32,
    source: *const c_char,
    source_len: usize,
    function: *const c_char,
    function_len: usize
) -> u64 }
enabled_fn! { pub fn ___tracy_alloc_srcloc_name(
    line: u32,
    source: *const c_char,
    source_len: usize,
    function: *const c_char,
    function_len: usize,
    name: *const c_char,
    name_len: usize
) -> u64 }
enabled_fn! { pub fn ___tracy_emit_zone_begin(
    srcloc: *const ___tracy_source_location_data,
    active: c_int
) -> TracyCZoneCtx }
enabled_fn! { pub fn ___tracy_emit_zone_begin_callstack(
    srcloc: *const ___tracy_source_location_data,
    depth: c_int,
    active: c_int
) -> TracyCZoneCtx }
enabled_fn! { pub fn ___tracy_emit_zone_begin_alloc(
    srcloc: u64,
    active: c_int
) -> TracyCZoneCtx }
enabled_fn! { pub fn ___tracy_emit_zone_begin_alloc_callstack(
    srcloc: u64,
    depth: c_int,
    active: c_int
) -> TracyCZoneCtx }
enabled_fn! { pub fn ___tracy_emit_zone_end(ctx: TracyCZoneCtx) }
enabled_fn! { pub fn ___tracy_emit_zone_text(ctx: TracyCZoneCtx, txt: *const c_char, size: usize) }
enabled_fn! { pub fn ___tracy_emit_zone_name(ctx: TracyCZoneCtx, txt: *const c_char, size: usize) }
enabled_fn! { pub fn ___tracy_emit_zone_value(ctx: TracyCZoneCtx, value: u64) }
enabled_fn! { pub fn ___tracy_emit_memory_alloc(ptr: *const c_void, size: usize) }
enabled_fn! { pub fn ___tracy_emit_memory_alloc_callstack(ptr: *const c_void, size: usize, depth: c_int) }
enabled_fn! { pub fn ___tracy_emit_memory_free(ptr: *const c_void) }
enabled_fn! { pub fn ___tracy_emit_memory_free_callstack(ptr: *const c_void, depth: c_int) }
enabled_fn! { pub fn ___tracy_emit_message( txt: *const c_char, size: usize, callstack: c_int) }
enabled_fn! { pub fn ___tracy_emit_messageL( txt: *const c_char, callstack: c_int) }
enabled_fn! { pub fn ___tracy_emit_messageC( txt: *const c_char, size: usize, color: u32, callstack: c_int) }
enabled_fn! { pub fn ___tracy_emit_messageLC( txt: *const c_char, color: u32, callstack: c_int) }
enabled_fn! { pub fn ___tracy_emit_frame_mark(name: *const c_char) }
enabled_fn! { pub fn ___tracy_emit_frame_mark_start(name: *const c_char) }
enabled_fn! { pub fn ___tracy_emit_frame_mark_end(name: *const c_char) }
enabled_fn! { pub fn ___tracy_emit_frame_image(image: *const c_void, w: u16, h: u16, offset: u8, flip: c_int) }
enabled_fn! { pub fn ___tracy_emit_plot(name: *const c_char, val: f64) }
enabled_fn! { pub fn ___tracy_emit_message_appinfo(txt: *const c_char, size: usize) }

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn emit_zone() {
        unsafe {
            let srcloc = ___tracy_source_location_data {
                name: b"name\0".as_ptr() as _,
                function: b"function\0".as_ptr() as _,
                file: b"file\0".as_ptr() as _,
                line: 42,
                color: 0,
            };
            let zone_ctx = ___tracy_emit_zone_begin(&srcloc, 1);
            ___tracy_emit_zone_end(zone_ctx);
        }
    }

    #[test]
    fn emit_message_no_null() {
        unsafe {
            ___tracy_emit_message(b"hello world".as_ptr() as _, 11, 1);
        }
    }
}