Use new kotlin.io.path API in tests
This commit is contained in:
@@ -7,15 +7,16 @@ package org.jetbrains.kotlin.idea.perf.util
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.sun.management.HotSpotDiagnosticMXBean
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileOutputStream
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.zip.ZipEntry
|
||||
import java.util.zip.ZipOutputStream
|
||||
import kotlin.io.path.*
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
object HeapDumper {
|
||||
private const val HOTSPOT_BEAN_NAME = "com.sun.management:type=HotSpotDiagnostic"
|
||||
|
||||
@@ -30,15 +31,15 @@ object HeapDumper {
|
||||
fun dumpHeap(fileNamePrefix: String, live: Boolean = true) {
|
||||
val format = SimpleDateFormat("yyyyMMdd-HHmmss")
|
||||
val timestamp = format.format(Date())
|
||||
val tempFile = File.createTempFile(fileNamePrefix, ".hprof")
|
||||
tempFile.delete()
|
||||
val tempFile = createTempFile(fileNamePrefix, ".hprof")
|
||||
tempFile.deleteIfExists()
|
||||
val fileName = "build/$fileNamePrefix-$timestamp.hprof.zip"
|
||||
logMessage { "Dumping a heap into $tempFile ..." }
|
||||
try {
|
||||
hotspotMBean.dumpHeap(tempFile.toString(), live)
|
||||
logMessage { "Heap dump is $tempFile ready." }
|
||||
|
||||
zipFile(tempFile, File(fileName))
|
||||
zipFile(tempFile, Path(fileName))
|
||||
|
||||
val testName = "Heap dump $timestamp"
|
||||
TeamCity.test(testName) {
|
||||
@@ -50,9 +51,9 @@ object HeapDumper {
|
||||
}
|
||||
}
|
||||
|
||||
private fun zipFile(srcFile: File, targetFile: File) {
|
||||
FileInputStream(srcFile).use { fis ->
|
||||
ZipOutputStream(FileOutputStream(targetFile)).use { os ->
|
||||
private fun zipFile(srcFile: Path, targetFile: Path) {
|
||||
srcFile.inputStream().use { fis ->
|
||||
ZipOutputStream(targetFile.outputStream()).use { os ->
|
||||
os.putNextEntry(ZipEntry(srcFile.name))
|
||||
FileUtilRt.copy(fis, os)
|
||||
os.closeEntry()
|
||||
|
||||
Reference in New Issue
Block a user