Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

处理heapDump命令outPut路径,优先采用用户配置路径 #2822

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()+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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -182,4 +183,9 @@ public interface CommandProcess extends Tty {
*/
void appendResult(ResultModel result);

/**
* add custom output file
*/
File getArthasOutput();

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<CliToken> argsTokens() {
return args;
Expand Down