1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-16 23:42:43 +01:00

Merge pull request #13767 from ethanavatar/master

libutil, libexpr: #10542 abstract over getrusage for getting cpuTime stat and implement windows version
This commit is contained in:
Jörg Thalheim 2025-09-06 09:26:13 +02:00 committed by GitHub
commit 1d62ccdb3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 69 additions and 15 deletions

View file

@ -0,0 +1,23 @@
#include "nix/util/current-process.hh"
#include "nix/util/error.hh"
#include <cmath>
#include <sys/resource.h>
namespace nix {
std::chrono::microseconds getCpuUserTime()
{
struct rusage buf;
if (getrusage(RUSAGE_SELF, &buf) != 0) {
throw SysError("failed to get CPU time");
}
std::chrono::seconds seconds(buf.ru_utime.tv_sec);
std::chrono::microseconds microseconds(buf.ru_utime.tv_usec);
return seconds + microseconds;
}
} // namespace nix

View file

@ -49,6 +49,7 @@ config_unix_priv_h = configure_file(
sources += config_unix_priv_h
sources += files(
'current-process.cc',
'environment-variables.cc',
'file-descriptor.cc',
'file-path.cc',