Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Created September 27, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrudolph/ca8128fa7f553b7592798bdced4c534a to your computer and use it in GitHub Desktop.
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
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