authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-08 21:14:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-08 21:14:30-07:00
log95907cb79578779108f3772cb93648d38354b9ec
treec01b3a7c4fdafba8d227dda8db78a51847c3c25e
parent5eb5d523b50e8e8912cf84bf021dc4c95e521a7a

restore progress reporting for package fetching


2 files changed, 18 insertions(+), 7 deletions(-)

src/Package/Fetch.zig+17-6
......@@ -539,16 +539,18 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
539539 // If the package does not have a build.zig.zon file then there are no dependencies.
540540 const manifest = f.manifest orelse return;
541541
542 const new_fetches = nf: {
542 const new_fetches, const prog_names = nf: {
543543 const parent_arena = f.arena.allocator();
544544 const gpa = f.arena.child_allocator;
545545 const cache_root = f.job_queue.global_cache;
546 const dep_names = manifest.dependencies.keys();
546547 const deps = manifest.dependencies.values();
547548 // Grab the new tasks into a temporary buffer so we can unlock that mutex
548549 // as fast as possible.
549550 // This overallocates any fetches that get skipped by the `continue` in the
550551 // loop below.
551552 const new_fetches = try parent_arena.alloc(Fetch, deps.len);
553 const prog_names = try parent_arena.alloc([]const u8, deps.len);
552554 var new_fetch_index: usize = 0;
553555
554556 f.job_queue.mutex.lock();
......@@ -568,7 +570,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
568570 // - Hash is added to the table based on the path alone before
569571 // calling run(); no need to add it again.
570572
571 for (deps) |dep| {
573 for (dep_names, deps) |dep_name, dep| {
572574 const new_fetch = &new_fetches[new_fetch_index];
573575 const location: Location = switch (dep.location) {
574576 .url => |url| .{ .remote = .{
......@@ -594,6 +596,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
594596 break :l .{ .relative_path = new_root };
595597 },
596598 };
599 prog_names[new_fetch_index] = dep_name;
597600 new_fetch_index += 1;
598601 f.job_queue.all_fetches.appendAssumeCapacity(new_fetch);
599602 new_fetch.* = .{
......@@ -620,15 +623,18 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
620623 };
621624 }
622625
623 break :nf new_fetches[0..new_fetch_index];
626 // job_queue mutex is locked so this is OK.
627 f.prog_node.unprotected_estimated_total_items += new_fetch_index;
628
629 break :nf .{ new_fetches[0..new_fetch_index], prog_names[0..new_fetch_index] };
624630 };
625631
626632 // Now it's time to give tasks to the thread pool.
627633 const thread_pool = f.job_queue.thread_pool;
628634
629 for (new_fetches) |*new_fetch| {
635 for (new_fetches, prog_names) |*new_fetch, prog_name| {
630636 f.job_queue.wait_group.start();
631 thread_pool.spawn(workerRun, .{new_fetch}) catch |err| switch (err) {
637 thread_pool.spawn(workerRun, .{ new_fetch, prog_name }) catch |err| switch (err) {
632638 error.OutOfMemory => {
633639 new_fetch.oom_flag = true;
634640 f.job_queue.wait_group.finish();
......@@ -654,8 +660,13 @@ pub fn relativePathDigest(
654660 return Manifest.hexDigest(hasher.finalResult());
655661}
656662
657pub fn workerRun(f: *Fetch) void {
663pub fn workerRun(f: *Fetch, prog_name: []const u8) void {
658664 defer f.job_queue.wait_group.finish();
665
666 var prog_node = f.prog_node.start(prog_name, 0);
667 defer prog_node.end();
668 prog_node.activate();
669
659670 run(f) catch |err| switch (err) {
660671 error.OutOfMemory => f.oom_flag = true,
661672 error.FetchFailed => {
src/main.zig+1-1
......@@ -4886,7 +4886,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
48864886 );
48874887
48884888 job_queue.wait_group.start();
4889 try job_queue.thread_pool.spawn(Package.Fetch.workerRun, .{&fetch});
4889 try job_queue.thread_pool.spawn(Package.Fetch.workerRun, .{ &fetch, "root" });
48904890 job_queue.wait_group.wait();
48914891
48924892 try job_queue.consolidateErrors();