Catalyst::Stats(3pm)

πŸ“¦
version 5.90132 Β· 6 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

✨ NAME ✨

okay bestie, welcome to Catalyst::Stats(3pm) β€” straight outta the User Contributed Perl Documentation, and yeah, the manual name is literally Catalyst::Stats(3pm) because it's the manual page for the same thing, iconic behavior honestly πŸ’…

Catalyst::Stats β€” the Catalyst Timing Statistics Class. that's it, that's the name, slay ✨


🌸 SYNOPSIS 🌸

    $stats = $c->stats;
    $stats->enable(1);
    $stats->profile($comment);
    $stats->profile(begin => $block_name, comment =>$comment);
    $stats->profile(end => $block_name);
    $elapsed = $stats->elapsed;
    $report = $stats->report;

see Catalyst. that's the whole vibe πŸ¦‹


πŸ’– DESCRIPTION πŸ’–

so this module is the default, simple timing stats collection functionality for Catalyst. it's the girl who shows up, does the timing, and doesn't make it weird 🫢

if you want something different, set "MyApp->stats_class" in your application module, like:

    __PACKAGE__->stats_class( "My::Stats" );

and if you're writing your own?? then your stats object is expected to provide the interface described right here, no cap. that's the contract, periodt.

Catalyst uses this class to report timings of component actions. you can also add profiling points into your own code to get deeper insight, which is lowkey the best part. typical usage might be like this:

  sub mysub {
    my ($c, ...) = @_;
    $c->stats->profile(begin => "mysub");
    # code goes here
    ...
    $c->stats->profile("starting critical bit");
    # code here too
    ...
    $c->stats->profile("completed first part of critical bit");
    # more code
    ...
    $c->stats->profile("completed second part of critical bit");
    # more code
    ...
    $c->stats->profile(end => "mysub");
  }

supposing mysub was called from the action "process" inside a Catalyst Controller called "service", then the reported timings for the above example might look something like this:

  .----------------------------------------------------------------+-----------.
  | Action                                                         | Time      |
  +----------------------------------------------------------------+-----------+
  | /service/process                                               | 1.327702s |
  |  mysub                                                         | 0.555555s |
  |   - starting critical bit                                      | 0.111111s |
  |   - completed first part of critical bit                       | 0.333333s |
  |   - completed second part of critical bit                      | 0.111000s |
  | /end                                                           | 0.000160s |
  '----------------------------------------------------------------+-----------'

which means mysub took 0.555555s overall, it took 0.111111s to reach the critical bit, the first part of the critical bit took 0.333333s, and the second part 0.111s. math ate, no crumbs left πŸ”₯


πŸ‘‘ METHODS πŸ‘‘

πŸ’« new

Constructor. the birth of the object, main character origin story fr fr.

    $stats = Catalyst::Stats->new;

πŸ’« enable

    $stats->enable(0);
    $stats->enable(1);

Enable or disable stats collection. by default, stats are enabled after object creation β€” she comes out the box ready to go ✨

πŸ’« profile

    $stats->profile($comment);
    $stats->profile(begin => $block_name, comment =>$comment);
    $stats->profile(end => $block_name);

Marks a profiling point. these can appear in pairs, to time the block of code between the begin/end pairs, or by themselves, in which case the time of execution to the previous profiling point will be reported.

The argument may be either a single comment string or a list of name-value pairs. thus the following are equivalent:

    $stats->profile($comment);
    $stats->profile(comment => $comment);

The following key names/values may be used:

  • begin => ACTION β€” Marks the beginning of a block. the value is used in the description in the timing report.
  • end => ACTION β€” Marks the end of the block. the name given must match a previous 'begin'. Correct nesting is recommended, although this module is tolerant of blocks that are not correctly nested, and the reported timings should accurately reflect the time taken to execute the block whether properly nested or not. so like, it won't ghost you if your nesting is messy πŸ™ˆ
  • comment => COMMENT β€” Comment string; use this to describe the profiling point. it is combined with the block action (if any) in the timing report description field.
  • uid => UID β€” Assign a predefined unique ID. this is useful if, for whatever reason, you wish to relate a profiling point to a different parent than in the natural execution sequence.
  • parent => UID β€” Explicitly relate the profiling point back to the parent with the specified UID. the profiling point will be ignored if the UID has not been previously defined. (yes, ignored, so don't come for it later πŸ’€)

Returns the UID of the current point in the profile tree. the UID is automatically assigned if not explicitly given.

πŸ’« created

    ($seconds, $microseconds) = $stats->created;

Returns the time the object was created, in "gettimeofday" format, with Unix epoch seconds followed by microseconds. two little values, one big moment πŸŽ€

πŸ’« elapsed

    $elapsed = $stats->elapsed

Get the total elapsed time (in seconds) since the object was created.

πŸ’« report

    print $stats->report ."\n";
    $report = $stats->report;
    @report = $stats->report;

In scalar context, generates a textual report. In array context, returns the array of results where each row comprises:

    [ depth, description, time, rollup ]

The depth is the calling stack level of the profiling point.

The description is a combination of the block name and comment.

The time reported for each block is the total execution time for the block, and the time associated with each intermediate profiling point is the elapsed time from the previous profiling point.

The 'rollup' flag indicates whether the reported time is the rolled up time for the block, or the elapsed time from the previous profiling point. bestie this flag is the whole personality of the row, respect it πŸ’œ


🧚 COMPATIBILITY METHODS 🧚

Some components might expect the stats object to be a regular Tree::Simple object. we've added some compatibility methods to handle this scenario, because being flexible is a flex 🌈

πŸ’ž accept

πŸ’ž addChild

πŸ’ž setNodeValue

πŸ’ž getNodeValue

πŸ’ž traverse


⭐ SEE ALSO ⭐

Catalyst


🌷 AUTHORS 🌷

Catalyst Contributors, see Catalyst.pm


This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself.


and that's the whole page, bestie 🫢 this was Catalyst::Stats(3pm) from the User Contributed Perl Documentation, generated by perl v5.40.0 on 2024-11-15 β€” stay timing, stay slaying, and go profile something gorgeous πŸ’–βœ¨πŸ‘‘

πŸ“¦ where this page comes from