001 profile metatype

○ Planned This feature is planned but not yet implemented.

Feature: Profile meta-type not implemented

Code

// Test profile meta-type - performance profiling with timing
// Shows profiling metadata capture with runtime timestamps
const std = @import("std");
~import "$std/taps"

~event hello {}
| done {}

~event goodbye {}
| done {}

~[comptime|runtime] event profiler { source: []const u8, branch: []const u8, destination: ?[]const u8, timestamp_ns: i128 }
| done {}

~proc hello {
    std.debug.print("Hello executed\n", .{});
    return .{ .done = .{} };
}

~proc goodbye {
    std.debug.print("Goodbye executed\n", .{});
    return .{ .done = .{} };
}

~proc profiler {
    if (destination) |dest| {
        std.debug.print("Profile: {s}.{s} -> {s} @ {}\n", .{source, branch, dest, timestamp_ns});
    } else {
        std.debug.print("Profile: {s}.{s} -> terminal @ {}\n", .{source, branch, timestamp_ns});
    }
    return .{ .done = .{} };
}

// Universal tap using profile meta-type
// Captures source event, branch, destination, and runtime timestamp
// NOTE: Profile uses string-based fields (no enum conversion needed)
~tap(* -> *)
| Profile p |> profiler(source: p.source, branch: p.branch, destination: p.destination, timestamp_ns: p.timestamp_ns)
    | done |> _

~hello()
| done |> goodbye()
    | done |> _
input.kz

Test Configuration

MUST_RUN

Post-validation Script:

#!/bin/bash
# Post-validation for Profile metatype runtime test
# Validates that runtime timestamps are captured and output is correct

# Check that actual.txt exists
if [ ! -f actual.txt ]; then
    echo "ERROR: actual.txt not found"
    exit 1
fi

# Expected output pattern (timestamps will vary):
# Hello executed
# Profile: input:hello.done -> input:goodbye @ <non-zero timestamp>
# Goodbye executed
# Profile: input:goodbye.done -> terminal @ <non-zero timestamp>

# Check for event execution messages
if ! grep -q "Hello executed" actual.txt; then
    echo "ERROR: Missing 'Hello executed' message"
    exit 1
fi

if ! grep -q "Goodbye executed" actual.txt; then
    echo "ERROR: Missing 'Goodbye executed' message"
    exit 1
fi

# Check for Profile messages with correct transitions (with module qualifiers)
if ! grep -q "Profile: input:hello\.done -> input:goodbye @" actual.txt; then
    echo "ERROR: Missing 'Profile: input:hello.done -> input:goodbye' transition"
    exit 1
fi

if ! grep -q "Profile: input:goodbye\.done -> terminal @" actual.txt; then
    echo "ERROR: Missing 'Profile: input:goodbye.done -> terminal' transition"
    exit 1
fi

# Extract timestamps and verify they're non-zero (proving runtime capture)
TIMESTAMP1=$(grep "Profile: input:hello\.done -> input:goodbye @" actual.txt | sed 's/.*@ //')
TIMESTAMP2=$(grep "Profile: input:goodbye\.done -> terminal @" actual.txt | sed 's/.*@ //')

if [ -z "$TIMESTAMP1" ] || [ "$TIMESTAMP1" = "0" ]; then
    echo "ERROR: First timestamp is zero or missing (expected runtime capture)"
    exit 1
fi

if [ -z "$TIMESTAMP2" ] || [ "$TIMESTAMP2" = "0" ]; then
    echo "ERROR: Second timestamp is zero or missing (expected runtime capture)"
    exit 1
fi

# Success! Runtime profiling is working correctly
echo "✓ All Profile messages present"
echo "✓ Transitions correct (input:hello→input:goodbye→terminal)"
echo "✓ Runtime timestamps captured (non-zero values)"
exit 0