summaryrefslogtreecommitdiff
path: root/src/benchmark/CApi.zig
blob: 3bef8b2698d3618dffbd61aa6426e1e6a5d70cb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const std = @import("std");
const cli = @import("cli.zig");
const state = &@import("../global.zig").state;

const log = std.log.scoped(.benchmark);

/// Run the Ghostty benchmark CLI with the given action and arguments.
export fn ghostty_benchmark_cli(
    action_name_: [*:0]const u8,
    args: [*:0]const u8,
) bool {
    const action_name = std.mem.sliceTo(action_name_, 0);
    const action: cli.Action = std.meta.stringToEnum(
        cli.Action,
        action_name,
    ) orelse {
        log.warn("unknown action={s}", .{action_name});
        return false;
    };

    cli.mainAction(
        state.alloc,
        action,
        .{ .string = std.mem.sliceTo(args, 0) },
    ) catch |err| {
        log.warn("failed to run action={s} err={}", .{
            @tagName(action),
            err,
        });
        return false;
    };

    return true;
}