override fun extract()

in src/main/kotlin/com/github/mkartashev/hserr/miner/artifact/JavaHeap.kt [32:57]


    override fun extract(log: HsErrLog): JavaHeapArtifact {
        val heapSelection = log.start
            .moveToLineStartsWithString("Heap address: ").selectUpToEOL()
        if (heapSelection.isEmpty()) fail("Couldn't find Heap address information")

        // Heap address: 0x0000000080000000, size: 2048 MB, Compressed Oops mode: 32-bit
        val heapLine = heapSelection.toString()
        val addressStr = heapLine.substringAfter("Heap address: ", "").substringBefore(',')
        val address = ArtifactExtractor.parseAddr(addressStr) ?: fail("Heap address is not a number")

        val sizeStr = heapLine.substringAfter("size: ", "").substringBefore(',')
        val size = parseMemorySize(sizeStr) ?: fail("Couldn't parse heap size")

        val heapSelection2 = log.start.moveToLineStartsWithString("Heap:").selectUpToFirstEmptyLine()
        var used = Artifact.DEFAULT_ULONG
        if (!heapSelection2.isEmpty()) {
            // garbage-first heap   total 1328128K, used 388956K [0x0000000080000000, 0x0000000100000000)
            val line = heapSelection2.toString().substringAfter("garbage-first heap", "").substringBefore('[')
            used = parseMemorySize(line.substringAfter("used ").trim()) ?: fail("Couldn't parse heap used size")
        }

        val locations = mutableSetOf(heapSelection)
        if (!heapSelection2.isEmpty()) locations.add(heapSelection2)

        return JavaHeapArtifact(log, locations, address, size, used)
    }