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:
+1
-1
@@ -446,7 +446,7 @@ Also sets `-jvm-target` value equal to the selected JDK version"""
|
|||||||
description = "Debug option: Run compiler with async profiler and save snapshots to `outputDir`; `command` is passed to async-profiler on start.\n" +
|
description = "Debug option: Run compiler with async profiler and save snapshots to `outputDir`; `command` is passed to async-profiler on start.\n" +
|
||||||
"`profilerPath` is a path to libasyncProfiler.so; async-profiler.jar should be on the compiler classpath.\n" +
|
"`profilerPath` is a path to libasyncProfiler.so; async-profiler.jar should be on the compiler classpath.\n" +
|
||||||
"If it's not on the classpath, the compiler will attempt to load async-profiler.jar from the containing directory of profilerPath.\n" +
|
"If it's not on the classpath, the compiler will attempt to load async-profiler.jar from the containing directory of profilerPath.\n" +
|
||||||
"Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000:<SNAPSHOT_DIR_PATH>"
|
"Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start:<SNAPSHOT_DIR_PATH>"
|
||||||
)
|
)
|
||||||
var profileCompilerCommand: String? by NullableStringFreezableVar(null)
|
var profileCompilerCommand: String? by NullableStringFreezableVar(null)
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.cli.common.profiling
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
import org.jetbrains.kotlin.cli.common.CommonCompilerPerformanceManager
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.FileOutputStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -43,7 +44,12 @@ class ProfilingCompilerPerformanceManager(
|
|||||||
private fun dumpProfile(postfix: String) {
|
private fun dumpProfile(postfix: String) {
|
||||||
outputDir.mkdirs()
|
outputDir.mkdirs()
|
||||||
val outputFile = outputDir.resolve("snapshot-${formatter.format(runDate)}-$postfix.collapsed")
|
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
|
active = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,4 +69,4 @@ class ProfilingCompilerPerformanceManager(
|
|||||||
return ProfilingCompilerPerformanceManager(path, command, File(outputDir))
|
return ProfilingCompilerPerformanceManager(path, command, File(outputDir))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -106,7 +106,7 @@ where advanced options include:
|
|||||||
Debug option: Run compiler with async profiler and save snapshots to `outputDir`; `command` is passed to async-profiler on start.
|
Debug option: Run compiler with async profiler and save snapshots to `outputDir`; `command` is passed to async-profiler on start.
|
||||||
`profilerPath` is a path to libasyncProfiler.so; async-profiler.jar should be on the compiler classpath.
|
`profilerPath` is a path to libasyncProfiler.so; async-profiler.jar should be on the compiler classpath.
|
||||||
If it's not on the classpath, the compiler will attempt to load async-profiler.jar from the containing directory of profilerPath.
|
If it's not on the classpath, the compiler will attempt to load async-profiler.jar from the containing directory of profilerPath.
|
||||||
Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start,framebuf=50000000:<SNAPSHOT_DIR_PATH>
|
Example: -Xprofile=<PATH_TO_ASYNC_PROFILER>/async-profiler/build/libasyncProfiler.so:event=cpu,interval=1ms,threads,start:<SNAPSHOT_DIR_PATH>
|
||||||
-Xrepeat=<number> Debug option: Repeats modules compilation <number> times
|
-Xrepeat=<number> Debug option: Repeats modules compilation <number> times
|
||||||
-Xsam-conversions={class|indy} Select code generation scheme for SAM conversions.
|
-Xsam-conversions={class|indy} Select code generation scheme for SAM conversions.
|
||||||
-Xsam-conversions=indy Generate SAM conversions using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 1.8` or greater.
|
-Xsam-conversions=indy Generate SAM conversions using `invokedynamic` with `LambdaMetafactory.metafactory`. Requires `-jvm-target 1.8` or greater.
|
||||||
|
|||||||
Reference in New Issue
Block a user