Skip to documentation
SLOP

tiny.profiling.fingerprint

Reference tiny.profiling fingerprint

Defined in tiny.profiling.

API (5)

Actions

Public operations.

Types and contracts

Public types and contracts.

No direct callersNo direct callstiny.profilingfingerprint
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallsNo direct callsexperiment.oracleverifyprivate; no linksrc.profiling.experiment.oracleverifyFilesprivate; no linksrc.profiling.experiment.runprepareContextprivate; no linksrc.profiling.experiment.variantarchivePreparedtest; no linksrc.profiling.fingerprinttest: profiling fingerprint hashes em...+4 morefingerprintinspect
Static calls · unresolved targets: 2 · external targets: 7.

Source: src/profiling/fingerprint.zig

zig
const std = @import("std");const sys = @import("sys");pub const Digest = [std.crypto.hash.sha2.Sha256.digest_length]u8;pub const Hex = [std.crypto.hash.sha2.Sha256.digest_length * 2]u8;pub const File = struct {    bytes: u64,    sha256: Digest,    pub fn hex(self: File) Hex {        return std.fmt.bytesToHex(self.sha256, .lower);    }};pub fn inspect(path: []const u8) !File {    var file = if (std.fs.path.isAbsolute(path))        try sys.fs.openAbsoluteFile(path, .{})    else        try sys.fs.cwd().openFile(sys.fs.debugIo(), path, .{});    defer file.close(sys.fs.debugIo());    const before = try file.stat(sys.fs.debugIo());    var hasher = std.crypto.hash.sha2.Sha256.init(.{});    var reader_buffer: [16 * 1024]u8 = undefined;    var chunk: [16 * 1024]u8 = undefined;    var reader = file.reader(sys.fs.debugIo(), &reader_buffer);    var bytes: u64 = 0;    while (true) {        const count = reader.interface.readSliceShort(&chunk) catch |err| switch (err) {            error.ReadFailed => return reader.err orelse error.ReadFailed,        };        if (count == 0) break;        hasher.update(chunk[0..count]);        bytes = std.math.add(u64, bytes, count) catch return error.FileTooLarge;    }    const after = try file.stat(sys.fs.debugIo());    if (before.size != after.size or        before.inode != after.inode or        !std.meta.eql(before.mtime, after.mtime) or        bytes != after.size)    {        return error.InputChanged;    }    var digest: Digest = undefined;    hasher.final(&digest);    return .{ .bytes = bytes, .sha256 = digest };}test "profiling fingerprint hashes empty files without allocation" {    var temporary = std.testing.tmpDir(.{});    defer temporary.cleanup();    try temporary.dir.writeFile(std.Options.debug_io, .{        .sub_path = "empty",        .data = "",    });    var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena_state.deinit();    const path = try temporary.parent_dir.realPathFileAlloc(        std.Options.debug_io,        temporary.sub_path[0..],        arena_state.allocator(),    );    const file_path = try std.fs.path.join(        arena_state.allocator(),        &.{ path, "empty" },    );    const result = try inspect(file_path);    const result_hex = result.hex();    try std.testing.expectEqual(@as(u64, 0), result.bytes);    try std.testing.expectEqualStrings(        "e3b0c44298fc1c149afbf4c8996fb924" ++            "27ae41e4649b934ca495991b7852b855",        &result_hex,    );}

Source: src/profiling/root.zig:25

zig
pub const fingerprint = @import("fingerprint.zig");

Complete caller list for fingerprint.inspect

9 direct callers.

Audit

Definitions6
Public names6
Members2
Version26.7.0
Revisiondaab053ee433