Skip to documentation
SLOP

tiny.smg.command.calls.text

Reference tiny.smg command calls text

Defined in command.calls.

API (1)

Actions

Public operations.

No direct callersNo direct callscommand.callstext
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallscommand.calls.commandruntest; no linktools.smg.src.command.calls.texttest: call architecture text distingu...private; no linktools.smg.src.command.calls.textwriteCycleprivate; no linktools.smg.src.command.calls.textwriteReachprivate; no linktools.smg.src.command.calls.textwriteResolutioncommand.calls.textwrite
Static calls · unresolved targets: 1 · external targets: 2.

Source: tools/smg/src/command/calls/root.zig:3

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

Source: tools/smg/src/command/calls/text.zig

zig
const std = @import("std");const smg = @import("../../root.zig");const calls = smg.calls;const graph_mod = smg.graph;const node_cli = smg.command.node;const sample_max: usize = 3;const territory_max: usize = 3;const cycle_member_max: usize = 8;pub fn write(    allocator: std.mem.Allocator,    writer: *std.Io.Writer,    graph: graph_mod.Graph,    report: calls.Report,    depth: u32,) !void {    const focus = graph.nodes.items[report.focus];    const territory = graph.nodes.items[report.focus_territory];    try writer.print("{s}  [{s}]\n", .{ focus.name, focus.type });    const location = try node_cli.location(allocator, focus);    if (location.len != 0) try writer.print("file: {s}\n", .{location});    try writer.print(        "territory: {s}  [{s}]\n\n",        .{ territory.name, territory.type },    );    try writer.writeAll("Static call relationships from the last scan\n");    try writer.print(        "Loaded graph: {d} nodes, {d} edges\n",        .{ report.graph_nodes, report.graph_edges },    );    try writer.writeAll(        "Complete traversal; strata use minimum call distance.\n",    );    try writer.writeAll(        "--depth controls display only; exact totals cover the loaded graph.\n",    );    try writer.writeAll(        "Deduplicated edges; locations are declarations, not call sites.\n",    );    try writer.writeAll("No runtime path, frequency, or traffic meaning.\n");    try writeReach(allocator, writer, graph, "Callers", report.callers, depth);    try writeReach(allocator, writer, graph, "Calls", report.calls, depth);    try writeCycle(allocator, writer, graph, report);    try writeResolution(writer, report.resolution);}fn writeReach(    allocator: std.mem.Allocator,    writer: *std.Io.Writer,    graph: graph_mod.Graph,    title: []const u8,    reach: calls.Reach,    depth: u32,) !void {    try writer.print(        "\n{s}  {d} total · {d} test-marked · {d} other · max depth {d}\n",        .{            title,            reach.total,            reach.test_marked,            reach.total - reach.test_marked,            reach.max_depth,        },    );    const shown_depth = @min(depth, reach.max_depth);    for (reach.strata[0..shown_depth]) |stratum| {        try writer.print(            "  depth {d}  {d} nodes · {d} test-marked · {d} other · " ++                "{d} territories\n",            .{                stratum.depth,                stratum.count,                stratum.test_marked,                stratum.count - stratum.test_marked,                stratum.territory_count,            },        );        try writeTerritories(writer, graph, reach, stratum);        try writeSamples(allocator, writer, graph, reach, stratum);    }    const beyond = reach.beyond(depth);    if (beyond != 0) {        try writer.print(            "  ... {d} node{s} beyond depth {d}\n",            .{ beyond, if (beyond == 1) "" else "s", depth },        );    }}fn writeTerritories(    writer: *std.Io.Writer,    graph: graph_mod.Graph,    reach: calls.Reach,    stratum: calls.Stratum,) !void {    const start: usize = @intCast(stratum.territory_start);    const count: usize = @intCast(stratum.territory_count);    const displayed = @min(count, territory_max);    try writer.writeAll("    territories: ");    for (reach.territories[start..][0..displayed], 0..) |item, index| {        if (index != 0) try writer.writeAll(", ");        try writer.print(            "{s} ({d})",            .{ graph.nodes.items[item.node].name, item.count },        );    }    if (displayed < count) {        try writer.print(", +{d} more", .{count - displayed});    }    try writer.writeByte('\n');}fn writeSamples(    allocator: std.mem.Allocator,    writer: *std.Io.Writer,    graph: graph_mod.Graph,    reach: calls.Reach,    stratum: calls.Stratum,) !void {    var displayed: usize = 0;    for (reach.entries) |entry| {        if (entry.depth != stratum.depth) continue;        if (displayed == sample_max) break;        const node = graph.nodes.items[entry.node];        const location = try node_cli.location(allocator, node);        try writer.print("    {s}", .{node.name});        if (entry.test_marked) try writer.writeAll(" [test]");        if (entry.cycle) try writer.writeAll(" [cycle]");        if (location.len != 0) try writer.print("  {s}", .{location});        try writer.writeByte('\n');        displayed += 1;    }    if (displayed < stratum.count) {        try writer.print(            "    ... {d} more at this depth\n",            .{stratum.count - displayed},        );    }}fn writeCycle(    allocator: std.mem.Allocator,    writer: *std.Io.Writer,    graph: graph_mod.Graph,    report: calls.Report,) !void {    try writer.writeAll("\nCycle participation\n");    try writer.print(        "  self-recursive: {s}\n",        .{if (report.cycle.recursive) "yes" else "no"},    );    try writer.print(        "  focus cycle: {d} other node{s}\n",        .{            report.cycle.members.len,            if (report.cycle.members.len == 1) "" else "s",        },    );    const displayed = @min(report.cycle.members.len, cycle_member_max);    for (report.cycle.members[0..displayed]) |node_index| {        const node = graph.nodes.items[node_index];        const location = try node_cli.location(allocator, node);        try writer.print("    {s}", .{node.name});        if (location.len != 0) try writer.print("  {s}", .{location});        try writer.writeByte('\n');    }    if (displayed < report.cycle.members.len) {        try writer.print(            "    ... {d} more cycle members\n",            .{report.cycle.members.len - displayed},        );    }}fn writeResolution(    writer: *std.Io.Writer,    resolution: calls.Resolution,) !void {    try writer.writeAll("\nCall target resolution evidence\n");    try writer.writeAll("  unresolved target names: ");    try writeOptionalCount(writer, resolution.unresolved_targets);    try writer.writeAll("  external target names: ");    try writeOptionalCount(writer, resolution.external_targets);}fn writeOptionalCount(writer: *std.Io.Writer, value: ?u32) !void {    if (value) |count| {        try writer.print("{d}\n", .{count});    } else {        try writer.writeAll("unknown (not recorded by this scan)\n");    }}test "call architecture text distinguishes exact totals from display depth" {    const fixture = @import("fixture.zig");    var arena = std.heap.ArenaAllocator.init(std.testing.allocator);    defer arena.deinit();    const allocator = arena.allocator();    const graph = try fixture.small(allocator);    const report = try calls.build(allocator, graph, "app.focus");    var out: std.Io.Writer.Allocating = .init(allocator);    try write(allocator, &out.writer, graph, report, 1);    try std.testing.expect(        std.mem.indexOf(u8, out.written(), "Callers  2 total") != null,    );    try std.testing.expect(        std.mem.indexOf(u8, out.written(), "... 1 node beyond depth 1") != null,    );    try std.testing.expect(        std.mem.indexOf(            u8,            out.written(),            "locations are declarations, not call sites",        ) != null,    );}

Audit

Definitions2
Public names3
Members0
Version26.7.0
Revisiondaab053ee433