1 21 22 package org.apache.derby.impl.store.access.heap; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 import org.apache.derby.iapi.store.raw.ContainerHandle; 28 import org.apache.derby.iapi.store.raw.Page; 29 import org.apache.derby.iapi.services.diag.Diagnosticable; 30 import org.apache.derby.iapi.services.diag.DiagnosticableGeneric; 31 import org.apache.derby.iapi.services.diag.DiagnosticUtil; 32 33 34 import java.util.Properties ; 35 36 37 43 44 class TableStats 45 { 46 public int num_pages = 0; public int num_overflow_pgs = 0; public int num_entries = 0; public int num_deleted = 0; public long max_pageno = 0; public long num_free_bytes = 0; public long num_res_bytes = 0; public long num_overflow_rows = 0; public long num_rowsize_bytes = 0; public long min_rowsize_bytes = Long.MAX_VALUE; public long max_rowsize_bytes = Long.MIN_VALUE; } 58 59 public class D_HeapController extends DiagnosticableGeneric 60 { 61 62 private static void diag_page( 63 Page page, 64 Properties prop, 65 TableStats stat) 66 throws StandardException 67 { 68 stat.num_pages++; 69 stat.num_entries += page.recordCount(); 70 stat.num_deleted += 71 (page.recordCount() - page.nonDeletedRecordCount()); 72 stat.max_pageno = Math.max(stat.max_pageno, page.getPageNumber()); 73 74 DiagnosticUtil.findDiagnostic(page).diag_detail(prop); 75 76 int free_bytes = 78 Integer.parseInt(prop.getProperty(Page.DIAG_BYTES_FREE)); 79 80 stat.num_free_bytes += free_bytes; 81 82 int res_bytes = 84 Integer.parseInt(prop.getProperty(Page.DIAG_BYTES_RESERVED)); 85 86 stat.num_res_bytes += res_bytes; 87 88 int overflow = 90 Integer.parseInt(prop.getProperty(Page.DIAG_NUMOVERFLOWED)); 91 92 stat.num_overflow_rows += overflow; 93 94 int rowsize = 96 Integer.parseInt(prop.getProperty(Page.DIAG_ROWSIZE)); 97 98 stat.num_rowsize_bytes += rowsize; 99 100 int min_rowsize = 102 Integer.parseInt(prop.getProperty(Page.DIAG_MINROWSIZE)); 103 104 if (min_rowsize != 0) 105 stat.min_rowsize_bytes = 106 Math.min(stat.min_rowsize_bytes, min_rowsize); 107 108 int max_rowsize = 110 Integer.parseInt(prop.getProperty(Page.DIAG_MAXROWSIZE)); 111 112 stat.max_rowsize_bytes = Math.max(stat.max_rowsize_bytes, max_rowsize); 113 } 114 115 private static String out_summary( 116 String hdr, 117 long value, 118 double ratio, 119 String ratio_desc) 120 { 121 String double_str = "" + ratio; 122 String short_str; 123 124 if (ratio > 0.001) 125 { 126 short_str = double_str.substring( 127 0, 128 Math.min(double_str.lastIndexOf(".") + 3, double_str.length())); 129 } 130 else 131 { 132 short_str = "NA"; 133 } 134 135 return( 136 "\t" + hdr + value + ".\t(" + short_str + 137 " " + ratio_desc + ").\n"); 138 } 139 140 141 private static String diag_tabulate( 142 Properties prop, 143 TableStats stat) 144 { 145 String ret_string = new String (); 146 147 ret_string += 149 "Heap conglom has:\n" + 150 "\t" + prop.getProperty(Page.DIAG_PAGE_SIZE) + " bytes per page\n" + 151 "\t" + stat.num_pages + " total used pages (" + 152 (Integer.parseInt(prop.getProperty(Page.DIAG_PAGE_SIZE)) * 153 stat.num_pages) + 154 " bytes)\n" + 155 "\tmaximum page number = " + stat.max_pageno + ".\n" + 156 "\treserved space % = " + prop.getProperty(Page.DIAG_RESERVED_SPACE) + "%.\n" + 157 "\tminimum record size = " + prop.getProperty(Page.DIAG_MINIMUM_REC_SIZE) + ".\n" + 158 "\tminimum record length = " + stat.min_rowsize_bytes + ".\n" + 159 "\tmaximum record length = " + stat.max_rowsize_bytes + ".\n" + 160 "\t# of bytes in rows = " + stat.num_rowsize_bytes + "." + 161 "\t(" + 162 (stat.num_entries == 0 ? 163 0 : (stat.num_rowsize_bytes / stat.num_entries)) + 164 " bytes/row).\n" + 165 out_summary( 166 "# of reserved bytes = ", 167 stat.num_res_bytes, 168 (stat.num_res_bytes / stat.num_pages), 169 "reserved bytes/page") + 170 out_summary( 171 "# of free bytes = ", 172 stat.num_free_bytes, 173 (stat.num_free_bytes / stat.num_pages), 174 "free bytes/page") + 175 out_summary( 176 "# of total records = ", 177 stat.num_entries, 178 (((double) stat.num_entries) / stat.num_pages), 179 "records/page") + 180 out_summary( 181 "# of overflow records = ", 182 stat.num_overflow_rows, 183 (((double) stat.num_overflow_rows) / stat.num_pages), 184 "overflow records/page") + 185 out_summary( 186 "# of deleted records = ", 187 stat.num_deleted, 188 (((double) stat.num_deleted) / stat.num_pages), 189 "deleted records/page"); 190 191 return(ret_string); 192 } 193 194 197 public void init(Object obj) 198 { 199 if (SanityManager.DEBUG) 200 SanityManager.ASSERT(obj instanceof HeapController); 201 202 super.init(obj); 203 } 204 205 206 220 public String diag() 221 throws StandardException 222 { 223 long pageid; 224 ContainerHandle container = 225 ((HeapController) this.diag_object).getOpenConglom().getContainer(); 226 227 TableStats stat = new TableStats(); 228 229 Properties prop = new Properties (); 231 prop.put(Page.DIAG_PAGE_SIZE, ""); 232 prop.put(Page.DIAG_BYTES_FREE, ""); 233 prop.put(Page.DIAG_BYTES_RESERVED, ""); 234 prop.put(Page.DIAG_RESERVED_SPACE, ""); 235 prop.put(Page.DIAG_MINIMUM_REC_SIZE, ""); 236 prop.put(Page.DIAG_NUMOVERFLOWED, ""); 237 prop.put(Page.DIAG_ROWSIZE, ""); 238 prop.put(Page.DIAG_MINROWSIZE, ""); 239 prop.put(Page.DIAG_MAXROWSIZE, ""); 240 241 Page page = container.getFirstPage(); 243 244 while (page != null) 245 { 246 this.diag_page(page, prop, stat); 247 pageid = page.getPageNumber(); 248 page.unlatch(); 249 page = container.getNextPage(pageid); 250 } 251 252 return(this.diag_tabulate(prop, stat)); 253 } 254 } 255 | Popular Tags |