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:
commit
1d62ccdb3d
6 changed files with 69 additions and 15 deletions
23
src/libutil/unix/current-process.cc
Normal file
23
src/libutil/unix/current-process.cc
Normal 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
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue