From 996fd131d0ef5502774ddb6f2079bcafc259f168 Mon Sep 17 00:00:00 2001 From: "Maxim.Kolmakov" Date: Mon, 22 May 2023 18:08:34 +0200 Subject: [PATCH] Implement Capture Memory Snapshot action in Performance Plugin Make the original action from YourKit to capture memory snapshots only using YourKit format GitOrigin-RevId: 59b1411eb6effb41109f8d054f18154909925a7e --- .../resources/META-INF/plugin.xml | 1 + .../PerformanceTestingBundle.properties | 3 ++ .../actions/CaptureMemorySnapshotAction.kt | 36 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 plugins/performanceTesting/src/com/jetbrains/performancePlugin/actions/CaptureMemorySnapshotAction.kt diff --git a/plugins/performanceTesting/resources/META-INF/plugin.xml b/plugins/performanceTesting/resources/META-INF/plugin.xml index 504a186d471a..62dbd3449bb7 100644 --- a/plugins/performanceTesting/resources/META-INF/plugin.xml +++ b/plugins/performanceTesting/resources/META-INF/plugin.xml @@ -24,6 +24,7 @@ + diff --git a/plugins/performanceTesting/resources/messages/PerformanceTestingBundle.properties b/plugins/performanceTesting/resources/messages/PerformanceTestingBundle.properties index a28ff9dacf18..853940f7bf76 100644 --- a/plugins/performanceTesting/resources/messages/PerformanceTestingBundle.properties +++ b/plugins/performanceTesting/resources/messages/PerformanceTestingBundle.properties @@ -74,6 +74,9 @@ dumping.project.files=Dumping Project Files\u2026 comparing.project.files=Comparing Project Files\u2026 comparing.project.files.for.0=Comparing Project Files for {0}\u2026 +action.CaptureMemorySnapShot.text=Capture Memory Snapshot +action.CaptureMemorySnapShot.description=Capture memory snapshot + intention.add.stopcommand=Add `%stopProfile` command inspection.message.activity.started.but.never.closed.with.stopprofile=`{0}` activity started, but never closed with `%stopProfile` inspection.message.two.startprofile.commands.cant.follow.each.other=`%startProfile` commands can''t follow each other. Add `%stopProfile` before `{0}` diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/actions/CaptureMemorySnapshotAction.kt b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/actions/CaptureMemorySnapshotAction.kt new file mode 100644 index 000000000000..808aa41920e6 --- /dev/null +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/actions/CaptureMemorySnapshotAction.kt @@ -0,0 +1,36 @@ +package com.jetbrains.performancePlugin.actions + +import com.intellij.openapi.actionSystem.ActionUpdateThread +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.progress.runModalTask +import com.intellij.openapi.project.DumbAwareAction +import com.intellij.util.MemoryDumpHelper +import com.intellij.util.SystemProperties +import com.jetbrains.performancePlugin.PerformanceTestingBundle +import com.jetbrains.performancePlugin.profilers.Profiler +import com.jetbrains.performancePlugin.profilers.ProfilerHandlerUtils +import java.io.File + +class CaptureMemorySnapshotAction : DumbAwareAction() { + + override fun actionPerformed(e: AnActionEvent) { + val snapshotFolder = System.getProperty("snapshots.path", SystemProperties.getUserHome()) + val snapshotName = Profiler.formatSnapshotName(true) + ".hprof" + val snapshotFile = File(snapshotFolder, snapshotName) + try { + MemoryDumpHelper.captureMemoryDump(snapshotFile.absolutePath) + ProfilerHandlerUtils.notify(e.project, snapshotFile) + } + catch (exception: Exception) { + ProfilerHandlerUtils.notifyCapturingError(exception, e.project) + } + } + + override fun getActionUpdateThread(): ActionUpdateThread { + return ActionUpdateThread.BGT + } + + override fun update(e: AnActionEvent) { + e.presentation.isEnabledAndVisible = MemoryDumpHelper.memoryDumpAvailable() + } +} \ No newline at end of file