tiny.profiling.fingerprint
Defined in tiny.profiling.
API (5)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
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.
tiny.profiling.experiment.oracle.verify[function] atsrc/profiling/experiment/oracle.zig:24src.profiling.experiment.oracle.verifyFiles[function] — private; no exact target atsrc/profiling/experiment/oracle.zig:60in nearest public ownertiny.profiling.experiment.oraclesrc.profiling.experiment.run.prepareContext[function] — private; no exact target atsrc/profiling/experiment/run.zig:128in nearest public ownertiny.profiling.experiment.runsrc.profiling.experiment.variant.archivePrepared[function] — private; no exact target atsrc/profiling/experiment/variant.zig:282in nearest public ownertiny.profiling.experiment.variantsrc.profiling.fingerprint.test_profiling_fingerprint_hashes_empty_files_without_allocation[function] — test; no exact target atsrc/profiling/fingerprint.zig:49in nearest public ownertiny.profiling.fingerprinttiny.profiling.iteration.run.execute[function] atsrc/profiling/iteration/run.zig:67src.profiling.iteration.run.prepareSource[function] — private; no exact target atsrc/profiling/iteration/run.zig:333in nearest public ownertiny.profiling.iteration.runsrc.profiling.iteration.run.replaceExact[function] — private; no exact target atsrc/profiling/iteration/run.zig:400in nearest public ownertiny.profiling.iteration.runsrc.profiling.reduction.loadProcess[function] — private; no exact target atsrc/profiling/reduction.zig:390in nearest public ownertiny.profiling.reduction
Audit
| Definitions | 6 |
|---|---|
| Public names | 6 |
| Members | 2 |
| Version | 26.7.0 |
| Revision | daab053ee433 |