From c4d373c51433ee58b2f44955e98c8d741ec29bb1 Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Sat, 4 Nov 2017 21:42:15 +0100 Subject: [PATCH] Expose basic CPU usage information: Kernel.cpu-usage 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. --- src/core/Kernel.pm | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/Kernel.pm b/src/core/Kernel.pm index 0e891a7d5e4..9d145487f8b 100644 --- a/src/core/Kernel.pm +++ b/src/core/Kernel.pm @@ -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', {