Link process tools with the lite proto runtime to cut their size to tenth. RELNOTES: None. PiperOrigin-RevId: 245412749
diff --git a/src/main/protobuf/execution_statistics.proto b/src/main/protobuf/execution_statistics.proto index 86bfe35..ed761890 100644 --- a/src/main/protobuf/execution_statistics.proto +++ b/src/main/protobuf/execution_statistics.proto
@@ -18,6 +18,7 @@ option java_package = "com.google.devtools.build.lib.shell"; option java_outer_classname = "Protos"; +option optimize_for = LITE_RUNTIME; // Verbatim representation of the rusage structure returned by getrusage(2). // For further details on all these cryptic names, see that manual page.
diff --git a/src/main/tools/process-tools.cc b/src/main/tools/process-tools.cc index 45aa6b7..0b5ecb94 100644 --- a/src/main/tools/process-tools.cc +++ b/src/main/tools/process-tools.cc
@@ -242,9 +242,24 @@ std::unique_ptr<tools::protos::ExecutionStatistics> execution_statistics = CreateExecutionStatisticsProto(rusage); + std::string serialized = execution_statistics->SerializeAsString(); - if (!execution_statistics->SerializeToFileDescriptor(fd_out)) { - DIE("could not write resource usage to file: %s", stats_path.c_str()); + if (serialized.empty()) { + DIE("invalid execution statistics message"); + } + + const char *remaining = serialized.c_str(); + ssize_t remaining_size = serialized.size(); + + while (remaining_size > 0) { + ssize_t written = write(fd_out, remaining, remaining_size); + if (written < 0 && errno != EINTR && errno != EAGAIN) { + DIE("could not write resource usage to file '%s': %s", + stats_path.c_str(), strerror(errno)); + } + + remaining_size -= written; + remaining += written; } close(fd_out);