Skip to content

Commit

Permalink
Add Telemetry::Period.cpus/utilization
Browse files Browse the repository at this point in the history
- cpus returns string indicating how many CPU's were used
- utilization returns a string indicating % of CPU power used
  • Loading branch information
lizmat committed Oct 29, 2017
1 parent 5244048 commit b30916f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Telemetry.pm6
Expand Up @@ -91,6 +91,16 @@ class Telemetry::Period is Telemetry {
nqp::getattr_i(self,Telemetry,'$!wallclock')
}))"
}

method cpus() {
nqp::add_i(
nqp::getattr_i(self,Telemetry,'$!cpu-user'),
nqp::getattr_i(self,Telemetry,'$!cpu-sys')
) / nqp::getattr_i(self,Telemetry,'$!wallclock')
}

my $factor = 100 / Kernel.cpu-cores;
method utilization() { $factor * self.cpus }
}

multi sub infix:<->(Telemetry:U $a, Telemetry:U $b) is export {
Expand Down

0 comments on commit b30916f

Please sign in to comment.