Add --record-mem-peak and --mem-poll-frequency
What
This MR makes Tezt capable of measuring peak memory usage and to store it in --records.
A side-effect is that Tezt can no longer be compiled with OCaml < 4.13.
Why
This is especially useful to investigate out of memory issues in CI and to calibrate CI runners.
The reason Tezt can no longer be compiled with OCaml 4.12 is that String.starts_with is not available. We could have rewrote this function but we don't really plan to actively support this older version.
How
Tezt measures memory usage by reading /proc. Using the (opt-in) memory measurement feature thus only works on OSes which provide the relevant files in /proc.
Measurements are done by the scheduler process. It measures the memory usage of each worker process as they run tests. Measurement is done recursively in case workers spawn child processes. Measurement uses proportional set size (PSS) so that shared memory is only counted once in total.
Manually testing the MR
$ dune exec test/unix/main.exe -- --record-mem-peak --record record.json -j 2
$ grep peak_memory_usage record.json
With the default value for --mem-poll-frequency, this won't give many results: when tests are too fast, Tezt does not have time to measure memory usage. You can try with a higher poll frequency to see more results:
$ dune exec test/unix/main.exe -- --record-mem-peak --record record.json -j 2 --mem-poll-frequency 10000
$ grep peak_memory_usage record.json
Checklist
-
Update CHANGES.md. No need to document changes to documentation and tests. -
Make sure all new values, types etc. are documented in .mlifiles and that the generated documentation looks ok. -
Add tests in test/, if relevant.