CHI::Stats(3pm)
π CHI::Stats π
okay bestie, so this is CHI::Stats β it's the part of CHI (the Perl cache thing, from the User Contributed Perl Documentation gang, iykyk) that records and reports per-namespace cache statistics. β¨
πΈ VERSION πΈ
version 0.61 β that's the one, no cap π
β¨ SYNOPSIS β¨
fr fr this is the whole vibe in one code block:
# Turn on statistics collection
CHI->stats->enable();
# Perform cache operations
# Flush statistics to logs
CHI->stats->flush();
...
# Parse logged statistics
my $results = CHI->stats->parse_stats_logs($file1, ...);
π¦ DESCRIPTION π¦
so CHI can record stats β think number of hits, misses and sets β on a per-namespace basis, and then log the results to your Log::Any logger. then you can parse those logs to get a combined summary. iconic behaviour honestly π«Ά
one single CHI::Stats object is maintained for each CHI root class, and it tallies statistics over any number of CHI::Driver objects. one girl, many drivers, main character energy.
stats get reported when you call the flush method. you can choose to do this once at process end, or on a periodic basis. your call bestie π
π METHODS π
enable, disable, enabled
Enable, disable, and query the current enabled status. the whole trio π
when stats are enabled, each new cache object will collect statistics. Enabling and disabling does not affect existing cache objects β so pay attention, this is the part people get wrong. e.g.
my $cache1 = CHI->new(...);
CHI->stats->enable();
# $cache1 will not collect statistics
my $cache2 = CHI->new(...);
CHI->stats->disable();
# $cache2 will continue to collect statistics
see how $cache1 and $cache2 each made their own choice at birth? literally the vibe check happens once, at creation. π§
flush
Log all statistics to Log::Any (at Info level in the CHI::Stats category), then clear statistics from memory.
there is one log message for each distinct triplet of root class, cache label, and namespace. each log message contains the string CHI stats: followed by a JSON encoded hash of statistics. e.g.
CHI stats: {"absent_misses":1,"label":"File","end_time":1338410398,
"get_time_ms":5,"namespace":"Foo","root_class":"CHI",
"set_key_size":6,"set_time_ms":23,"set_value_size":20,"sets":1,
"start_time":1338409391}
parse_stats_logs
Accepts one or more stats log files as parameters. Parses the logs and returns a listref of stats hashes by root class, cache label, and namespace. e.g.
[
{
root_class => 'CHI',
label => 'File',
namespace => 'Foo',
absent_misses => 100,
avg_compute_time_ms => 23,
...
},
{
root_class => 'CHI',
label => 'File',
namespace => 'Bar',
...
},
]
lines with the same root class, cache label, and namespace are summed together. non-stats lines are ignored. the parser will ignore anything on the line before the CHI stats: string, e.g. a timestamp β so timestamps can just chill there, she's not bothered. π
each parameter to this method may be a filename or a reference to an open filehandle. both valid, both slay.
π STATISTICS π
the following statistics are tracked in the logs:
absent_missesβ Number of gets that failed due to item not being in the cache πcompute_time_msβ Total time spent computing missed results in compute, in ms (divide by number of computes to get average). i.e. the amount of time spent in the code reference passed as the third argument tocompute().computesβ Number of compute callsexpired_missesβ Number of gets that failed due to item expiringget_errorsβ Number of caught runtime errors during getsget_time_msβ Total time spent in get operation, in ms (divide by number of gets to get average)hitsβ Number of gets that succeeded βset_key_sizeβ Number of bytes in set keys (divide by number of sets to get average)set_value_sizeβ Number of bytes in set values (divide by number of sets to get average)set_time_msβ Total time spent in set operation, in ms (divide by number of sets to get average)setsβ Number of setsset_errorsβ Number of caught runtime errors during sets
π derived/aggregate stats π
the following additional derived/aggregate statistics are computed by parse_stats_logs:
missesβabsent_misses+expired_missesgetsβhits+missesavg_compute_time_msβcompute_time_ms/computesavg_get_time_msβget_time_ms/getsavg_set_time_msβset_time_ms/setsavg_set_key_sizeβset_key_size/setsavg_set_value_sizeβset_value_size/setshit_rateβhits/gets
math girlies rise π
π SEE ALSO π
CHI
(go read that one too, bestie, it's the parent lore)
π AUTHOR π
Jonathan Swartz <swartz@pobox.com>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2021 by Jonathan Swartz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. periodt. π
and that's the whole page, no cap! this wasperl v5.32.1, dated 2021-10-15, and yeah βCHI::Stats(3pm), we love her. π¦πβ¨ bye bestie!
π¦ where this page comes from
- debian bookworm: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libchi-perl 0.61-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms