=comment Copyright (c) 2024, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =cut =comment User contributed content on the Perforce Public Depot is not supported by Perforce, although it may be supported by its author. This applies to all contributions even those submitted by Perforce employees. =cut =comment This program processes a journal and reports a summary of the records found within it, printing each table and the size of the records associated with that table. It does not consider records like @dl@. Usage: jnltool.pl --progress=0 -E jnltool-record_size_stats.pl $journal_file db.label 11462384 00.83% db.locks 37316028 02.71% db.domain 56355007 04.09% db.working 72359061 05.25% db.have 1177237088 85.39% Note that this is not a stand-alone program, but relies on the jnltool support utility. The execution context of the below code is from within the jnltool runtime. =cut $jnl = open_ckp $jnl_name; use bytes; my %tab_sz; my $jnl_sz = -s $jnl; parse $jnl, sub { my $rec = $_[ 0 ]; # The size we report is the size of each record on-disk. $tab_sz{ $rec->{ table } } += length to_jnl_fmt $rec; return 0; }, [ 0, $jnl_sz ]; my $mtl = 0; # Maximum table length, for padding. map { $mtl = length if length > $mtl } keys %tab_sz; my $mvl = 0; # Maximum value length, for padding. map { my $v = $tab_sz{ $_ }; $mvl = length $v if length( $v ) > $mvl } keys %tab_sz; # Print the report: map { my $v = $tab_sz{ $_ }; print $_ # Table . ( ' ' x ( 5 + $mtl - length ) ) # Table padding . ( ' ' x ( $mvl - length $v ) ) # Value padding . "$v " # Value (bytes) . sprintf "%05.2f%%\n", 100 * ( $v / $jnl_sz ) # Value (percentage) } sort { $tab_sz{ $a } <=> $tab_sz{ $b } } keys %tab_sz;