NAME
Pg::Explain::Buffers - Object to store buffers information about node in PostgreSQL's explain analyze
VERSION
Version 2.7
SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use Pg::Explain;
my $explain = Pg::Explain->new('source_file' => 'some_file.out');
...
if ( $explain->top_node->buffers ) {
print $explain->top_node->buffers->as_text();
}
...
Alternatively you can build the object itself from either a string (conforming to text version of EXPLAIN ANALYZE output) or a structure, containing keys like in JSON/YAML/XML formats of the explain:
use Pg::Explain::Buffers;
my $from_string = Pg::Explain::Buffers->new( 'Buffers: shared hit=12101 read=73' );
my $from_struct = Pg::Explain::Buffers->new( {
'Shared Hit Blocks' => 12101,
'Shared Read Blocks' => 73,
} );
To such object you can later on add Timing information, though only with string - if you had it in struct, make it available on creation.
$buffers->add_timing( 'I/O Timings: read=58.316 write=1.672' );
FUNCTIONS
new
Object constructor.
Takes one argument, either a string or hashref to build data from.
add_timing
Adds timing information to existing buffer info.
Takes one argument, either a string or hashref to build data from.
as_text
Returns text representation of stored buffers info, together with timings (if available).
get_struct
Returns hash(ref) with all data about buffers from this object. Keys in this hash:
shared (with subkeys: hit, read, dirtied, written)
local (with subkeys: hit, read, dirtied, written)
temp (with subkeys: read, written)
timings (with subkeys: read, write, info)
Only elements with non-zero values are returned. If there are no elements to be returned, it returns undef.
data
Accessor to internal data.
OPERATORS
To allow for easier work on buffer values + and - operators are overloaded, so you can:
$buffers_out = $buffers1 - $buffers2;
While processing subtraction, it is important that it's not possible to get negative values, so if any value would drop below 0, it will get auto-adjusted to 0.
INTERNAL METHODS
_build_from_struct
Gets data out of provided HASH.
_build_timing_info
Based on data from structure from json/yaml/xml, build I/O Timings: info line for textual representation of explain.
_build_from_string
Gets data out of provided string.
_buffers_add
Creates new Pg::Explain::Buffers object by adding values based on two objects. To be used like:
my $result = $buffers1 + $buffers2;
_buffers_subtract
Creates new Pg::Explain::Buffers object by subtracting values based on two objects. To be used like:
my $result = $buffers1 - $buffers2;
_buffers_bool
For checking if given variable is set, as in:
$r = $buffers1 - $buffers2;
if ( $r ) {...}
AUTHOR
hubert depesz lubaczewski, <depesz at depesz.com>
BUGS
Please report any bugs or feature requests to depesz at depesz.com
.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Pg::Explain::Buffers
COPYRIGHT & LICENSE
Copyright 2008-2023 hubert depesz lubaczewski, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.