RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Profile buffered copy progress overhead
Melc5c897ef9edb
diff --git a/src/files/copy_bench.zig b/src/files/copy_bench.zigindex 52649c2..2ed966d 100644--- a/src/files/copy_bench.zig+++ b/src/files/copy_bench.zig@@ -371,7 +371,7 @@ fn emitRow(@as(f64, @floatFromInt(median_ns));std.debug.print(- "BENCH,A,job_copy_e2e_{s},{s},warm_source_cache,{d},{d},{d},{d},{d},{d},{d},{d},{d:.2},{d:.2},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d}\n",+ "BENCH,A,job_copy_e2e_{s},{s},warm_source_cache,{d},{d},{d},{d},{d},{d},{d},{d},{d:.2},{d:.2},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d},{d}\n",.{strategy.name(),profile.name,@@ -403,8 +403,20 @@ fn emitRow(profile_totals.directory_create_calls,profile_totals.path_allocations,profile_totals.path_allocation_bytes,+ },+ );+ std.debug.print(+ "{d},{d},{d},{d},{d},{d},{d},{d},{d}\n",+ .{profile_totals.manifest_lookup_comparisons,profile_totals.mutex_lock_calls,+ profile_totals.buffered_read_ns,+ profile_totals.buffered_write_ns,+ profile_totals.progress_publish_ns,+ profile_totals.buffered_read_calls,+ profile_totals.buffered_write_calls,+ profile_totals.progress_publish_calls,+ profile_totals.progress_publish_bytes,},);}@@ -414,6 +426,13 @@ fn addProfileTotals(total: *ops.CopyProfile, sample: ops.CopyProfile) void {total.destination_resolution_ns +|= sample.destination_resolution_ns;total.recursive_copy_ns +|= sample.recursive_copy_ns;total.data_transfer_ns +|= sample.data_transfer_ns;+ total.buffered_read_ns +|= sample.buffered_read_ns;+ total.buffered_write_ns +|= sample.buffered_write_ns;+ total.progress_publish_ns +|= sample.progress_publish_ns;+ total.buffered_read_calls +|= sample.buffered_read_calls;+ total.buffered_write_calls +|= sample.buffered_write_calls;+ total.progress_publish_calls +|= sample.progress_publish_calls;+ total.progress_publish_bytes +|= sample.progress_publish_bytes;total.lstat_calls +|= sample.lstat_calls;total.fstat_calls +|= sample.fstat_calls;total.opendir_calls +|= sample.opendir_calls;@@ -521,7 +540,7 @@ pub fn run(allocator: Allocator) !void {defer ops.deleteRecursive(allocator, benchmark_root) catch {};std.debug.print(- "BENCH,phase,operation,profile,cache_mode,files,directories,total_bytes,buffer_bytes,iterations,median_ns,min_ns,max_ns,median_mib_per_second,median_files_per_second,reflink_calls,reflink_bytes,reflink_fallback_files,copy_file_range_calls,copy_file_range_bytes,buffered_fallback_files,manifest_scan_ns,destination_resolution_ns,recursive_copy_ns,data_transfer_ns,lstat_calls,fstat_calls,opendir_calls,directory_entries,file_open_calls,directory_create_calls,path_allocations,path_allocation_bytes,manifest_lookup_comparisons,mutex_lock_calls\n",+ "BENCH,phase,operation,profile,cache_mode,files,directories,total_bytes,buffer_bytes,iterations,median_ns,min_ns,max_ns,median_mib_per_second,median_files_per_second,reflink_calls,reflink_bytes,reflink_fallback_files,copy_file_range_calls,copy_file_range_bytes,buffered_fallback_files,manifest_scan_ns,destination_resolution_ns,recursive_copy_ns,data_transfer_ns,lstat_calls,fstat_calls,opendir_calls,directory_entries,file_open_calls,directory_create_calls,path_allocations,path_allocation_bytes,manifest_lookup_comparisons,mutex_lock_calls,buffered_read_ns,buffered_write_ns,progress_publish_ns,buffered_read_calls,buffered_write_calls,progress_publish_calls,progress_publish_bytes\n",.{},);diff --git a/src/files/ops.zig b/src/files/ops.zigindex 0df15b7..50f63cf 100644--- a/src/files/ops.zig+++ b/src/files/ops.zig@@ -70,6 +70,13 @@ pub const CopyProfile = struct {destination_resolution_ns: u64 = 0,recursive_copy_ns: u64 = 0,data_transfer_ns: u64 = 0,+ buffered_read_ns: u64 = 0,+ buffered_write_ns: u64 = 0,+ progress_publish_ns: u64 = 0,+ buffered_read_calls: u64 = 0,+ buffered_write_calls: u64 = 0,+ progress_publish_calls: u64 = 0,+ progress_publish_bytes: u64 = 0,lstat_calls: u64 = 0,fstat_calls: u64 = 0,opendir_calls: u64 = 0,@@ -849,7 +856,15 @@ fn copyFileContentsTracked(_ = c.unlink(dst_z);return error.Cancelled;}+ const read_started = if (runner) |job| job.profileStart() else 0;const n = c.read(src_fd, buf.ptr, buf.len);+ if (runner) |job| {+ job.profileCount(&job.profile_metrics.buffered_read_calls, 1);+ job.profileAddDuration(+ read_started,+ &job.profile_metrics.buffered_read_ns,+ );+ }if (n == 0) break;if (n < 0 and std.posix.errno(n) == .INTR) continue;if (n < 0) {@@ -860,7 +875,15 @@ fn copyFileContentsTracked(var chunk_written: u64 = 0;const total = @as(usize, @intCast(n));while (written < total) {+ const write_started = if (runner) |job| job.profileStart() else 0;const wn = c.write(dst_fd, buf[written..].ptr, total - written);+ if (runner) |job| {+ job.profileCount(&job.profile_metrics.buffered_write_calls, 1);+ job.profileAddDuration(+ write_started,+ &job.profile_metrics.buffered_write_ns,+ );+ }if (wn < 0 and std.posix.errno(wn) == .INTR) continue;if (wn <= 0) {if (runner) |job| job.addFileTransferredBytes(chunk_written);@@ -1508,6 +1531,15 @@ pub const JobRunner = struct {fn addTransferredBytesImpl(self: *JobRunner, bytes: u64, file_progress: bool) void {if (bytes == 0) return;+ const publish_started = if (file_progress) self.profileStart() else 0;+ defer if (file_progress) self.profileAddDuration(+ publish_started,+ &self.profile_metrics.progress_publish_ns,+ );+ if (file_progress) {+ self.profileCount(&self.profile_metrics.progress_publish_calls, 1);+ self.profileCount(&self.profile_metrics.progress_publish_bytes, bytes);+ }self.profileCount(&self.profile_metrics.mutex_lock_calls, 1);_ = c.pthread_mutex_lock(&self.mutex);if (bytes > std.math.maxInt(u64) - self.transferred_bytes) {