Created
September 27, 2017 16:04
-
-
Save jrudolph/ca8128fa7f553b7592798bdced4c534a to your computer and use it in GitHub Desktop.
Ongoing effort to parse stack dumps generated e.g. by jstack or the JVM directly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File | |
import scala.io.Source | |
object StackDumpAnalyzer extends App { | |
val ThreadLine = """"([^"]+)" #(\d+) prio=(\d+) os_prio=(\d+) tid=0x([0-9a-f]+) nid=0x([0-9a-f]+) (.*)""".r | |
val file = "ThreadDump.txt" | |
case class ThreadState(name: String, id: Int, prio: Int, osPrio: Int, tid: Long, nid: Int, state: String) | |
val lines = Source.fromFile(new File(file)).getLines() | |
val threads = | |
lines.collect { | |
case ThreadLine(name, id, prio, osPrio, tid, nid, state) => | |
ThreadState(name, id.toInt, prio.toInt, osPrio.toInt, java.lang.Long.parseLong(tid, 16), java.lang.Integer.parseInt(nid, 16), state) | |
}.toSeq.sortBy(_.name) | |
println(threads.size) | |
threads.foreach(println) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment