Author: thomasm
Date: Wed Aug 17 13:39:17 2016
New Revision: 1756634
URL: http://svn.apache.org/viewvc?rev=1756634&view=rev
Log:
OAK-4521 Oak-run: add profiling and analysis tools (support alternative full
thread dump format)
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpConverter.java
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/ThreadDumpCommand.java
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpCleaner.java
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/ThreadDumpCommand.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/ThreadDumpCommand.java?rev=1756634&r1=1756633&r2=1756634&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/ThreadDumpCommand.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/ThreadDumpCommand.java
Wed Aug 17 13:39:17 2016
@@ -42,6 +42,7 @@ import joptsimple.OptionSpec;
import org.apache.jackrabbit.oak.benchmark.util.Profiler;
import org.apache.jackrabbit.oak.threadDump.ThreadDumpCleaner;
+import org.apache.jackrabbit.oak.threadDump.ThreadDumpConverter;
public class ThreadDumpCommand implements Command {
@@ -49,6 +50,8 @@ public class ThreadDumpCommand implement
@Override
public void execute(String... args) throws Exception {
OptionParser parser = new OptionParser();
+ OptionSpec<Void> convertSpec = parser.accepts("convert",
+ "convert the thread dumps to the standard format");
OptionSpec<Void> filterSpec = parser.accepts("filter",
"filter the thread dumps, only keep working threads");
OptionSpec<Void> profileSpec = parser.accepts("profile",
@@ -71,6 +74,7 @@ public class ThreadDumpCommand implement
parser.printHelpOn(System.out);
return;
}
+ boolean convert = options.has(convertSpec);
boolean filter = options.has(filterSpec);
boolean profile = options.has(profileSpec);
boolean profileClasses = options.has(profileClassesSpec);
@@ -82,6 +86,11 @@ public class ThreadDumpCommand implement
file = combineAndExpandFiles(file);
System.out.println("Combined into " + file.getAbsolutePath());
}
+ if (convert) {
+ file = ThreadDumpConverter.process(file);
+ System.out.println("Converted to " + file.getAbsolutePath());
+
+ }
if (filter) {
file = ThreadDumpCleaner.process(file);
System.out.println("Filtered into " + file.getAbsolutePath());
@@ -169,7 +178,7 @@ public class ThreadDumpCommand implement
if (s == null) {
break;
}
- if (s.startsWith("Full thread dump")) {
+ if (s.startsWith("Full thread dump") || s.startsWith("Full
Java thread dump")) {
fullThreadDumps++;
}
writer.println(s);
Modified:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpCleaner.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpCleaner.java?rev=1756634&r1=1756633&r2=1756634&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpCleaner.java
(original)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpCleaner.java
Wed Aug 17 13:39:17 2016
@@ -50,6 +50,8 @@ public class ThreadDumpCleaner {
" Locked ownable synchronizers:(?s).*?\n\n",
+ " Locked synchronizers:(?s).*?\n\n",
+
"\".*?\".*?\n java.lang.Thread.State: (TIMED_)?WAITING(?s).*?\n\n",
"\".*?\".*?\n java.lang.Thread.State:.*\n\t" +
Added:
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpConverter.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpConverter.java?rev=1756634&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpConverter.java
(added)
+++
jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/threadDump/ThreadDumpConverter.java
Wed Aug 17 13:39:17 2016
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.threadDump;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.LineNumberReader;
+import java.io.PrintWriter;
+
+/**
+ * A tool that converts full thread dumps files to the "standard" format.
+ */
+public class ThreadDumpConverter {
+
+ public static void main(String... args) throws IOException {
+ process(new File(args[0]));
+ }
+
+ public static File process(File file) throws IOException {
+ String fileName = file.getName();
+ if (fileName.endsWith(".txt")) {
+ fileName = fileName.substring(0, fileName.length() -
".txt".length());
+ }
+ File target = new File(file.getParentFile(), fileName +
".converted.txt");
+ PrintWriter writer = new PrintWriter(new BufferedWriter(
+ new FileWriter(target)));
+ try {
+ processFile(file, writer);
+ } finally {
+ writer.close();
+ }
+ return target;
+ }
+
+ private static void processFile(File file, PrintWriter writer) throws
IOException {
+ LineNumberReader r = new LineNumberReader(new BufferedReader(
+ new FileReader(file)));
+ try {
+ process(r, writer);
+ } finally {
+ r.close();
+ }
+ }
+
+ private static void process(LineNumberReader reader, PrintWriter writer)
throws IOException {
+ StringBuilder buff = new StringBuilder();
+ while (true) {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ }
+ if (line.startsWith(" at ")) {
+ line = "\t" + line.substring(4);
+ } else if (line.startsWith(" Locked synchronizers")) {
+ line = " " + line.substring(4);
+ } else if (line.startsWith(" - locked ")) {
+ line = "\t" + line.substring(4);
+ } else if (line.startsWith(" owned by ")) {
+ line = "\t" + line.substring(4);
+ }
+ buff.append(line).append('\n');
+ if (line.trim().length() == 0) {
+ writer.print(convert(buff.toString()));
+ buff = new StringBuilder();
+ }
+ }
+ writer.println(convert(buff.toString()));
+ }
+
+ private static String convert(String string) {
+ int endOfLine = string.indexOf('\n');
+ String firstLine;
+ if (endOfLine < 0) {
+ firstLine = string;
+ } else {
+ firstLine = string.substring(0, endOfLine);
+ }
+ if (!firstLine.startsWith("\"")) {
+ return string;
+ }
+ String remainingText = string.substring(endOfLine);
+ for (Thread.State state : Thread.State.values()) {
+ int index = firstLine.indexOf(" in " + state.toString());
+ if (index > 0) {
+ String stateName = firstLine.substring(index + 4,
+ index + 4 + state.toString().length());
+ firstLine = firstLine.substring(0, index) + "\n";
+ remainingText = " java.lang.Thread.State: "+ stateName +
+ remainingText;
+ }
+ }
+ return firstLine + remainingText;
+ }
+
+}