tiny.profiling.report.format
Defined in report.
API (9)
Actions
Public operations.
Types and contracts
Public types and contracts.
Source
Source: src/profiling/report/format.zig
zig
const std = @import("std");const Allocator = std.mem.Allocator;pub const Error = Allocator.Error;pub fn ns(allocator: Allocator, value: f64) Error![]u8 { const magnitude = @abs(value); if (magnitude < 1_000) return std.fmt.allocPrint(allocator, "{d:.0} ns", .{value}); if (magnitude < 1_000_000) return std.fmt.allocPrint(allocator, "{d:.1} µs", .{value / 1_000}); if (magnitude < 1_000_000_000) return std.fmt.allocPrint(allocator, "{d:.1} ms", .{value / 1_000_000}); if (magnitude < 60 * 1_000_000_000) return std.fmt.allocPrint(allocator, "{d:.2} s", .{value / 1_000_000_000}); const total_seconds = value / 1_000_000_000; const minutes = @divTrunc(total_seconds, 60); return std.fmt.allocPrint(allocator, "{d:.0} m {d:.0} s", .{ minutes, total_seconds - minutes * 60 });}pub fn kib(allocator: Allocator, value: f64) Error![]u8 { const magnitude = @abs(value); if (magnitude < 1024) return std.fmt.allocPrint(allocator, "{d:.0} KiB", .{value}); if (magnitude < 1024 * 1024) return std.fmt.allocPrint(allocator, "{d:.1} MiB", .{value / 1024}); return std.fmt.allocPrint(allocator, "{d:.2} GiB", .{value / (1024 * 1024)});}pub fn bytes(allocator: Allocator, value: f64) Error![]u8 { const magnitude = @abs(value); if (magnitude < 1024) return std.fmt.allocPrint(allocator, "{d:.0} B", .{value}); return kib(allocator, value / 1024);}pub fn count(allocator: Allocator, value: f64) Error![]u8 { const magnitude = @abs(value); if (magnitude < 10_000) return std.fmt.allocPrint(allocator, "{d:.0}", .{value}); if (magnitude < 1_000_000) return std.fmt.allocPrint(allocator, "{d:.1} k", .{value / 1_000}); if (magnitude < 1_000_000_000) return std.fmt.allocPrint(allocator, "{d:.1} M", .{value / 1_000_000}); return std.fmt.allocPrint(allocator, "{d:.1} G", .{value / 1_000_000_000});}pub fn percent(allocator: Allocator, value: f64) Error![]u8 { if (value >= 0) return std.fmt.allocPrint(allocator, "+{d:.1}%", .{value}); return std.fmt.allocPrint(allocator, "{d:.1}%", .{value});}pub fn seconds(allocator: Allocator, value: f64) Error![]u8 { return ns(allocator, value * 1_000_000_000);}pub fn timestamp(allocator: Allocator, unix_ns: i128) Error![]u8 { if (unix_ns <= 0) return allocator.dupe(u8, "unknown"); const secs: u64 = @intCast(@divTrunc(unix_ns, std.time.ns_per_s)); const epoch_seconds = std.time.epoch.EpochSeconds{ .secs = secs }; const year_day = epoch_seconds.getEpochDay().calculateYearDay(); const month_day = year_day.calculateMonthDay(); const day_seconds = epoch_seconds.getDaySeconds(); return std.fmt.allocPrint(allocator, "{d:0>4}-{d:0>2}-{d:0>2} {d:0>2}:{d:0>2} UTC", .{ year_day.year, month_day.month.numeric(), month_day.day_index + 1, day_seconds.getHoursIntoDay(), day_seconds.getMinutesIntoHour(), });}pub fn shortSha(sha: ?[]const u8) []const u8 { const actual = sha orelse return "unknown"; return actual[0..@min(actual.len, 10)];}test "format ns scales through units" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); try std.testing.expectEqualStrings("512 ns", try ns(allocator, 512)); try std.testing.expectEqualStrings("1.5 µs", try ns(allocator, 1_500)); try std.testing.expectEqualStrings("32.0 ms", try ns(allocator, 32_028_329)); try std.testing.expectEqualStrings("2.05 s", try ns(allocator, 2_045_000_690)); try std.testing.expectEqualStrings("1 m 21 s", try ns(allocator, 80_837_892_135));}test "format memory and counts" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); try std.testing.expectEqualStrings("640 KiB", try kib(allocator, 640)); try std.testing.expectEqualStrings("1.7 MiB", try kib(allocator, 1_762)); try std.testing.expectEqualStrings("1.68 GiB", try kib(allocator, 1_762_464)); try std.testing.expectEqualStrings("96 B", try bytes(allocator, 96)); try std.testing.expectEqualStrings("64 KiB", try bytes(allocator, 65_536)); try std.testing.expectEqualStrings("387", try count(allocator, 387)); try std.testing.expectEqualStrings("12.5 k", try count(allocator, 12_500));}test "format percent carries sign" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); try std.testing.expectEqualStrings("+12.3%", try percent(allocator, 12.34)); try std.testing.expectEqualStrings("-4.2%", try percent(allocator, -4.2));}test "format timestamp renders utc" { var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator); defer arena_state.deinit(); const allocator = arena_state.allocator(); try std.testing.expectEqualStrings("2026-07-04 13:06 UTC", try timestamp(allocator, 1783170388327580663)); try std.testing.expectEqualStrings("unknown", try timestamp(allocator, 0));}test "format short sha" { try std.testing.expectEqualStrings("abf0e4b279", shortSha("abf0e4b279ac79b61e1929655be71eee969e1aba")); try std.testing.expectEqualStrings("unknown", shortSha(null)); try std.testing.expectEqualStrings("abc", shortSha("abc"));}Source: src/profiling/report/root.zig:4
zig
pub const format = @import("format.zig");Complete caller list for report.format.ns
19 direct callers.
tiny.profiling.analyze.render.writeText[function] atsrc/profiling/analyze/render.zig:190tiny.profiling.report.format.seconds[function] atsrc/profiling/report/format.zig:44src.profiling.report.format.test_format_ns_scales_through_units[function] — test; no exact target atsrc/profiling/report/format.zig:69in nearest public ownertiny.profiling.report.formatsrc.profiling.report.page.benchmarkReductionRow[function] — private; no exact target atsrc/profiling/report/page.zig:1134in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.executionWallCell[function] — private; no exact target atsrc/profiling/report/page.zig:1390in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.indexRuns[function] — private; no exact target atsrc/profiling/report/page.zig:173in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.optionalNsCell[function] — private; no exact target atsrc/profiling/report/page.zig:2095in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.orderEffectsTable[function] — private; no exact target atsrc/profiling/report/page.zig:875in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.runAnalysis[function] — private; no exact target atsrc/profiling/report/page.zig:585in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.runMeta[function] — private; no exact target atsrc/profiling/report/page.zig:436in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.runWorkloads[function] — private; no exact target atsrc/profiling/report/page.zig:500in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.signedNs[function] — private; no exact target atsrc/profiling/report/page.zig:1374in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.trendCard[function] — private; no exact target atsrc/profiling/report/page.zig:143in nearest public ownertiny.profiling.report.pagetiny.profiling.report.page.workload[function] atsrc/profiling/report/page.zig:1006src.profiling.report.page.workloadCapturePerturbation[function] — private; no exact target atsrc/profiling/report/page.zig:1306in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.workloadExecutionArtifacts[function] — private; no exact target atsrc/profiling/report/page.zig:1907in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.workloadTiming[function] — private; no exact target atsrc/profiling/report/page.zig:1594in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.workloadWallMetadata[function] — private; no exact target atsrc/profiling/report/page.zig:1420in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.workloadWarmupMetadata[function] — private; no exact target atsrc/profiling/report/page.zig:1479in nearest public ownertiny.profiling.report.page
Complete caller list for report.format.percent
8 direct callers.
src.profiling.report.format.test_format_percent_carries_sign[function] — test; no exact target atsrc/profiling/report/format.zig:93in nearest public ownertiny.profiling.report.formatsrc.profiling.report.page.causalCurve[function] — private; no exact target atsrc/profiling/report/page.zig:1808in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.orderEffectsTable[function] — private; no exact target atsrc/profiling/report/page.zig:875in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.percentCell[function] — private; no exact target atsrc/profiling/report/page.zig:2105in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.rangePairCell[function] — private; no exact target atsrc/profiling/report/page.zig:854in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.runAnalysis[function] — private; no exact target atsrc/profiling/report/page.zig:585in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.trendCard[function] — private; no exact target atsrc/profiling/report/page.zig:143in nearest public ownertiny.profiling.report.pagesrc.profiling.report.page.workloadCausal[function] — private; no exact target atsrc/profiling/report/page.zig:1716in nearest public ownertiny.profiling.report.page
Audit
| Definitions | 10 |
|---|---|
| Public names | 10 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |