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