Skip to content

Commit

Permalink
Add snapper.pm6
Browse files Browse the repository at this point in the history
- helper module for starting up a Telemetry snapper externally
  - through either -Msnapper or "use snapper"
  - because of auto-reporting now a useful tool for snapping a whole script
- some other minor tweaks in Telemetry
  • Loading branch information
lizmat committed Oct 31, 2017
1 parent 2f963b1 commit c1867ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Telemetry.pm6
@@ -1,4 +1,4 @@
# An attempt at providing an API to nqp::getrusage.
# Provide an API for keeping track of a lot of system lifesigns

use nqp;

Expand Down Expand Up @@ -320,7 +320,7 @@ multi sub report(@s) {
sub hide0(\value) { value ?? sprintf("%3d",value) !! " " }

my $total = @s[*-1] - @s[0];
my $text := nqp::list_s(qq:to/HEADER/);
my $text := nqp::list_s(qq:to/HEADER/.chomp);
Telemetry Report of Process #$*PID ($*INIT-INSTANT.DateTime())
Number of Snapshots: {+@s}
Total Time: { ($total.wallclock / 1000000).fmt("%9.2f") } seconds
Expand All @@ -331,25 +331,25 @@ HEADER

sub push-period($_) {
nqp::push_s($text,
sprintf("%6.2f %s %s %s %s %s %s\n",
sprintf("%6.2f %s %s %s %s %s %s",
.utilization,
hide0(.supervisor),
hide0(.general-workers), hide0(.general-jobs),
hide0(.timer-workers), hide0(.timer-jobs),
hide0(.affinity-workers)
)
).trim-trailing
);
}

push-period($_) for periods(@s);

nqp::push_s($text, qq:to/FOOTER/);
nqp::push_s($text, qq:to/FOOTER/.chomp);
------ --- --- --- --- --- ---
FOOTER

push-period($total);

nqp::join('',$text)
nqp::join("\n",$text)
}

END { if @snaps { snap; note report } }
Expand Down
7 changes: 7 additions & 0 deletions lib/snapper.pm6
@@ -0,0 +1,7 @@
# shorthand for loading Telemetry and starting a snapper

use Telemetry;

snapper;

# vim: ft=perl6 expandtab sw=4
1 change: 1 addition & 0 deletions tools/build/install-core-dist.pl
Expand Up @@ -11,6 +11,7 @@
"experimental" => "lib/experimental.pm6",
"CompUnit::Repository::Staging" => "lib/CompUnit/Repository/Staging.pm",
"Telemetry" => "lib/Telemetry.pm6",
"snapper" => "lib/snapper.pm6",
;

PROCESS::<$REPO> := CompUnit::Repository::Staging.new(
Expand Down

0 comments on commit c1867ba

Please sign in to comment.