Skip to content

Commit

Permalink
Add Telemetry.supervisor
Browse files Browse the repository at this point in the history
- number of supervisor threads running (expected values: 0 or 1)
- use Telemetry; signal(SIGINT).tap: &exit; say Telemetry.supervisor # 1
- use Telemetry; say Telemetry.supervisor # 0
  • Loading branch information
lizmat committed Oct 31, 2017
1 parent 91543fe commit f72ad22
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/Telemetry.pm6
Expand Up @@ -8,16 +8,22 @@ class Telemetry {
has int $!cpu-user;
has int $!cpu-sys;
has int $!wallclock;
has int $!supervisor;

my num $start = Rakudo::Internals.INITTIME;

submethod BUILD() {
my \rusage = nqp::getrusage;
$!cpu-user = nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_SEC) * 1000000
$!cpu-user = nqp::atpos_i(rusage,nqp::const::RUSAGE_UTIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_UTIME_MSEC);
$!cpu-sys = nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_SEC) * 1000000
$!cpu-sys = nqp::atpos_i(rusage,nqp::const::RUSAGE_STIME_SEC) * 1000000
+ nqp::atpos_i(rusage, nqp::const::RUSAGE_STIME_MSEC);
$!wallclock = nqp::fromnum_I(1000000*nqp::sub_n(nqp::time_n,$start),Int);
$!wallclock =
nqp::fromnum_I(1000000 * nqp::sub_n(nqp::time_n,$start),Int);

my $scheduler := nqp::decont($*SCHEDULER);
$!supervisor = 1
if nqp::getattr($scheduler,ThreadPoolScheduler,'$!supervisor');
}

proto method cpu() { * }
Expand Down Expand Up @@ -54,6 +60,16 @@ class Telemetry {
}
multi method wallclock(Telemetry:D:) is raw { $!wallclock }

proto method supervisor() { * }
multi method supervisor(Telemetry:U:) {
nqp::istrue(
nqp::getattr(
nqp::decont($*SCHEDULER),ThreadPoolScheduler,'$!supervisor'
)
)
}
multi method supervisor(Telemetry:D:) { $!supervisor }

multi method Str(Telemetry:D:) {
$!wallclock ?? "$.cpu / $!wallclock" !! "cpu / wallclock"
}
Expand Down

0 comments on commit f72ad22

Please sign in to comment.