~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
14 lines · 481 B Raw History
const std = @import("std");

pub const DurationProfile = struct {
    count: std.atomic.Value(u64) = .init(0),
    total_ns: std.atomic.Value(u64) = .init(0),
    max_ns: std.atomic.Value(u64) = .init(0),

    pub fn observe(self: *DurationProfile, elapsed: i96) void {
        const ns: u64 = @intCast(@max(0, elapsed));
        _ = self.count.fetchAdd(1, .monotonic);
        _ = self.total_ns.fetchAdd(ns, .monotonic);
        _ = self.max_ns.fetchMax(ns, .monotonic);
    }
};