Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ongoing effort to parse stack dumps generated e.g. by jstack or the JVM directly
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.