提交 4b982f97 authored 作者: Thomas Mueller's avatar Thomas Mueller

MVStore tool: improved output

上级 6fa15ff8
...@@ -47,7 +47,7 @@ public class MVStoreTool { ...@@ -47,7 +47,7 @@ public class MVStoreTool {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if ("-dump".equals(args[i])) { if ("-dump".equals(args[i])) {
String fileName = args[++i]; String fileName = args[++i];
dump(fileName, new PrintWriter(System.out)); dump(fileName, new PrintWriter(System.out), true);
} else if ("-info".equals(args[i])) { } else if ("-info".equals(args[i])) {
String fileName = args[++i]; String fileName = args[++i];
info(fileName, new PrintWriter(System.out)); info(fileName, new PrintWriter(System.out));
...@@ -65,9 +65,10 @@ public class MVStoreTool { ...@@ -65,9 +65,10 @@ public class MVStoreTool {
* Read the contents of the file and write them to system out. * Read the contents of the file and write them to system out.
* *
* @param fileName the name of the file * @param fileName the name of the file
* @param details whether to print details
*/ */
public static void dump(String fileName) { public static void dump(String fileName, boolean details) {
dump(fileName, new PrintWriter(System.out)); dump(fileName, new PrintWriter(System.out), details);
} }
/** /**
...@@ -86,7 +87,7 @@ public class MVStoreTool { ...@@ -86,7 +87,7 @@ public class MVStoreTool {
* @param fileName the name of the file * @param fileName the name of the file
* @param writer the print writer * @param writer the print writer
*/ */
public static void dump(String fileName, Writer writer) { public static void dump(String fileName, Writer writer, boolean details) {
PrintWriter pw = new PrintWriter(writer, true); PrintWriter pw = new PrintWriter(writer, true);
if (!FilePath.get(fileName).exists()) { if (!FilePath.get(fileName).exists()) {
pw.println("File not found: " + fileName); pw.println("File not found: " + fileName);
...@@ -96,11 +97,15 @@ public class MVStoreTool { ...@@ -96,11 +97,15 @@ public class MVStoreTool {
pw.printf("File %s, %d bytes, %d MB\n", fileName, size, size / 1024 / 1024); pw.printf("File %s, %d bytes, %d MB\n", fileName, size, size / 1024 / 1024);
FileChannel file = null; FileChannel file = null;
int blockSize = MVStore.BLOCK_SIZE; int blockSize = MVStore.BLOCK_SIZE;
TreeMap<Integer, Long> mapSizesTotal =
new TreeMap<Integer, Long>();
long pageSizeTotal = 0;
try { try {
file = FilePath.get(fileName).open("r"); file = FilePath.get(fileName).open("r");
long fileSize = file.size(); long fileSize = file.size();
int len = Long.toHexString(fileSize).length(); int len = Long.toHexString(fileSize).length();
ByteBuffer block = ByteBuffer.allocate(4096); ByteBuffer block = ByteBuffer.allocate(4096);
long pageCount = 0;
for (long pos = 0; pos < fileSize;) { for (long pos = 0; pos < fileSize;) {
block.rewind(); block.rewind();
DataUtils.readFully(file, pos, block); DataUtils.readFully(file, pos, block);
...@@ -133,8 +138,10 @@ public class MVStoreTool { ...@@ -133,8 +138,10 @@ public class MVStoreTool {
int p = block.position(); int p = block.position();
pos += length; pos += length;
int remaining = c.pageCount; int remaining = c.pageCount;
TreeMap<Integer, Integer> mapSizes = new TreeMap<Integer, Integer>(); pageCount += c.pageCount;
int totalSize = 0; TreeMap<Integer, Integer> mapSizes =
new TreeMap<Integer, Integer>();
int pageSizeSum = 0;
while (remaining > 0) { while (remaining > 0) {
try { try {
chunk.position(p); chunk.position(p);
...@@ -151,6 +158,7 @@ public class MVStoreTool { ...@@ -151,6 +158,7 @@ public class MVStoreTool {
int type = chunk.get(); int type = chunk.get();
boolean compressed = (type & 2) != 0; boolean compressed = (type & 2) != 0;
boolean node = (type & 1) != 0; boolean node = (type & 1) != 0;
if (details) {
pw.printf( pw.printf(
"+%0" + len + "+%0" + len +
"x %s, map %x, %d entries, %d bytes, maxLen %x%n", "x %s, map %x, %d entries, %d bytes, maxLen %x%n",
...@@ -162,13 +170,20 @@ public class MVStoreTool { ...@@ -162,13 +170,20 @@ public class MVStoreTool {
pageSize, pageSize,
DataUtils.getPageMaxLength(DataUtils.getPagePos(0, 0, pageSize, 0)) DataUtils.getPageMaxLength(DataUtils.getPagePos(0, 0, pageSize, 0))
); );
}
p += pageSize; p += pageSize;
Integer mapSize = mapSizes.get(mapId); Integer mapSize = mapSizes.get(mapId);
if (mapSize == null) { if (mapSize == null) {
mapSize = 0; mapSize = 0;
} }
mapSizes.put(mapId, mapSize + pageSize); mapSizes.put(mapId, mapSize + pageSize);
totalSize += pageSize; Long total = mapSizesTotal.get(mapId);
if (total == null) {
total = 0L;
}
mapSizesTotal.put(mapId, total + pageSize);
pageSizeSum += pageSize;
pageSizeTotal += pageSize;
remaining--; remaining--;
long[] children = null; long[] children = null;
long[] counts = null; long[] counts = null;
...@@ -184,7 +199,7 @@ public class MVStoreTool { ...@@ -184,7 +199,7 @@ public class MVStoreTool {
} }
} }
String[] keys = new String[entries]; String[] keys = new String[entries];
if (mapId == 0) { if (mapId == 0 && details) {
if (!compressed) { if (!compressed) {
for (int i = 0; i < entries; i++) { for (int i = 0; i < entries; i++) {
String k = StringDataType.INSTANCE.read(chunk); String k = StringDataType.INSTANCE.read(chunk);
...@@ -223,7 +238,7 @@ public class MVStoreTool { ...@@ -223,7 +238,7 @@ public class MVStoreTool {
} }
} }
} else { } else {
if (node) { if (node && details) {
for (int i = 0; i <= entries; i++) { for (int i = 0; i <= entries; i++) {
long cp = children[i]; long cp = children[i];
pw.printf(" %d children @ chunk %x +%0" + pw.printf(" %d children @ chunk %x +%0" +
...@@ -236,8 +251,8 @@ public class MVStoreTool { ...@@ -236,8 +251,8 @@ public class MVStoreTool {
} }
} }
for (Integer mapId : mapSizes.keySet()) { for (Integer mapId : mapSizes.keySet()) {
int percent = 100 * mapSizes.get(mapId) / totalSize; int percent = 100 * mapSizes.get(mapId) / pageSizeSum;
pw.printf("map %x: %d%%%n", mapId, percent); pw.printf("map %x: %d bytes, %d%%%n", mapId, mapSizes.get(mapId), percent);
} }
int footerPos = chunk.limit() - Chunk.FOOTER_LENGTH; int footerPos = chunk.limit() - Chunk.FOOTER_LENGTH;
try { try {
...@@ -254,6 +269,12 @@ public class MVStoreTool { ...@@ -254,6 +269,12 @@ public class MVStoreTool {
} }
pw.printf("%n%0" + len + "x eof%n", fileSize); pw.printf("%n%0" + len + "x eof%n", fileSize);
pw.printf("\n"); pw.printf("\n");
pw.printf("page size total: %d bytes, page count: %d, average page size: %d bytes\n",
pageSizeTotal, pageCount, pageSizeTotal / pageCount);
for (Integer mapId : mapSizesTotal.keySet()) {
int percent = (int) (100 * mapSizesTotal.get(mapId) / pageSizeTotal);
pw.printf("map %x: %d bytes, %d%%%n", mapId, mapSizesTotal.get(mapId), percent);
}
} catch (IOException e) { } catch (IOException e) {
pw.println("ERROR: " + e); pw.println("ERROR: " + e);
e.printStackTrace(pw); e.printStackTrace(pw);
......
...@@ -324,7 +324,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -324,7 +324,7 @@ public class Recover extends Tool implements DataHandler {
Constants.SUFFIX_PAGE_FILE.length()); Constants.SUFFIX_PAGE_FILE.length());
PrintWriter writer; PrintWriter writer;
writer = getWriter(fileName, ".txt"); writer = getWriter(fileName, ".txt");
MVStoreTool.dump(fileName, writer); MVStoreTool.dump(fileName, writer, true);
MVStoreTool.info(fileName, writer); MVStoreTool.info(fileName, writer);
writer.close(); writer.close();
writer = getWriter(f + ".h2.db", ".sql"); writer = getWriter(f + ".h2.db", ".sql");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论