Skip to content

Instantly share code, notes, and snippets.

@shijinkui
Created January 24, 2017 09:28
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 shijinkui/5232c28ab6fef577fcc22d300cd601c6 to your computer and use it in GitHub Desktop.
Save shijinkui/5232c28ab6fef577fcc22d300cd601c6 to your computer and use it in GitHub Desktop.
package utils
import scala.io.Source
/**
* parse jstack log
*/
object JavaStackParser {
def main(args: Array[String]): Unit = {
val lines = Source.fromFile("/Users/sjk/19229.log").getLines()
val ret = convertHashId(lines)
println(ret.mkString("\n"))
// println(convertHashId(Iterator("C2 CompilerThread0 daemon prio=5 tid=0x00007fb428816800 nid=0x4b03 waiting on condition [0x0000000000000000]")).mkString("\n"))
}
def convertHashId(it: Iterator[String]): Array[String] = {
it.toArray.map(f => if (f.contains("0x")) {
// println(f)
f.split("0x").zipWithIndex.map(x => {
if (x._2 > 0) {
x._1.toCharArray.zipWithIndex.find(f => {
f._1 == '>' || f._1 == ')' || f._1 == ']' || f._1 == 32
}) match {
case Some((_, idx)) =>
java.lang.Long.decode("0x" + x._1.substring(0, idx)) + x._1.substring(idx)
case None =>
x._1
}
} else x._1
}).mkString
} else {
f
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment