tiny.profiling.ingest.selector
Defined in ingest.
API (3)
Actions
Public operations.
Values and defaults
Public values and defaults.
Source
Source: src/profiling/ingest/root.zig:6
zig
pub const selector = @import("selector.zig");Source: src/profiling/ingest/selector.zig
zig
const std = @import("std");const ingest = @import("root.zig");pub const upstream_repository = "https://github.com/simdjson/simdjson";pub const upstream_revision = "8e6bac94877f2d3d026000d36ce81e0aaf38d26f";const slot_count = 64;const empty = std.math.maxInt(u8);const Entry = struct { name: []const u8, field: ingest.event.Field,};const entries = [_]Entry{ .{ .name = "schema", .field = .schema }, .{ .name = "event", .field = .event }, .{ .name = "kind", .field = .kind }, .{ .name = "summary", .field = .summary }, .{ .name = "sample_ns", .field = .sample_ns }, .{ .name = "mean_ns", .field = .mean_ns }, .{ .name = "median_ns", .field = .median_ns }, .{ .name = "p95_ns", .field = .p95_ns }, .{ .name = "p99_ns", .field = .p99_ns }, .{ .name = "alloc_bytes", .field = .alloc_bytes }, .{ .name = "alloc_count", .field = .alloc_count }, .{ .name = "value", .field = .value }, .{ .name = "mean", .field = .mean }, .{ .name = "median", .field = .median }, .{ .name = "allocated_bytes", .field = .allocated_bytes }, .{ .name = "retained_bytes", .field = .retained_bytes }, .{ .name = "high_water_live_bytes", .field = .high_water_live_bytes }, .{ .name = "len", .field = .len }, .{ .name = "old_len", .field = .old_len }, .{ .name = "new_len", .field = .new_len },};const slots = buildSlots();comptime { if (!std.math.isPowerOfTwo(slot_count)) @compileError("selector slot count must be a power of two"); if (entries.len >= empty) @compileError("selector entry index exceeds its representation");}pub fn field(hash: u64, key: []const u8) ingest.event.Field { const slot = @as(usize, @intCast(hash & (slot_count - 1))); const index = slots[slot]; if (index == empty) return .other; const entry = entries[index]; return if (std.mem.eql(u8, key, entry.name)) entry.field else .other;}fn buildSlots() [slot_count]u8 { var result: [slot_count]u8 = @splat(empty); for (entries, 0..) |entry, index| { const hash = std.hash.Wyhash.hash(ingest.duplicate.hash_seed, entry.name); const slot = @as(usize, @intCast(hash & (slot_count - 1))); if (result[slot] != empty) @compileError("selector hash seed is not collision free"); result[slot] = @intCast(index); } return result;}test "on demand field selector has one exact candidate per known key" { try std.testing.expectEqual(@as(usize, 20), entries.len); for (entries, 0..) |entry, index| { try std.testing.expectEqual(index, @backingInt(entry.field)); const hash = std.hash.Wyhash.hash(ingest.duplicate.hash_seed, entry.name); try std.testing.expectEqual(entry.field, field(hash, entry.name)); } var occupied_miss = false; for ([_][]const u8{ "schemas", "events", "allocated_count", "high_water_live_byte", "new_lens", "unknown", "kindred", "sample_ns_extra", }) |unknown| { const hash = std.hash.Wyhash.hash(ingest.duplicate.hash_seed, unknown); const slot = @as(usize, @intCast(hash & (slot_count - 1))); occupied_miss = occupied_miss or slots[slot] != empty; try std.testing.expectEqual(ingest.event.Field.other, field(hash, unknown)); } try std.testing.expect(occupied_miss);}Audit
| Definitions | 4 |
|---|---|
| Public names | 4 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |