Write snapshot by chunks in ProfilingCompilerPerformanceManager.dumpProfile
To prevent OutOfMemoryError from converting the whole string to byte array, in case the snapshot is very big (see KT-51058). Also, remove 'framebuf' option from -Xprofile help, since async-profiler 2.0+ has unlimited frame buffer.
This commit is contained in:
+8
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.cli.common.profiling
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
@@ -43,7 +44,12 @@ class ProfilingCompilerPerformanceManager(
|
||||
private fun dumpProfile(postfix: String) {
|
||||
outputDir.mkdirs()
|
||||
val outputFile = outputDir.resolve("snapshot-${formatter.format(runDate)}-$postfix.collapsed")
|
||||
outputFile.writeText(profiler.execute("collapsed"))
|
||||
val profile = profiler.execute("collapsed")
|
||||
FileOutputStream(outputFile).use { out ->
|
||||
for (chunk in profile.chunkedSequence(1 shl 20)) {
|
||||
out.write(chunk.toByteArray(Charsets.UTF_8))
|
||||
}
|
||||
}
|
||||
active = false
|
||||
}
|
||||
|
||||
@@ -63,4 +69,4 @@ class ProfilingCompilerPerformanceManager(
|
||||
return ProfilingCompilerPerformanceManager(path, command, File(outputDir))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user