tiny.tracy.cli.args.timeline
Defined in cli.args.
API (1)
Actions
Public operations.
Source
Source: lib/tracy/src/cli/args/root.zig:20
zig
pub const timeline = @import("timeline.zig");Source: lib/tracy/src/cli/args/timeline.zig
zig
const std = @import("std");const tracy = @import("../../root.zig");const scalar = @import("scalar.zig");const types = @import("types.zig");pub fn parse(args: []const []const u8) !types.TimelineArgs { if (args.len == 0) return error.InvalidArguments; var parsed = types.TimelineArgs{ .path = args[0] }; var around_ns: ?u64 = null; var window_ns: ?u64 = null; var index: usize = 1; while (index < args.len) : (index += 1) { if (std.mem.eql(u8, args[index], "--format")) { index += 1; if (index >= args.len) return error.InvalidArguments; if (std.mem.eql(u8, args[index], "text")) { parsed.format = .text; } else if (std.mem.eql(u8, args[index], "jsonl")) { parsed.format = .jsonl; } else { return error.UnsupportedFormat; } } else if (std.mem.eql(u8, args[index], "--top")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.top = try scalar.parsePositiveUsize(args[index]); } else if (std.mem.eql(u8, args[index], "--kind")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.kind = tracy.timeline.Kind.fromName(args[index]) orelse return error.UnsupportedKind; } else if (std.mem.eql(u8, args[index], "--sort")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.sort = tracy.timeline.Sort.fromName(args[index]) orelse return error.UnsupportedSort; } else if (std.mem.eql(u8, args[index], "--thread")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.thread = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--since-ns")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.since_ns = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--until-ns")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.until_ns = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--around-ns")) { index += 1; if (index >= args.len) return error.InvalidArguments; around_ns = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--window-ns")) { index += 1; if (index >= args.len) return error.InvalidArguments; window_ns = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--min-duration-ns")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.min_duration_ns = try scalar.parseU64(args[index]); } else if (std.mem.eql(u8, args[index], "--match")) { index += 1; if (index >= args.len) return error.InvalidArguments; parsed.options.match = args[index]; } else { return error.UnknownArgument; } } if (around_ns) |center| { if (parsed.options.since_ns != null or parsed.options.until_ns != null) return error.InvalidArguments; const width = window_ns orelse 1_000_000; const half = width / 2; parsed.options.since_ns = if (center > half) center - half else 0; parsed.options.until_ns = center +| (width - half); } else if (window_ns != null) { return error.InvalidArguments; } if (parsed.options.since_ns != null and parsed.options.until_ns != null and parsed.options.since_ns.? > parsed.options.until_ns.?) { return error.InvalidArguments; } return parsed;}test "timeline args parse filters window and format" { const parsed = try parse(&.{ "events.jsonl", "--format", "jsonl", "--top", "12", "--kind", "zone", "--sort", "duration", "--thread", "7", "--around-ns", "1000", "--window-ns", "200", "--min-duration-ns", "50", "--match", "phase", }); try std.testing.expectEqualStrings("events.jsonl", parsed.path); try std.testing.expectEqual(types.Format.jsonl, parsed.format); try std.testing.expectEqual(@as(usize, 12), parsed.options.top); try std.testing.expectEqual(tracy.timeline.Kind.zone, parsed.options.kind); try std.testing.expectEqual(tracy.timeline.Sort.duration, parsed.options.sort); try std.testing.expectEqual(@as(?u64, 7), parsed.options.thread); try std.testing.expectEqual(@as(?u64, 900), parsed.options.since_ns); try std.testing.expectEqual(@as(?u64, 1100), parsed.options.until_ns); try std.testing.expectEqual(@as(u64, 50), parsed.options.min_duration_ns); try std.testing.expectEqualStrings("phase", parsed.options.match.?);}Audit
| Definitions | 2 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |