From: <tho...@us...> - 2011-03-17 14:40:00
|
Revision: 4307 http://bigdata.svn.sourceforge.net/bigdata/?rev=4307&view=rev Author: thompsonbry Date: 2011-03-17 14:39:53 +0000 (Thu, 17 Mar 2011) Log Message: ----------- Corrected some inconsistencies in DumpJournal and DumpIndex with respect to gathering and reporting the PageStats for an index. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/btree/DumpIndex.java branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/DumpJournal.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/btree/DumpIndex.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/btree/DumpIndex.java 2011-03-17 12:34:36 UTC (rev 4306) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/btree/DumpIndex.java 2011-03-17 14:39:53 UTC (rev 4307) @@ -93,24 +93,25 @@ * @param dumpNodeState * When <code>true</code>, provide gruesome detail on each * visited page. + * + * @return Some interesting statistics about the pages in that index which + * the caller can print out. */ - public static void dumpPages(final AbstractBTree ndx, + public static PageStats dumpPages(final AbstractBTree ndx, final boolean dumpNodeState) { final PageStats stats = new PageStats(); dumpPages(ndx, ndx.getRoot(), stats, dumpNodeState); - System.out.println("name=" + ndx.getIndexMetadata().getName() + " : " - + stats); + return stats; } - - /* - * FIXME report the min/max page size as well and report as a nice table in - * DumpJournal. + + /** + * Class reports various summary statistics for nodes and leaves. */ - static class PageStats { + public static class PageStats { /** The #of nodes visited. */ public long nnodes; @@ -120,16 +121,39 @@ public long nodeBytes; /** The #of bytes in the raw records for the leaves visited. */ public long leafBytes; + /** The min/max bytes per node. */ + public long minNodeBytes, maxNodeBytes; + /** The min/max bytes per leaf. */ + public long minLeafBytes, maxLeafBytes; + /** Return {@link #nodeBytes} plus {@link #leafBytes}. */ + public long getTotalBytes() { + return nodeBytes + leafBytes; + } + + /** The average bytes per node. */ + public long getBytesPerNode() { + return (nnodes == 0 ? 0 : nodeBytes / nnodes); + } + + /** The average bytes per leaf. */ + public long getBytesPerLeaf() { + return (nleaves == 0 ? 0 : leafBytes / nleaves); + } + public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(getClass().getName()); - sb.append("{nnodes="+nnodes); - sb.append(",nleaves="+nleaves); - sb.append(",nodeBytes="+nodeBytes); - sb.append(",leafBytes="+leafBytes); - sb.append(",bytesPerNode="+(nnodes==0?0:nodeBytes/nnodes)); - sb.append(",bytesPerLeaf="+(nleaves==0?0:leafBytes/nleaves)); + sb.append("{nnodes=" + nnodes); + sb.append(",nleaves=" + nleaves); + sb.append(",nodeBytes=" + nodeBytes); + sb.append(",minNodeBytes=" + minNodeBytes); + sb.append(",maxNodeBytes=" + maxNodeBytes); + sb.append(",leafBytes=" + leafBytes); + sb.append(",minLeafBytes=" + minLeafBytes); + sb.append(",maxLeafBytes=" + maxLeafBytes); + sb.append(",bytesPerNode=" + getBytesPerNode()); + sb.append(",bytesPerLeaf=" + getBytesPerLeaf()); sb.append("}"); return sb.toString(); } @@ -153,11 +177,19 @@ stats.nleaves++; stats.leafBytes += nbytes; + if (stats.minLeafBytes > nbytes || stats.minLeafBytes == 0) + stats.minLeafBytes = nbytes; + if (stats.maxLeafBytes < nbytes) + stats.maxLeafBytes = nbytes; } else { stats.nnodes++; stats.nodeBytes += nbytes; + if (stats.minNodeBytes > nbytes || stats.minNodeBytes == 0) + stats.minNodeBytes = nbytes; + if (stats.maxNodeBytes < nbytes) + stats.maxNodeBytes = nbytes; final int nkeys = node.getKeyCount(); Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/DumpJournal.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/DumpJournal.java 2011-03-17 12:34:36 UTC (rev 4306) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/java/com/bigdata/journal/DumpJournal.java 2011-03-17 14:39:53 UTC (rev 4307) @@ -29,7 +29,9 @@ import java.io.File; import java.util.Date; +import java.util.Map; import java.util.Properties; +import java.util.TreeMap; import org.apache.log4j.Logger; @@ -37,6 +39,7 @@ import com.bigdata.btree.DumpIndex; import com.bigdata.btree.IIndex; import com.bigdata.btree.ITupleIterator; +import com.bigdata.btree.DumpIndex.PageStats; import com.bigdata.rawstore.Bytes; import com.bigdata.util.InnerCause; @@ -260,10 +263,10 @@ System.out.println("Historical commit points follow in temporal sequence (first to last):"); - CommitRecordIndex commitRecordIndex = journal.getCommitRecordIndex(); + final CommitRecordIndex commitRecordIndex = journal.getCommitRecordIndex(); // CommitRecordIndex commitRecordIndex = journal._commitRecordIndex; - ITupleIterator<CommitRecordIndex.Entry> itr = commitRecordIndex.rangeIterator(); + final ITupleIterator<CommitRecordIndex.Entry> itr = commitRecordIndex.rangeIterator(); while(itr.hasNext()) { @@ -311,14 +314,17 @@ * @param journal * @param commitRecord */ - private static void dumpNamedIndicesMetadata(AbstractJournal journal, - ICommitRecord commitRecord, boolean dumpPages, boolean dumpIndices, boolean showTuples) { + private static void dumpNamedIndicesMetadata(AbstractJournal journal, + ICommitRecord commitRecord, boolean dumpPages, boolean dumpIndices, boolean showTuples) { // view as of that commit record. final IIndex name2Addr = journal.getName2Addr(commitRecord.getTimestamp()); final ITupleIterator itr = name2Addr.rangeIterator(null,null); - + + final Map<String, PageStats> pageStats = dumpPages ? new TreeMap<String, PageStats>() + : null; + while (itr.hasNext()) { // a registered index. @@ -362,14 +368,100 @@ // show metadata record. System.out.println("\t" + ndx.getIndexMetadata()); - if (dumpPages) - DumpIndex.dumpPages(ndx, false/* dumpNodeState */); + if (pageStats != null) { + + final PageStats stats = DumpIndex + .dumpPages(ndx, false/* dumpNodeState */); + System.out.println("\t" + stats); + + pageStats.put(entry.name, stats); + + } + if (dumpIndices) DumpIndex.dumpIndex(ndx, showTuples); } + + if (pageStats != null) { + + /* + * TODO If we kept the BTree counters for the #of bytes written per + * node and per leaf up to date when nodes and leaves were recycled + * then we could generate this table very quickly. As it stands, we + * have to actually scan the pages in the index. + */ + System.out.print("name"); + System.out.print('\t'); + System.out.print("m"); + System.out.print('\t'); + System.out.print("height"); + System.out.print('\t'); + System.out.print("nnodes"); + System.out.print('\t'); + System.out.print("nleaves"); + System.out.print('\t'); + System.out.print("nodeBytes"); + System.out.print('\t'); + System.out.print("leafBytes"); + System.out.print('\t'); + System.out.print("totalBytes"); + System.out.print('\t'); + System.out.print("avgNodeBytes"); + System.out.print('\t'); + System.out.print("avgLeafBytes"); + System.out.print('\t'); + System.out.print("minNodeBytes"); + System.out.print('\t'); + System.out.print("maxNodeBytes"); + System.out.print('\t'); + System.out.print("minLeafBytes"); + System.out.print('\t'); + System.out.print("maxLeafBytes"); + System.out.print('\n'); + + for(Map.Entry<String,PageStats> e : pageStats.entrySet()) { + + final String name = e.getKey(); + + final PageStats stats = e.getValue(); + + final BTree ndx = (BTree) journal.getIndex(name, commitRecord); + + System.out.print(name); + System.out.print('\t'); + System.out.print(ndx.getBranchingFactor()); + System.out.print('\t'); + System.out.print(ndx.getHeight()); + System.out.print('\t'); + System.out.print(ndx.getNodeCount()); + System.out.print('\t'); + System.out.print(ndx.getLeafCount()); + System.out.print('\t'); + System.out.print(stats.nodeBytes); + System.out.print('\t'); + System.out.print(stats.leafBytes); + System.out.print('\t'); + System.out.print(stats.getTotalBytes()); + System.out.print('\t'); + System.out.print(stats.getBytesPerNode()); + System.out.print('\t'); + System.out.print(stats.getBytesPerLeaf()); + System.out.print('\t'); + System.out.print(stats.minNodeBytes); + System.out.print('\t'); + System.out.print(stats.maxNodeBytes); + System.out.print('\t'); + System.out.print(stats.minLeafBytes); + System.out.print('\t'); + System.out.print(stats.maxLeafBytes); + System.out.print('\n'); + + } + + } - } + } // dumpNamedIndicesMetadata } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |