Skip to content

Commit

Permalink
Introducing Telemetry snapper
Browse files Browse the repository at this point in the history
- runs a repeated snap() in a separate Thread
  - outside the ThreadPoolScheduler, as to prevent interference
- defaults to once every .1 second, can be adjusted with snapper($sleep)
- can be run in a BEGIN or INIT phaser
- will only allow one snapper to be running at any time
  • Loading branch information
lizmat committed Oct 31, 2017
1 parent f51a3ef commit 8a0eb7f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/Telemetry.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,23 @@ multi sub infix:<->(Telemetry:D $a, Telemetry:D $b) is export {
)
}

constant T is export = Telemetry;

my @snaps;
proto sub snap(|) is export { * }
multi sub snap(--> Nil) { @snaps.push(Telemetry.new) }
multi sub snap(@s --> Nil) { @s.push(Telemetry.new) }

my int $snapper-running;
sub snapper($sleep = 0.1 --> Nil) is export {
unless $snapper-running {
Thread.start(:app_lifetime, :name<Snapper>, {
loop { snap; sleep $sleep }
});
$snapper-running = 1
}
}

proto sub periods(|) is export { * }
multi sub periods() {
my @s = @snaps;
Expand Down

0 comments on commit 8a0eb7f

Please sign in to comment.