╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ tracy.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
189 return new_memory; 190 } else { 191 // No `messageColor` call here because this case is hit frequently in normal operation. 192 ___tracy_emit_memory_alloc_callstack(memory.ptr, memory.len, callstack_depth, 0); 193 return null; 194 } 195 } 196 197 fn freeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void { 198 const self: *Allocator = @ptrCast(@alignCast(ptr)); 199 assert(memory.len > 0); 200 ___tracy_emit_memory_free_callstack(memory.ptr, callstack_depth, 0); 201 self.parent_allocator.rawFree(memory, alignment, ret_addr); 202 } 203 }; 204 205 // This function only accepts comptime-known strings, see `messageCopy` for runtime strings 206 pub inline fn message(comptime msg: [:0]const u8) void { 207 messageColor(msg, 0); 208 } 209 210 // This function only accepts comptime-known strings, see `messageColorCopy` for runtime strings 211 pub inline fn messageColor(comptime msg: [:0]const u8, color: u24) void { 212 if (!enable) return; 213 ___tracy_emit_logStringL(.Info, color, callstack_depth, msg.ptr); 214 } 215 216 pub inline fn messageCopy(msg: []const u8) void { 217 messageColorCopy(msg, 0); 218 } 219 220 pub inline fn messageColorCopy(msg: []const u8, color: u24) void { 221 if (!enable) return; 222 ___tracy_emit_logString(.Info, color, callstack_depth, msg.len, msg.ptr); 223 } 224 225 /// Used to store strings which Tracy requires to have stable pointers for the program's entire 226 /// lifetime. All such strings will be leaked. 227 /// 228 /// The `enable` check ensures that this is not referenced if Tracy is disabled. 229 var tracy_arena: std.heap.ArenaAllocator = if (enable) .init(std.heap.page_allocator); 230 231 pub inline fn namedFrame(name: []const u8) Frame { 232 if (!enable) return .{ .name = {} }; 233 const stable_name = tracy_arena.allocator().dupeSentinel(u8, name, 0) catch @panic("tracy arena OOM"); 234 ___tracy_emit_frame_mark_start(stable_name.ptr); 235 return .{ .name = stable_name.ptr }; 236 } 237 238 pub const Frame = struct { 239 name: if (enable) [*:0]const u8 else void, 240 pub inline fn end(frame: Frame) void { 241 if (!enable) return; 242 ___tracy_emit_frame_mark_end(frame.name); 243 } 244 }; 245 246 pub const MessageSeverity = enum(i8) { 247 Trace, // Broadly track variable states and events in the software program. 248 Debug, // Describes variable states and details about specific internal events in the software, that are useful for investigations. 249 Info, // Describes normal events, which inform on the expected progress and state of your software. 250 Warning, // Describes potentially dangerous situations caused by unexpected events and states. 251 Error, // Describes the occurance of unexpected behavior. Does not interrupt the execution of the software. 252 Fatal, // Describes a critical event that will lead to a software failure/crash. 253 }; 254 255 pub const PlotConfig = struct { 256 format: Format, 257 mode: Mode, 258 fill: bool = true, 259 color: u24 = 0, 260 261 pub const Format = enum(i32) { 262 number = 0, 263 memory = 1, 264 percentage = 2, 265 watt = 3, 266 }; 267 268 pub const Mode = enum(i32) { 269 line = 0, 270 step = 1, 271 }; 272 }; 273 274 extern fn ___tracy_emit_frame_mark_start(name: [*:0]const u8) void; 275 extern fn ___tracy_emit_frame_mark_end(name: [*:0]const u8) void; 276 extern fn ___tracy_emit_zone_begin_callstack(srcloc: *const ___tracy_source_location_data, depth: i32, active: i32) ___tracy_c_zone_context; 277 extern fn ___tracy_emit_zone_text(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void; 278 extern fn ___tracy_emit_zone_name(ctx: ___tracy_c_zone_context, txt: [*]const u8, size: usize) void; 279 extern fn ___tracy_emit_zone_color(ctx: ___tracy_c_zone_context, color: u32) void; 280 extern fn ___tracy_emit_zone_value(ctx: ___tracy_c_zone_context, value: u64) void; 281 extern fn ___tracy_emit_zone_end(ctx: ___tracy_c_zone_context) void; 282 extern fn ___tracy_emit_memory_alloc_callstack(ptr: *const anyopaque, size: usize, depth: i32, secure: i32) void; 283 extern fn ___tracy_emit_memory_free_callstack(ptr: *const anyopaque, depth: i32, secure: i32) void; 284 extern fn ___tracy_emit_logString(severity: MessageSeverity, color: i32, callstack_depth: i32, size: usize, txt: [*]const u8) void; 285 extern fn ___tracy_emit_logStringL(severity: MessageSeverity, color: i32, callstack_depth: i32, txt: [*:0]const u8) void; 286 extern fn ___tracy_emit_plot_int(name: [*:0]const u8, val: i64) void; 287 extern fn ___tracy_emit_plot_config(name: [*:0]const u8, format: PlotConfig.Format, mode: PlotConfig.Mode, fill: i32, color: u32) void; 288 extern fn ___tracy_fiber_enter(fiber: [*:0]const u8) void; 289 extern fn ___tracy_fiber_leave() void; 290 291 const ___tracy_source_location_data = extern struct { 292 name: ?[*:0]const u8, 293 function: [*:0]const u8, 294 file: [*:0]const u8, 295 line: u32, 296 color: u32, 297 }; 298