From 3b0d3c70d92d6e966f78673909fbd90a4089ea94 Mon Sep 17 00:00:00 2001 From: "zhou.yun" Date: Thu, 25 Apr 2024 18:14:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=A4=84=E7=90=86heapDump=E5=91=BD?= =?UTF-8?q?=E4=BB=A4outPut=E8=B7=AF=E5=BE=84=EF=BC=8C=E4=BC=98=E5=85=88?= =?UTF-8?q?=E9=87=87=E7=94=A8=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE=E8=B7=AF?= =?UTF-8?q?=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/command/monitor200/HeapDumpCommand.java | 2 +- .../core/shell/command/CommandProcess.java | 6 ++++++ .../core/shell/system/impl/ProcessImpl.java | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java index e1e031e4c69..4c9f561d82e 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java @@ -51,7 +51,7 @@ public void setLive(boolean live) { @Override public void process(CommandProcess process) { try { - String dumpFile = file; + String dumpFile = file == null ? process.getArthasOutput().getAbsolutePath() : null; if (dumpFile == null || dumpFile.isEmpty()) { String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date()); File file = File.createTempFile("heapdump" + date + (live ? "-live" : ""), ".hprof"); diff --git a/core/src/main/java/com/taobao/arthas/core/shell/command/CommandProcess.java b/core/src/main/java/com/taobao/arthas/core/shell/command/CommandProcess.java index 3cdf16af3b9..33bc7190cab 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/command/CommandProcess.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/command/CommandProcess.java @@ -8,6 +8,7 @@ import com.taobao.arthas.core.shell.term.Tty; import com.taobao.middleware.cli.CommandLine; +import java.io.File; import java.lang.instrument.ClassFileTransformer; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -182,4 +183,9 @@ public interface CommandProcess extends Tty { */ void appendResult(ResultModel result); + /** + * add custom output file + */ + File getArthasOutput(); + } diff --git a/core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java index 74adfd1bdb0..4ca082450b9 100644 --- a/core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java +++ b/core/src/main/java/com/taobao/arthas/core/shell/system/impl/ProcessImpl.java @@ -25,6 +25,7 @@ import com.taobao.middleware.cli.CommandLine; import io.termd.core.function.Function; +import java.io.File; import java.lang.instrument.ClassFileTransformer; import java.util.Date; import java.util.LinkedList; @@ -367,8 +368,10 @@ public synchronized void run(boolean fg) { process.echoTips("job id : " + this.jobId + "\n"); process.echoTips("cache location : " + cacheLocation() + "\n"); } + ArthasBootstrap arthasBootstrap = ArthasBootstrap.getInstance(); + process.setArthasOutput(arthasBootstrap.getOutputPath()); Runnable task = new CommandProcessTask(process); - ArthasBootstrap.getInstance().execute(task); + arthasBootstrap.execute(task); } private class CommandProcessTask implements Runnable { @@ -400,12 +403,23 @@ private class CommandProcessImpl implements CommandProcess { private AtomicInteger times = new AtomicInteger(); private AdviceListener listener = null; private ClassFileTransformer transformer; + private File arthasOutput; + public CommandProcessImpl(Process process, Tty tty) { this.process = process; this.tty = tty; } + public void setArthasOutput(File arthasOutput){ + this.arthasOutput = arthasOutput; + } + + @Override + public File getArthasOutput(){ + return this.arthasOutput; + } + @Override public List argsTokens() { return args; From 13a8def2e7db2a0434b01463264bc22d647aed8e Mon Sep 17 00:00:00 2001 From: "zhou.yun" Date: Thu, 25 Apr 2024 19:10:26 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E7=BB=99heapdump=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taobao/arthas/core/command/monitor200/HeapDumpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java index 4c9f561d82e..acce76fe44f 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java @@ -51,7 +51,7 @@ public void setLive(boolean live) { @Override public void process(CommandProcess process) { try { - String dumpFile = file == null ? process.getArthasOutput().getAbsolutePath() : null; + String dumpFile = file == null ? (process.getArthasOutput().getAbsolutePath()+"heapdump"+System.currentTimeMillis()+".hprof") : null; if (dumpFile == null || dumpFile.isEmpty()) { String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date()); File file = File.createTempFile("heapdump" + date + (live ? "-live" : ""), ".hprof"); From 7d6a31954ef4821be4581a356332603f79310980 Mon Sep 17 00:00:00 2001 From: "zhou.yun" Date: Thu, 25 Apr 2024 19:25:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=BB=99heapdump=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D=E5=A2=9E=E5=8A=A0=E5=88=86=E9=9A=94=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../taobao/arthas/core/command/monitor200/HeapDumpCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java index acce76fe44f..3e02ef01317 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/HeapDumpCommand.java @@ -51,7 +51,7 @@ public void setLive(boolean live) { @Override public void process(CommandProcess process) { try { - String dumpFile = file == null ? (process.getArthasOutput().getAbsolutePath()+"heapdump"+System.currentTimeMillis()+".hprof") : null; + String dumpFile = file == null ? (process.getArthasOutput().getAbsolutePath()+File.separator+"heapdump-"+System.currentTimeMillis()+".hprof") : null; if (dumpFile == null || dumpFile.isEmpty()) { String date = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date()); File file = File.createTempFile("heapdump" + date + (live ? "-live" : ""), ".hprof");