Skip to content

Commit

Permalink
Expose basic CPU usage information: Kernel.cpu-usage
Browse files Browse the repository at this point in the history
For situations like the Benchmark module, we don't want to have to load
a lot of stuff.  This gives the bare-bones of the stuff we need there.
  • Loading branch information
lizmat committed Nov 4, 2017
1 parent 4ed91ed commit c4d373c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/Kernel.pm
Expand Up @@ -170,6 +170,14 @@ class Kernel does Systemic {
multi method signal(Kernel:D: Int:D \signal --> Int:D) { signal }

method cpu-cores() is raw { nqp::cpucores }

method cpu-usage() is raw {
my \rusage = nqp::getrusage();
nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_MSEC)
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC)
}
}

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

0 comments on commit c4d373c

Please sign in to comment.