in src/main/kotlin/org/jetbrains/tinygoplugin/heapAllocations/TinyGoHeapAlloc.kt [21:53]
suspend fun supplyHeapAllocsFromOutput(module: Module, processOutput: String): Map<String, Set<TinyGoHeapAlloc>> {
val result = mutableMapOf<String, MutableSet<TinyGoHeapAlloc>>()
val heapAllocRegex = Regex("(/.+/+.+.go):([0-9]+):([0-9]+): (.+)")
val matches = heapAllocRegex.findAll(processOutput)
val tinyGoSettings = module.project.tinyGoConfiguration()
val tinyGoSdkRoot = tinyGoSettings.sdk.sdkRoot!!
for (match in matches) {
val file = readAction {
var f = VfsUtil.findFile(File(match.groupValues[1]).toPath(), false)!!
if (VfsUtil.isAncestor(tinyGoSdkRoot, f, false)) {
val relativePath = VfsUtil.getRelativePath(f, tinyGoSdkRoot)
if (relativePath != null) {
f = tinyGoSettings.cachedGoRoot.sdkRoot?.findFileByRelativePath(relativePath)!!
}
}
f
}
val parentDir = file.parent.canonicalPath!!
result.putIfAbsent(parentDir, mutableSetOf())
result[parentDir]?.add(
@Suppress("MagicNumber")
TinyGoHeapAlloc(
file,
match.groupValues[2].toInt(),
match.groupValues[3].toInt(),
match.groupValues[4]
)
)
}
return result
}