From 3170a92b565b59c037fe501accc7c0ef4187f0d4 Mon Sep 17 00:00:00 2001 From: hengyunabc Date: Fri, 7 May 2021 23:34:28 +0800 Subject: [PATCH] vmtool command support libPath --- .../core/command/monitor200/VmToolCommand.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java index e053b59f6..35e46ec0e 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/VmToolCommand.java @@ -71,7 +71,8 @@ public class VmToolCommand extends AnnotatedCommand { */ private int limit; - private static String libPath; + private String libPath; + private static String defaultLibPath; private static VmTool vmTool = null; static { @@ -83,7 +84,7 @@ public class VmToolCommand extends AnnotatedCommand { File bootJarPath = new File(codeSource.getLocation().toURI().getSchemeSpecificPart()); File soFile = new File(bootJarPath.getParentFile(), "lib" + File.separator + libName); if (soFile.exists()) { - libPath = soFile.getAbsolutePath(); + defaultLibPath = soFile.getAbsolutePath(); } } catch (Throwable e) { logger.error("can not find VmTool so", e); @@ -131,6 +132,12 @@ public class VmToolCommand extends AnnotatedCommand { this.limit = limit; } + @Option(longName = "libPath") + @Description("The specify lib path.") + public void setLibPath(String path) { + libPath = path; + } + @Option(longName = "express", required = false) @Description("The ognl expression, default valueis `instances`.") public void setExpress(String express) { @@ -138,7 +145,7 @@ public class VmToolCommand extends AnnotatedCommand { } public enum VmToolAction { - getInstances, forceGc, load + getInstances, forceGc } @Override @@ -230,6 +237,9 @@ public class VmToolCommand extends AnnotatedCommand { if (vmTool != null) { return vmTool; } else { + if (libPath == null) { + libPath = defaultLibPath; + } vmTool = VmTool.getInstance(libPath); } return vmTool;