Skip to content

Commit

Permalink
Add message capability to snap()
Browse files Browse the repository at this point in the history
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 afc9f84
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/Telemetry.pm6
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -565,8 +565,9 @@ INIT without $*SAMPLER {


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


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


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


# Making a Telemetry object procedurally --------------------------------------- # Making a Telemetry object procedurally ---------------------------------------
proto sub snap(|) is export {*} proto sub snap(|) is export {*}
multi sub snap(--> Nil) { $snaps.push(Telemetry.new) } multi sub snap(--> Nil) {
multi sub snap(@s --> Nil) { @s.push(Telemetry.new) } $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 # Starting the snapper / changing the period size
my int $snapper-running; my int $snapper-running;
Expand Down Expand Up @@ -858,6 +869,10 @@ HEADER
} }


sub push-period($period --> Nil) { 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, nqp::push_s($text,
@formats.map( -> @info { @formats.map( -> @info {
@info[DISPLAY]($period{@info[NAME]}) @info[DISPLAY]($period{@info[NAME]})
Expand Down

0 comments on commit afc9f84

Please sign in to comment.