Skip to content

Commit

Permalink
Expose getrusage<max-rss> as Kernel.memory
Browse files Browse the repository at this point in the history
This is the 3rd part of exposing nqp::cpucores and nqp::getrusage to
the world.  We should probably decide if we want to keep these or not
this way before the next release.  This applies to:
- Kernel.cpu-cores  # number of cores in system
- Kernel.cpu-usage  # number of microseconds of CPU used by process
- Kernel.memory     # max resident set size in Kbytes
  • Loading branch information
lizmat committed Nov 12, 2017
1 parent 8c5bc57 commit 928e243
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/core/Kernel.pm
Expand Up @@ -178,6 +178,11 @@ class Kernel does Systemic {
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC)
}

my int $b2kb = nqp::atkey(nqp::backendconfig,'osname') eq 'darwin' ?? 10 !! 0;
method memory() is raw {
nqp::bitshiftr_i(nqp::atpos_i(nqp::getrusage,4),$b2kb) # ru_maxrss
}
}

Rakudo::Internals.REGISTER-DYNAMIC: '$*KERNEL', {
Expand Down

0 comments on commit 928e243

Please sign in to comment.