Created
January 24, 2017 09:28
-
-
Save shijinkui/5232c28ab6fef577fcc22d300cd601c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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