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 {...@@ -539,16 +539,18 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
539 // If the package does not have a build.zig.zon file then there are no dependencies.539 // If the package does not have a build.zig.zon file then there are no dependencies.
540 const manifest = f.manifest orelse return;540 const manifest = f.manifest orelse return;
541541
542 const new_fetches = nf: {542 const new_fetches, const prog_names = nf: {
543 const parent_arena = f.arena.allocator();543 const parent_arena = f.arena.allocator();
544 const gpa = f.arena.child_allocator;544 const gpa = f.arena.child_allocator;
545 const cache_root = f.job_queue.global_cache;545 const cache_root = f.job_queue.global_cache;
546 const dep_names = manifest.dependencies.keys();
546 const deps = manifest.dependencies.values();547 const deps = manifest.dependencies.values();
547 // Grab the new tasks into a temporary buffer so we can unlock that mutex548 // Grab the new tasks into a temporary buffer so we can unlock that mutex
548 // as fast as possible.549 // as fast as possible.
549 // This overallocates any fetches that get skipped by the `continue` in the550 // This overallocates any fetches that get skipped by the `continue` in the
550 // loop below.551 // loop below.
551 const new_fetches = try parent_arena.alloc(Fetch, deps.len);552 const new_fetches = try parent_arena.alloc(Fetch, deps.len);
553 const prog_names = try parent_arena.alloc([]const u8, deps.len);
552 var new_fetch_index: usize = 0;554 var new_fetch_index: usize = 0;
553555
554 f.job_queue.mutex.lock();556 f.job_queue.mutex.lock();
...@@ -568,7 +570,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {...@@ -568,7 +570,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
568 // - Hash is added to the table based on the path alone before570 // - Hash is added to the table based on the path alone before
569 // calling run(); no need to add it again.571 // calling run(); no need to add it again.
570572
571 for (deps) |dep| {573 for (dep_names, deps) |dep_name, dep| {
572 const new_fetch = &new_fetches[new_fetch_index];574 const new_fetch = &new_fetches[new_fetch_index];
573 const location: Location = switch (dep.location) {575 const location: Location = switch (dep.location) {
574 .url => |url| .{ .remote = .{576 .url => |url| .{ .remote = .{
...@@ -594,6 +596,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {...@@ -594,6 +596,7 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
594 break :l .{ .relative_path = new_root };596 break :l .{ .relative_path = new_root };
595 },597 },
596 };598 };
599 prog_names[new_fetch_index] = dep_name;
597 new_fetch_index += 1;600 new_fetch_index += 1;
598 f.job_queue.all_fetches.appendAssumeCapacity(new_fetch);601 f.job_queue.all_fetches.appendAssumeCapacity(new_fetch);
599 new_fetch.* = .{602 new_fetch.* = .{
...@@ -620,15 +623,18 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {...@@ -620,15 +623,18 @@ fn queueJobsForDeps(f: *Fetch) RunError!void {
620 };623 };
621 }624 }
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] };
624 };630 };
625631
626 // Now it's time to give tasks to the thread pool.632 // Now it's time to give tasks to the thread pool.
627 const thread_pool = f.job_queue.thread_pool;633 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| {
630 f.job_queue.wait_group.start();636 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) {
632 error.OutOfMemory => {638 error.OutOfMemory => {
633 new_fetch.oom_flag = true;639 new_fetch.oom_flag = true;
634 f.job_queue.wait_group.finish();640 f.job_queue.wait_group.finish();
...@@ -654,8 +660,13 @@ pub fn relativePathDigest(...@@ -654,8 +660,13 @@ pub fn relativePathDigest(
654 return Manifest.hexDigest(hasher.finalResult());660 return Manifest.hexDigest(hasher.finalResult());
655}661}
656662
657pub fn workerRun(f: *Fetch) void {663pub fn workerRun(f: *Fetch, prog_name: []const u8) void {
658 defer f.job_queue.wait_group.finish();664 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
659 run(f) catch |err| switch (err) {670 run(f) catch |err| switch (err) {
660 error.OutOfMemory => f.oom_flag = true,671 error.OutOfMemory => f.oom_flag = true,
661 error.FetchFailed => {672 error.FetchFailed => {
src/main.zig+1-1
...@@ -4886,7 +4886,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi...@@ -4886,7 +4886,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
4886 );4886 );
48874887
4888 job_queue.wait_group.start();4888 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" });
4890 job_queue.wait_group.wait();4890 job_queue.wait_group.wait();
48914891
4892 try job_queue.consolidateErrors();4892 try job_queue.consolidateErrors();