# Copyright (C) 2009 Facebook, 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: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * 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. # * Neither the name of Facebook nor the # names of its contributors may be used to endorse or promote products # derived from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY Facebook ''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 Facebook 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. # # This flattens the output from xtrabackup --stats to print one line per index # BEGIN { can_print = 0; printf "db-table-index-1 spaceid-2 rootpage-3 "; printf "leaf-rec-4 leaf-page-5 leaf-data-MB-6 leaf-pct-use-7 "; printf "non-leaf-page-8 non-leaf-data-MB-9 non-leaf-pct-use-10 "; printf "ext-page-11 ext-data-MB-12 ext-pct-use-13 "; printf "tot-page-14 tot-data-MB-15 tot-pct-use-16 "; printf "est-keys-17 est-leaf-pages-18 est-total-pages-19\n"; } /table:/ { if (can_print) { printme(); } tname = substr($2, 1, length($2) - 1); iname = substr($4, 1, length($4) - 1); space_id = substr($7, 1, length($7) - 1); root_page = $10; } /key vals:/ { est_key_vals = substr($3, 1, length($3) - 1); est_leaf_pages = substr($6, 1, length($6) - 1); est_total_pages = $9; } /real statistics:/ { non_leaf_pages = 0; non_leaf_data = 0; ext_pages = 0; ext_data = 0; } /level [0-9]+ pages:/ { non_leaf_pages += substr($4, 7, length($4) - 7); non_leaf_data += substr($5, 6, length($5) - 6); } /leaf pages:/ { can_print = 1; recs = substr($3, 6, length($3) - 6); pages = substr($4, 7, length($4) - 7); data = substr($5, 6, length($5) - 6); } /external pages:/ { ext_pages += substr($3, 7, length($3) - 7); ext_data += substr($4, 6, length($4) - 6); } function printme() { can_print = 0; printf("%s/%s %s %s ", tname, iname, space_id, root_page); # leaf only nzero_pages = 1; if (pages > nzero_pages) { nzero_pages = pages; } printf("%s %s %.1f %.1f ", recs, pages, data / (1024 * 1024), (data / (nzero_pages * 16 * 1024)) * 100); # non-leaf nzero_pages = 1; if (non_leaf_pages > nzero_pages) { nzero_pages = non_leaf_pages; } printf("%s %.1f %.1f ", non_leaf_pages, non_leaf_data / (1024 * 1024), (non_leaf_data / (nzero_pages * 16 * 1024)) * 100); # external nzero_pages = 1; if (ext_pages > nzero_pages) { nzero_pages = ext_pages; } printf("%s %.1f %.1f ", ext_pages, ext_data / (1024 * 1024), (ext_data / (nzero_pages * 16 * 1024)) * 100); # total tot_pages = pages + non_leaf_pages + ext_pages; tot_data = data + non_leaf_data + ext_data; nzero_pages = 1; if (tot_pages > nzero_pages) { nzero_pages = tot_pages; } printf("%s %.1f %.1f ", tot_pages, tot_data / (1024 * 1024), (tot_data / (nzero_pages * 16 * 1024)) * 100); # estimates printf("%s %s %s\n", est_key_vals, est_leaf_pages, est_total_pages); } END { if (can_print) { printme(); } }