in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/Thread.kt [189:243]
override fun extract(log: HsErrLog): ThreadInfoArtifact {
val threadSectionStart = log.start.moveToLineStartsWithString("--------------- T H R E A D")
if (!threadSectionStart.isValid()) fail("Couldn't find THREAD section marker")
val currentThreadLine = threadSectionStart.moveToLineStartsWithString("Current thread").selectUpToEOL()
if (currentThreadLine.isEmpty()) fail("Couldn't locate info about the current thread")
val isThreadNative = currentThreadLine.toString().startsWith("Current thread is native thread")
var threadName = ""
if (!isThreadNative) {
val threadNameSelection =
currentThreadLine.start.moveToNextWord().moveToNextWord().moveToNextWord().moveToNextWord()
.selectQuotedString(false)
threadName = threadNameSelection.toString()
}
val compileTaskLine = threadSectionStart.moveToLineStartsWithString("Current CompileTask:")
val isCompilerThread = compileTaskLine.isValid()
var methodBeingCompiled = ""
if (isCompilerThread) {
val tokens = log.lineAsTokens(compileTaskLine.moveToNextLine())
if (tokens.size > 3) {
val methodSelection = tokens[tokens.lastIndex - 2]
methodBeingCompiled = methodSelection.toString()
}
}
val stackStart = threadSectionStart.moveToLineStartsWithString("Stack: ")
var stackEnd = stackStart
var emptyLinesCount = 0
while (stackEnd.isValid() && !stackEnd.isAtEnd() && emptyLinesCount < 2) {
stackEnd = stackEnd.moveToNextLine()
val currentLine = stackEnd.selectUpToEOL()
if (currentLine.toString().isBlank()) emptyLinesCount += 1 else emptyLinesCount = 0
}
if (!stackEnd.isValid()) stackEnd = log.end
val stackSelection = stackStart.selectUpTo(stackEnd)
val frameLines = stackSelection.toString().lines().filter {
val c = if (it.isEmpty()) ' ' else it[0]
when (c) {
'v', 'V', 'j', 'J', 'C', 'A' -> it.length > 2 && it[1].isWhitespace()
else -> false
}
}
if (frameLines.isEmpty()) fail("No frames in stack")
val sel = threadSectionStart.selectUpTo(stackEnd)
return ThreadInfoArtifact(
log, sel, threadName, Stack(frameLines),
isThreadNative, isCompilerThread, methodBeingCompiled
)
}