Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
run: sed -n 's/.*url *= *"\(.*\)".*/\1/p' build.zig.zon | xargs -t -n1 zig fetch

- name: "Prefetch ZLS dependencies (workaround)"
run: curl -L https://raw.githubusercontent.com/zigtools/zls/7b9d079c65e2400612bd126ee64ffda5dbb7e1f6/build.zig.zon | sed -n 's/.*url *= *"\(.*\)".*/\1/p' | xargs -t -n1 zig fetch
run: curl -L https://raw.githubusercontent.com/zigtools/zls/0ced338490bf50ef3e51736d7357767fa9988c9d/build.zig.zon | sed -n 's/.*url *= *"\(.*\)".*/\1/p' | xargs -t -n1 zig fetch

- name: "Run unit tests with coverage"
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#####
.zig-cache/
zig-out/
zig-pkg/

# MacOS
#######
Expand Down
15 changes: 7 additions & 8 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -995,22 +995,21 @@ const ZlinterRun = struct {
std.debug.print("zlinter command:\n\t{s}\n", .{
std.Build.Step.allocPrintCmd(
arena,
null,
.inherit,
null,
argv_list.items,
) catch @panic("OOM"),
});
}

var timer = try std.time.Timer.start();
const start_time = std.Io.Clock.awake.now(io);

_ = std.debug.lockStderr(&.{});
defer std.debug.unlockStderr();

var child = std.process.spawn(io, .{
.argv = argv_list.items,
.cwd = b.build_root.path,
.cwd_dir = b.build_root.handle,
.cwd = .{ .dir = b.build_root.handle },
.environ_map = &environ_map,
// As we're using stdout and stderr inherit we don't want to update
// parent of childs progress (i.e commented out as deliberately not set)
Expand Down Expand Up @@ -1040,7 +1039,7 @@ const ZlinterRun = struct {

const term = try child.wait(io);

step.result_duration_ns = timer.read();
step.result_duration_ns = @intCast(start_time.untilNow(io, .awake).toNanoseconds());
step.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
step.test_results = .{};

Expand All @@ -1058,7 +1057,7 @@ const ZlinterRun = struct {
return step.fail("zlinter command crashed:\n\t{s}", .{
std.Build.Step.allocPrintCmd(
arena,
null,
.inherit,
null,
argv_list.items,
) catch @panic("OOM"),
Expand All @@ -1069,7 +1068,7 @@ const ZlinterRun = struct {
return step.fail("zlinter was terminated unexpectedly:\n\t{s}", .{
std.Build.Step.allocPrintCmd(
arena,
null,
.inherit,
null,
argv_list.items,
) catch @panic("OOM"),
Expand Down Expand Up @@ -1102,7 +1101,7 @@ fn readHtmlTemplate(b: *std.Build, path: std.Build.LazyPath) ![]const u8 {
// Ignore.
}

const timestamp = try std.Io.Clock.real.now(b.graph.io);
const timestamp = std.Io.Clock.real.now(b.graph.io);
const build_timestamp = b.fmt("{d}", .{@divTrunc(timestamp.nanoseconds, std.time.ns_per_ms)});
const zig_version = zig_version_string;

Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
.zls = .{
// Update with `zig fetch --save git+https://github.com/zigtools/zls#master`
// IF changed THEN update .github/coverage.yml
.url = "git+https://github.com/zigtools/zls?ref=master#be4ddd69067e1fd62644d9a999b17adffd8766c2",
.hash = "zls-0.16.0-dev-rmm5flNfJQA26cb4HX9zW4379iE2lPGPDZD0qdh_VXMA",
.url = "git+https://github.com/zigtools/zls?ref=master#0ced338490bf50ef3e51736d7357767fa9988c9d",
.hash = "zls-0.16.0-dev-rmm5fklfJQD1jd1zHEqgN3dhCV2VWnaJYbw-0uxyXaMP",
},
},
.paths = .{
Expand Down
65 changes: 33 additions & 32 deletions src/exe/run_linter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ fn run(
args: zlinter.Args,
printer: *zlinter.rendering.Printer,
) !RunResult {
var timer = Timer.createStarted();
var total_timer = Timer.createStarted();
var timer = Timer.createStarted(io);
var total_timer = Timer.createStarted(io);

// Key is index to `lint_files` and value are errors for the file.
var file_lint_problems = std.AutoArrayHashMap(
Expand Down Expand Up @@ -184,7 +184,7 @@ fn run(
file.excluded = !index.contains(file.pathname);
}

if (timer.lapMilliseconds()) |ms| printer.println(.verbose, "Resolving {d} files took: {d}ms", .{ lint_files.len, ms });
printer.println(.verbose, "Resolving {d} files took: {d}ms", .{ lint_files.len, timer.lapMilliseconds() });

try runLinterRules(
io,
Expand All @@ -199,7 +199,7 @@ fn run(

printer.printBanner(.verbose);
printer.println(.verbose, "Linted {d} files", .{lint_files.len});
if (total_timer.lapMilliseconds()) |ms| printer.println(.verbose, "Took {d}ms", .{ms});
printer.println(.verbose, "Took {d}ms", .{total_timer.lapMilliseconds()});
printer.printBanner(.verbose);

// ------------------------------------------------------------------------
Expand Down Expand Up @@ -335,16 +335,15 @@ fn runLinterRules(
}
printer.println(.verbose, "[{d}/{d}] Linting: {s}", .{ i + 1, lint_files.len, lint_file.pathname });

var rule_timer = Timer.createStarted();
var rule_timer = Timer.createStarted(io);
defer {
if (rule_timer.lapNanoseconds()) |ns| {
printer.println(.verbose, " - Total elapsed {d}ms", .{ns / std.time.ns_per_ms});
if (maybe_slowest_files) |*slowest_files| {
slowest_files.add(.{
.name = lint_file.pathname,
.elapsed_ns = ns,
});
}
const ns = rule_timer.lapNanoseconds();
printer.println(.verbose, " - Total elapsed {d}ms", .{ns / std.time.ns_per_ms});
if (maybe_slowest_files) |*slowest_files| {
slowest_files.add(.{
.name = lint_file.pathname,
.elapsed_ns = ns,
});
}
}

Expand All @@ -359,10 +358,7 @@ fn runLinterRules(
};
defer doc.deinit(context.gpa);

if (timer.lapMilliseconds()) |ms|
printer.println(.verbose, " - Load document: {d}ms", .{ms})
else
printer.println(.verbose, " - Load document", .{});
printer.println(.verbose, " - Load document: {d}ms", .{timer.lapMilliseconds()});
printer.println(.verbose, " - {d} bytes", .{doc.handle.tree.source.len});
printer.println(.verbose, " - {d} nodes", .{doc.handle.tree.nodes.len});
printer.println(.verbose, " - {d} tokens", .{doc.handle.tree.tokens.len});
Expand Down Expand Up @@ -395,7 +391,7 @@ fn runLinterRules(
},
);
}
if (timer.lapMilliseconds()) |ms| printer.println(.verbose, " - Process syntax errors: {d}ms", .{ms});
printer.println(.verbose, " - Process syntax errors: {d}ms", .{timer.lapMilliseconds()});

printer.println(.verbose, " - Rules", .{});

Expand All @@ -415,12 +411,11 @@ fn runLinterRules(
try results.append(gpa, result);
}

if (timer.lapNanoseconds()) |ns| {
if (maybe_rule_elapsed_times) |*rule_elapsed_time| {
rule_elapsed_time[rule_index] += ns;
}
printer.println(.verbose, " - {s}: {d}ms", .{ rule.rule_id, ns / std.time.ns_per_ms });
} else printer.println(.verbose, " - {s}", .{rule.rule_id});
const ns = timer.lapNanoseconds();
if (maybe_rule_elapsed_times) |*rule_elapsed_time| {
rule_elapsed_time[rule_index] += ns;
}
printer.println(.verbose, " - {s}: {d}ms", .{ rule.rule_id, ns / std.time.ns_per_ms });
}

if (results.items.len > 0) {
Expand Down Expand Up @@ -753,20 +748,26 @@ const RunResult = struct {
const usage_error: RunResult = .{ .exit_code = .usage_error };
};

/// Simple more forgiving timer for optionally timing laps in verbose mode.
const Timer = struct {
backing: ?std.time.Timer = null,
last_timestamp: std.Io.Timestamp,
io: std.Io,

pub fn createStarted() Timer {
return .{ .backing = std.time.Timer.start() catch null };
pub fn createStarted(io: std.Io) Timer {
return .{
.last_timestamp = std.Io.Clock.now(.awake, io),
.io = io,
};
}

pub fn lapNanoseconds(self: *Timer) ?usize {
return (self.backing orelse return null).lap();
pub fn lapNanoseconds(self: *Timer) usize {
const current = std.Io.Clock.now(.awake, self.io);
const elapsed = self.last_timestamp.durationTo(current).toNanoseconds();
self.last_timestamp = current;
return @intCast(elapsed);
}

pub fn lapMilliseconds(self: *Timer) ?usize {
return (self.lapNanoseconds() orelse return null) / std.time.ns_per_ms;
pub fn lapMilliseconds(self: *Timer) usize {
return self.lapNanoseconds() / std.time.ns_per_ms;
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/session.zig
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub const LintContext = struct {
.allocator = gpa,
.io = io,
},
.intern_pool = try .init(gpa),
.intern_pool = try .init(io, gpa),
.document_store = undefined, // zlinter-disable-current-line no_undefined - set below
.analyser = undefined, // zlinter-disable-current-line no_undefined - set below
.io = io,
Expand Down
Loading