@@ -19,7 +19,8 @@ L<C<Telemetry::Instrument::Usage>|/type/Telemetry::Instrument::Usage>
1919and L<C<Telemetry::Instrument::ThreadPool>|/type/Telemetry::Instrument::ThreadPool>
2020instruments are activated.
2121
22- The C<Telemetry> (and L<C<Telemetry::Period>|/type/Telemetry::Period>) object also L<C<Associative>|/type/Associative>. This means
22+ The C<Telemetry> (and L<C<Telemetry::Period>|/type/Telemetry::Period>) objects
23+ also do the role L<C<Associative>|/type/Associative>. This means
2324that you can treat a Telemetry object as a read-only L<C<Hash>|/type/Hash>, with all of the
2425data values of the instruments as keys.
2526
@@ -77,22 +78,50 @@ say "Used {T<max-rss cpu>} (KiB CPU) so far";
7778 multi snap(@s --> Nil)
7879
7980The C<snap> subroutine is shorthand for creating a new C<Telemetry> object and
80- pushing it to an array for later processing. It is exported by default. From
81- release 2021.12, it returns the filename it's storing the snapshots in the
82- case it's provided with a C<:$heap> associative parameter.
81+ pushing it to an array for later processing. The subroutine is exported by default.
82+
83+ From release 2017.11, one can give a custom array C<@s> to push to:
8384
8485=begin code
8586use Telemetry;
86- my @t ;
87+ my @s ;
8788for ^5 {
88- snap(@t );
89+ snap(@s );
8990 # do some stuff
90- LAST snap(@t );
91+ LAST snap(@s );
9192}
9293=end code
9394
9495If no array is specified, it will use an internal array for convenience.
9596
97+ From release 2019.07, C<snap> accepts a positional argument C<$message> of type C<Str>, which will
98+ become the value of the C<message> attribute of the new C<Telemetry> object.
99+
100+ Also from release 2019.07, one can pass a named argument C<:heap>
101+ to instruct the compiler to write a heap snapshot to a file.
102+ From release 2021.12, C<snap> returns that filename.
103+ The argument C<:heap> can be of type C<Bool>, C<Str>, or C<IO::Path>. Their implications are as follows:
104+
105+ =item C<IO::Path>, e.g. C«snap( heap => 'outputfile'.IO )»: The snapshot will be written to exactly this path.
106+ The returned filename is always an absolute path.
107+
108+ =item C<Str>, e.g. C«snap(:heap<outputfile>)»: The snapshot will be written to this path I<if> no such file already exists.
109+ If such a file already exists, the snapshot will instead be written to C<outputfile-$($*PID)-$($i).mvmheap>
110+ (where C<$i> starts at 1 and increases each time).
111+ The returned filename is a relative or an absolute path depending on what form C<:heap> has.
112+
113+ =item Boolean C<True>, e.g. C<snap(:heap)>: The snapshot will be written to the file C<heapsnapshot-$($*PID)-$($i).mvmheap>.
114+ The returned filename is always a relative path.
115+
116+ Additionally, in each of these cases, two ordinary C<Telemetry> objects are pushed to the internal array:
117+ One of them is created just before writing the snapshot and has C<$message> as its C<message> attribute.
118+ The other is created just after writing the snapshot and has the filename as ith C<message> attribute.
119+
120+ Finally, there's also this option for C<:heap>:
121+
122+ =item Boolean C<False>, e.g. C<snap(:!heap)>: No heap snapshot is taken, no file is written.
123+ Instead, C<snap()> will be called (or C<snap($message)>, if a custom C<$message> has been specified).
124+
96125=head2 routine snapper
97126
98127 sub snapper($sleep = 0.1, :$stop, :$reset --> Nil)
0 commit comments