Page MenuHomePhorge

debug.zig
No OneTemporary

Size
866 B
Referenced Files
None
Subscribers
None

debug.zig

const std = @import("std");
const builtin = @import("builtin");
pub var enabled: bool = false;
pub fn log(comptime fmt: []const u8, args: anytype) void {
if (!enabled) return;
var buf: [2048]u8 = undefined;
const msg = std.fmt.bufPrint(&buf, "[pkg] " ++ fmt ++ "\n", args) catch return;
if (comptime builtin.os.tag == .windows) {
const handle = std.os.windows.GetStdHandle(std.os.windows.STD_ERROR_HANDLE) catch return;
_ = std.os.windows.WriteFile(handle, msg, null) catch {};
} else _ = std.c.write(2, msg.ptr, msg.len);
}
pub fn timer(comptime label: []const u8, start: u64) u64 {
if (!enabled) return start;
const now = std.time.nanoTimestamp();
const elapsed_ns: u64 = @intCast(now - @as(i128, start));
const elapsed_ms = elapsed_ns / 1_000_000;
log("{s}: {d}ms", .{ label, elapsed_ms });
return @intCast(now);
}

File Metadata

Mime Type
text/plain
Expires
Sun, May 3, 7:20 AM (21 m, 37 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
533570
Default Alt Text
debug.zig (866 B)

Event Timeline