Skip to content

Fix ReportsDaemon `cpu_s`: measure thread time

Aleksei Lipniagov requested to merge 362900-fix-measure-thread-cpu-time into master

What does this MR do and why?

We used Benchmark.measure to measure cpu_s here: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/memory/reports_daemon.rb.
It is not correct.
As pointed by @mkaeppler:

Benchmark.measure calls out to https://man7.org/linux/man-pages/man2/getrusage.2.html with RUSAGE_SELF, which:

       RUSAGE_SELF
              Return resource usage statistics for the calling process,
              which is the sum of resources used by all threads in the
              process.

We should use, for example, Process::CLOCK_THREAD_CPUTIME_ID instead.

You could find more in the thread: #367845 (comment 1042087332)

How to set up and validate locally

Similar to !91283 (merged)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #362900 (closed)

Edited by Aleksei Lipniagov

Merge request reports