提交 f8743f49 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved ThreaDumpFilter tool

上级 c82444f4
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
*/ */
package org.h2.dev.util; package org.h2.dev.util;
import java.io.InputStreamReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.PrintWriter;
/** /**
* Filter full thread dumps from a log file. * Filter full thread dumps from a log file.
...@@ -15,14 +19,19 @@ public class ThreadDumpFilter { ...@@ -15,14 +19,19 @@ public class ThreadDumpFilter {
/** /**
* Usage: java ThreadDumpFilter <log.txt >threadDump.txt * Usage: java ThreadDumpFilter <log.txt >threadDump.txt
* @param a ignored *
* @param a the file name
*/ */
public static void main(String... a) throws Exception { public static void main(String... a) throws Exception {
LineNumberReader in = new LineNumberReader(new InputStreamReader(System.in)); String fileName = a[0];
LineNumberReader in = new LineNumberReader(
new BufferedReader(new FileReader(fileName)));
PrintWriter writer = new PrintWriter(new BufferedWriter(
new FileWriter(fileName + ".filtered.txt")));
for (String s; (s = in.readLine()) != null;) { for (String s; (s = in.readLine()) != null;) {
if (s.startsWith("Full thread")) { if (s.startsWith("Full thread")) {
do { do {
System.out.println(s); writer.println(s);
s = in.readLine(); s = in.readLine();
} while(s != null && (s.length() == 0 || " \t\"".indexOf(s.charAt(0)) >= 0)); } while(s != null && (s.length() == 0 || " \t\"".indexOf(s.charAt(0)) >= 0));
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论