in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/Uptime.kt [39:61]
override fun extract(log: HsErrLog): UptimeArtifact {
val summary = log.getArtifact(SummaryArtifact::class) ?: fail("No Summary section found")
val uptimeStartLoc = summary.location.start.moveToString("elapsed time:").moveToNextWord().moveToNextWord()
val uptimeEndLoc = uptimeStartLoc.moveToWordEnd()
if (!uptimeEndLoc.isValid()) fail("failed to find 'elapsed time' in the summary")
val unitsStartLoc = uptimeEndLoc.moveToNextWord()
val unitsTextRange = TextRange.of(unitsStartLoc, unitsStartLoc.moveToWordEnd())
if (!unitsTextRange.toString().contains("seconds")) {
fail("failed to find the word 'seconds' following JVM uptime")
}
if (!summary.location.contains(uptimeEndLoc)) {
fail("elapsed time found outside of the summary")
}
val uptimeTextRange = TextRange.of(uptimeStartLoc, uptimeEndLoc)
val uptime =
uptimeTextRange.toString().trim().toDoubleOrNull() ?: fail("failed parsing uptime '$uptimeTextRange'")
return UptimeArtifact(log, uptimeTextRange, uptime.toInt())
}