Skip to content
Permalink
Browse files

Add message capability to snap()

snap("checkpoint one") will now store that message with the period and will
show it in the report:

  $ perl6 -e 'use Telemetry; snapper; sleep .2; snap("checkpoint"); sleep .1'
Telemetry Report of Process #89112 (2019-04-16T10:18:37Z)
Number of Snapshots: 6
Initial/Final Size: 81664 / 82052 Kbytes
Total Time:           0.31 seconds
Total CPU Usage:      0.01 seconds
No supervisor thread has been running

wallclock  util%  max-rss
   105562   0.88      368
    99626   0.05        4
     3318   1.38       12
   100438   0.04
     1959   3.31        4
--------- ------ --------
   310903   0.36      388
  • Loading branch information...
lizmat committed Apr 16, 2019
1 parent 9ce87ee commit afc9f849493c8383a15b8bb07a60b7782c270edb
Showing with 19 additions and 4 deletions.
  1. +19 −4 lib/Telemetry.pm6
@@ -565,8 +565,9 @@ INIT without $*SAMPLER {

# Telemetry --------------------------------------------------------------------
class Telemetry does Associative {
has $!sampler;
has $!samples;
has $!sampler;
has $!samples;
has Str $.message is rw;

multi method new(Telemetry:) {
my $self := nqp::create(self);
@@ -658,6 +659,7 @@ multi sub infix:<->(
my $period := nqp::create(Telemetry::Period);
nqp::bindattr($period,Telemetry,'$!sampler',
nqp::getattr($a,Telemetry,'$!sampler'));
$period.message = $_ with $a.message;

my \samples-a := nqp::getattr($a,Telemetry,'$!samples');
my \samples-b := nqp::getattr($b,Telemetry,'$!samples');
@@ -698,8 +700,17 @@ multi sub infix:<->(

# Making a Telemetry object procedurally ---------------------------------------
proto sub snap(|) is export {*}
multi sub snap(--> Nil) { $snaps.push(Telemetry.new) }
multi sub snap(@s --> Nil) { @s.push(Telemetry.new) }
multi sub snap(--> Nil) {
$snaps.push(Telemetry.new);
}
multi sub snap(Str:D $message --> Nil) {
my \T := Telemetry.new;
T.message = $message;
$snaps.push(T);
}
multi sub snap(@s --> Nil) {
@s.push(Telemetry.new);
}

# Starting the snapper / changing the period size
my int $snapper-running;
@@ -858,6 +869,10 @@ HEADER
}

sub push-period($period --> Nil) {
with $period.message -> $message {
my $line = "#-- $message ";
nqp::push_s($text,$line ~ "-" x 80 - $line.chars);
}
nqp::push_s($text,
@formats.map( -> @info {
@info[DISPLAY]($period{@info[NAME]})

0 comments on commit afc9f84

Please sign in to comment.
You can’t perform that action at this time.