Add logging to io.cc on failed write and read.

This should provide insights into any failures.

PiperOrigin-RevId: 815784482
This commit is contained in:
Nitin Gangahar 2025-10-06 10:25:07 -07:00 committed by Copybara-Service
parent 684a0444e9
commit 9dc802c7aa
1 changed files with 14 additions and 2 deletions

View File

@ -106,7 +106,13 @@ class FilePosix : public File {
for (;;) { for (;;) {
// pread seems to be faster than lseek + read when parallelized. // pread seems to be faster than lseek + read when parallelized.
const auto bytes_read = pread(fd_, bytes + pos, size - pos, offset + pos); const auto bytes_read = pread(fd_, bytes + pos, size - pos, offset + pos);
if (bytes_read <= 0) break; if (bytes_read <= 0) {
HWY_WARN(
"Read failure at pos %zu within size %zu with offset %zu and "
"errno %d\n",
pos, size, offset, errno);
break;
}
pos += bytes_read; pos += bytes_read;
HWY_ASSERT(pos <= size); HWY_ASSERT(pos <= size);
if (pos == size) break; if (pos == size) break;
@ -120,7 +126,13 @@ class FilePosix : public File {
for (;;) { for (;;) {
const auto bytes_written = const auto bytes_written =
pwrite(fd_, bytes + pos, size - pos, offset + pos); pwrite(fd_, bytes + pos, size - pos, offset + pos);
if (bytes_written <= 0) break; if (bytes_written <= 0) {
HWY_WARN(
"Write failure at pos %zu within size %zu with offset %zu and "
"errno %d\n",
pos, size, offset, errno);
break;
}
pos += bytes_written; pos += bytes_written;
HWY_ASSERT(pos <= size); HWY_ASSERT(pos <= size);
if (pos == size) break; if (pos == size) break;