localexec: reap the spawn helper so local CPU time is accounted

Since the out-of-process spawn helper landed, non-console actions run as
children of the helper instead of siso. The helper reaps each action, so
all of their CPU time accumulates in the helper's rusage cutime. Nothing
ever waited on the helper, so on siso exit it was orphaned to init and
its cutime was discarded. getrusage(RUSAGE_CHILDREN) up the tree
therefore never saw the local build's CPU: A local offline build of base
shows 49% CPU (16.7 core-s) before and 2998% CPU (991 core-s) after,
with identical wall time and step count.

To fix this, close the control socket on Siso shutdown so the helper
drains and exits, then wait for it to roll the helper's accumulated
child rusage up into siso.

Tested:
- No-op on non-unix, where there is no helper.
- Wall time is unchanged, so the extra wait adds no latency.
- Single Ctrl-C interrupt cancels the build context and the function
  returns normally, so StopHelper runs and the cancelled build's CPU is
  still accounted (verified: a build stopped after 4s reports 97s user
  CPU). A second Ctrl-C still hard-exits via os.Exit without waiting, on
  purpose; the helper drains its own children on socket EOF, so nothing
  is orphaned.
- Added a regression test that runs a CPU-burning action through the
  helper and asserts its CPU shows up in the process's RUSAGE_CHILDREN
  after StopHelper. Without the wait the delta is zero.

Bug: 531402317
Change-Id: I65bdcdacfb07bfb17da9e1304f10c1d48f05a483
Reviewed-on: https://chromium-review.googlesource.com/c/build/+/8045440
Auto-Submit: Philipp Wollermann <philwo@google.com>
Reviewed-by: Fumitoshi Ukai <ukai@google.com>
Commit-Queue: Philipp Wollermann <philwo@google.com>
4 files changed
tree: 26b84a8bbcc80e420c5c0befd2c52b509961a90b
  1. bench/
  2. gong/
  3. hashigo/
  4. infra/
  5. kajiya/
  6. kzipinfo/
  7. remote-apis/
  8. runmc/
  9. siso/
  10. .gitignore
  11. .golangci.yml
  12. .style.yapf
  13. BUILD_OWNERS
  14. BUILD_TEAM_OWNERS
  15. CONTRIBUTING.md
  16. LICENSE
  17. OWNERS
  18. PRESUBMIT.py
  19. README.md
  20. WATCHLISTS
README.md

build.git repository

This repository contains tools developed and owned by the Chrome Build Team.

Quick start

The steps for getting the code are:

  1. Install depot_tools
  2. Run git clone https://chromium.googlesource.com/build

We use the standard Go module workflow to work on our projects.

Links