|
| 1 | +=begin pod |
| 2 | +
|
| 3 | +=TITLE class Telemetry |
| 4 | +
|
| 5 | +=SUBTITLE Collect performance state for analysis |
| 6 | +
|
| 7 | + class Telemetry { } |
| 8 | + class Telemetry::Period { } |
| 9 | +
|
| 10 | +On creation, a C<Telemetry> object contains a snapshot of the current state |
| 11 | +of the virtual machine. This is in itself useful, but generally one needs |
| 12 | +two snapshots for the difference (which is a C<Telemetry::Period> object). |
| 13 | +
|
| 14 | +The following data is available both as a method on a C<Telemetry> type object, |
| 15 | +as well as on an instantiated C<Telemetry> object. When loading it as a |
| 16 | +module with the C<:COLUMNS> named parameter, these are also available as |
| 17 | +standalone subroutines. |
| 18 | +
|
| 19 | +=begin code :skip-test |
| 20 | +use Telemetry; # imports default subroutines: T, snap, snapper, periods, report |
| 21 | +use Telemetry :COLUMNS; # imports all of the possible columns of report |
| 22 | +use Telemetry < cpu wallclock snap >; # only imports cpu, wallclock and snap |
| 23 | +=end code |
| 24 | +
|
| 25 | +=head2 available data |
| 26 | +
|
| 27 | +=item affinity-tasks-completed |
| 28 | +
|
| 29 | +The number of tasks completed in affinity threads. Column name: C<atc>. |
| 30 | +
|
| 31 | +=item affinity-tasks-queued |
| 32 | +
|
| 33 | +The number of tasks queued for execution in affinity threads. Column name: |
| 34 | +C<atq>. |
| 35 | +
|
| 36 | +=item affinity-workers |
| 37 | +
|
| 38 | +The number of affinity threads. Column name: C<aw>. |
| 39 | +
|
| 40 | +=item cpu |
| 41 | +
|
| 42 | +The amount of CPU time spent since start of program (in microseconds). |
| 43 | +Essentially, this is the same as C<cpu-user> + C<cpu-sys>. |
| 44 | +
|
| 45 | +=item cpu-user |
| 46 | +
|
| 47 | +The amount of CPU time spent on executing user code since start of program |
| 48 | +(in microseconds). |
| 49 | +
|
| 50 | +=item cpu-sys |
| 51 | +
|
| 52 | +The amount of CPU time spent in system overhead since start of program |
| 53 | +(in microseconds). |
| 54 | +
|
| 55 | +=item general-tasks-completed |
| 56 | +
|
| 57 | +The number of tasks completed in general worker threads. Column name: C<gtc>. |
| 58 | +
|
| 59 | +=item general-tasks-queued |
| 60 | +
|
| 61 | +The number of tasks queued for execution in general worker threads. Column |
| 62 | +name: C<gtq>. |
| 63 | +
|
| 64 | +=item general-workers |
| 65 | +
|
| 66 | +The number of general worker threads. Column name: C<gw>. |
| 67 | +
|
| 68 | +=item max-rss |
| 69 | +
|
| 70 | +Maximum resident set size (in Kbytes). |
| 71 | +
|
| 72 | +=item supervisor |
| 73 | +
|
| 74 | +The number of supervisor threads running, usually C<0> or C<1>. Column name: |
| 75 | +C<s>. |
| 76 | +
|
| 77 | +=item timer-tasks-completed |
| 78 | +
|
| 79 | +The number of tasks completed in timer worker threads. Column name: C<ttc>. |
| 80 | +
|
| 81 | +=item timer-tasks-queued |
| 82 | +
|
| 83 | +The number of tasks queued for execution in timer worker threads. Column |
| 84 | +name: C<ttq>. |
| 85 | +
|
| 86 | +=item timer-workers |
| 87 | +
|
| 88 | +The number of timer worker threads. Column name: C<tw>. |
| 89 | +
|
| 90 | +=item wallclock |
| 91 | +
|
| 92 | +The time the program has been executing (in microseconds). |
| 93 | +
|
| 94 | +Apart from this data, other fields in the POSIX C<getrusage> struct are also |
| 95 | +collected, but are probably not in use on most operating systems and will thus |
| 96 | +always give 0. These are (column names in parenthesis): |
| 97 | +
|
| 98 | +id-rss, inblock (inb), invcw, is-rss, ix-rss, maj-flt (aft), min-flt (ift), |
| 99 | +msgrcv (mrc), msgsnd (msd), nsignals (ngs), nswap (nsw), nvcsw (vcs), |
| 100 | +outblock (oub). |
| 101 | +
|
| 102 | +Please consult the C<getrusage> manual information for the meaning of these |
| 103 | +fields. |
| 104 | +
|
| 105 | +=begin code |
| 106 | +# basic simple usage |
| 107 | +use Telemetry; |
| 108 | +my $t = Telemetry.new; |
| 109 | +say "Used $t (cpu / wallclock) microseconds to execute so far"; |
| 110 | +=end code |
| 111 | +
|
| 112 | +=head1 Additional subroutines |
| 113 | +
|
| 114 | +=head2 routine T |
| 115 | +
|
| 116 | +Shortcut for C<Telemetry.new>. It is exported by default. Since the |
| 117 | +C<Telemetry> class also provides an C<Associative> interface, one can easily |
| 118 | +interpolate multiple values in a single statement: |
| 119 | +
|
| 120 | +=begin code |
| 121 | +use Telemetry; |
| 122 | +say "Used {T<max-rss cpu>} (KBytes CPU) so far"; |
| 123 | +=end code |
| 124 | +
|
| 125 | +=head2 routine snap |
| 126 | +
|
| 127 | +The C<snap> subroutine is shorthand for creating a new C<Telemetry> object and |
| 128 | +pushing it to an array for later processing. It is exported by default. |
| 129 | +
|
| 130 | +=begin code |
| 131 | +use Telemetry; |
| 132 | +my @t; |
| 133 | +for ^5 { |
| 134 | + snap(@t); |
| 135 | + # do some stuff |
| 136 | + LAST snap(@t); |
| 137 | +} |
| 138 | +=end code |
| 139 | +
|
| 140 | +If no array is specified, it will use an internal array for convenience. |
| 141 | +
|
| 142 | +=head2 routine snapper |
| 143 | +
|
| 144 | +The C<snapper> routine starts a separate thread that will call C<snap> |
| 145 | +repeatedly until the end of program. It is exported by default. |
| 146 | +
|
| 147 | +By default, it will call C<snap> every B<0.1> second. The only positional |
| 148 | +parameter is taken to be the delay between C<snap>s. |
| 149 | +
|
| 150 | +Please see the L<snapper> module for externally starting a snapper without |
| 151 | +having to change the code. Simply adding C<-Msnapper> as a command line |
| 152 | +parameter, will then start a snapper for you. |
| 153 | +
|
| 154 | +=head2 routine periods |
| 155 | +
|
| 156 | +The C<periods> subroutine processes an array of C<Telemetry> objects and |
| 157 | +generates a L<Seq> of C<Telemetry::Period> objects out of that. It is exported |
| 158 | +by default. |
| 159 | +
|
| 160 | +=begin code :preamble<my @t;use Telemetry;> |
| 161 | +.say for periods(@t); |
| 162 | +
|
| 163 | +# OUTPUT: |
| 164 | +# ==================== |
| 165 | +# 164 / 160 |
| 166 | +# 23 / 21 |
| 167 | +# 17 / 17 |
| 168 | +# 15 / 16 |
| 169 | +# 29 / 28 |
| 170 | +=end code |
| 171 | +
|
| 172 | +If no array is specified, it will use the internal array of C<snap> without |
| 173 | +parameters B<and> will reset that array upon completion (so that new C<snap>s |
| 174 | +can be added again). |
| 175 | +
|
| 176 | +=begin code |
| 177 | +use Telemetry; |
| 178 | +for ^5 { |
| 179 | + snap; |
| 180 | + LAST snap; |
| 181 | +} |
| 182 | +.say for periods; |
| 183 | +
|
| 184 | +# OUTPUT: |
| 185 | +# ==================== |
| 186 | +# 172 / 168 |
| 187 | +# 24 / 21 |
| 188 | +# 17 / 18 |
| 189 | +# 17 / 16 |
| 190 | +# 27 / 27 |
| 191 | +=end code |
| 192 | +
|
| 193 | +If only one C<snap> was done, another C<snap> will be done to create at least |
| 194 | +one C<Telemetry::Period> object. |
| 195 | +
|
| 196 | +=head2 routine report |
| 197 | +
|
| 198 | +The C<report> subroutine generates a report about an array of C<Telemetry> |
| 199 | +objects. It is exported by default. These can have been created by regularly |
| 200 | +calling C<snap>, or by having a L<snapper> running. If no positional parameter |
| 201 | +is used, it will assume the internal array to which the parameterless C<snap> |
| 202 | +pushes. |
| 203 | +
|
| 204 | +=head3 additional named parameters |
| 205 | +
|
| 206 | +=item :columns |
| 207 | +
|
| 208 | +Specify the names of the columns to be included in the report. Names can |
| 209 | +be specified with the full method name (e.g. C<general-workers>) or with |
| 210 | +the abbreviated column name (e.g. C<gw>). If not specified, defaults to |
| 211 | +what is specified in the C<RAKUDO_REPORT_COLUMNS> environment variable. |
| 212 | +If that is not set either, defaults to: |
| 213 | +
|
| 214 | + =for code :skip-test |
| 215 | + wallclock util% max-rss gw gtc tw ttc aw atc |
| 216 | +
|
| 217 | +=item :header-repeat |
| 218 | +
|
| 219 | +Specifies after how many lines the header should be repeated in the report. |
| 220 | +If not specified, defaults to what is specified in the |
| 221 | +C<RAKUDO_REPORT_HEADER_REPEAT> environment variable. If that is not set either, |
| 222 | +defaults to 32. |
| 223 | +
|
| 224 | +=item :legend |
| 225 | +
|
| 226 | +Specifies whether a legend should be added to the report. If not specified, |
| 227 | +defaults to what is specified in the C<RAKUDO_REPORT_LEGEND> environment variable. |
| 228 | +If that is not set either, defaults to True. |
| 229 | +
|
| 230 | +If there are C<snap>s available in the internal array at the end of the |
| 231 | +program, then C<report> will be automatically generated and printed on C<STDERR>. |
| 232 | +
|
| 233 | +See Also: L<Telemetry::Period>, L<snapper> |
| 234 | +
|
| 235 | +=end pod |
0 commit comments