mirror of
https://github.com/alibaba/arthas.git
synced 2026-10-21 03:35:26 +00:00
improve vmtool search class.
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
##step1 在您的pom.xml中增加profile配置
|
||||
```
|
||||
<profiles>
|
||||
<!-- macos -->
|
||||
<profile>
|
||||
<id>macos</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>mac</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<os_family>macos</os_family>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
<!-- linux -->
|
||||
<profile>
|
||||
<id>linux</id>
|
||||
<activation>
|
||||
<os>
|
||||
<name>linux</name>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<os_family>linux</os_family>
|
||||
</properties>
|
||||
</profile>
|
||||
|
||||
<!-- windows -->
|
||||
<profile>
|
||||
<id>windows</id>
|
||||
<activation>
|
||||
<os>
|
||||
<family>windows</family>
|
||||
</os>
|
||||
</activation>
|
||||
<properties>
|
||||
<os_family>windows</os_family>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
```
|
||||
##step2 在您的pom.xml中引入依赖
|
||||
PS:一定要配置好profile,不然无法自动生成`<classifier>`配置。
|
||||
```
|
||||
<dependency>
|
||||
<groupId>com.taobao.arthas</groupId>
|
||||
<artifactId>mana-pool-analyzer</artifactId>
|
||||
<version>${arthas.vision}</version>
|
||||
<classifier>${os_family}-${os.arch}</classifier>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
##step3 如果没有合适的版本
|
||||
1. 如果是32位的操作系统,不好意思,目前暂不支持。
|
||||
|
||||
2. 如果是64位操作系统,请先尝试`mvn clean compile package install -DskipTests=true -U`把依赖安装到本地;
|
||||
|
||||
3. 如果报错,请先确保您本地的g++编译器能够正常工作,再重新尝试`mvn clean compile package install -DskipTests=true -U`;
|
||||
|
||||
如有问题请联系`1936978077@qq.com`。
|
||||
@@ -48,7 +48,9 @@ import arthas.VmTool;
|
||||
+ " vmtool --action getInstances --className demo.MathGame\n"
|
||||
+ " vmtool --action getInstances --className demo.MathGame --express 'instances.length'\n"
|
||||
+ " vmtool --action getInstances --className demo.MathGame --express 'instances[0]'\n"
|
||||
+ " vmtool --action getInstances --className demo.MathGame -x 2\n"
|
||||
+ " vmtool --action getInstances --className java.lang.String --limit 10\n"
|
||||
+ " vmtool --action getInstances --classLoaderClass org.springframework.boot.loader.LaunchedURLClassLoader --className org.springframework.context.ApplicationContext\n"
|
||||
+ " vmtool --action forceGc\n"
|
||||
+ Constants.WIKI + Constants.WIKI_HOME + "vmtool")
|
||||
//@formatter:on
|
||||
@@ -62,7 +64,7 @@ public class VmToolCommand extends AnnotatedCommand {
|
||||
private String hashCode = null;
|
||||
private String classLoaderClass;
|
||||
/**
|
||||
* default value 2
|
||||
* default value 1
|
||||
*/
|
||||
private int expand;
|
||||
|
||||
@@ -107,8 +109,8 @@ public class VmToolCommand extends AnnotatedCommand {
|
||||
}
|
||||
|
||||
@Option(shortName = "x", longName = "expand")
|
||||
@Description("Expand level of object (2 by default)")
|
||||
@DefaultValue("2")
|
||||
@Description("Expand level of object (1 by default)")
|
||||
@DefaultValue("1")
|
||||
public void setExpand(int expand) {
|
||||
this.expand = expand;
|
||||
}
|
||||
@@ -154,6 +156,10 @@ public class VmToolCommand extends AnnotatedCommand {
|
||||
Instrumentation inst = process.session().getInstrumentation();
|
||||
|
||||
if (VmToolAction.getInstances.equals(action)) {
|
||||
if (className == null) {
|
||||
process.end(-1, "The className option cannot be empty!");
|
||||
return;
|
||||
}
|
||||
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
if (hashCode == null && classLoaderClass != null) {
|
||||
List<ClassLoader> matchedClassLoaders = ClassLoaderUtils.getClassLoaderByClassName(inst,
|
||||
@@ -177,7 +183,7 @@ public class VmToolCommand extends AnnotatedCommand {
|
||||
}
|
||||
|
||||
List<Class<?>> matchedClasses = new ArrayList<Class<?>>(
|
||||
SearchUtils.searchClass(inst, className, false, hashCode));
|
||||
SearchUtils.searchClassOnly(inst, className, false, hashCode));
|
||||
int matchedClassSize = matchedClasses.size();
|
||||
if (matchedClassSize == 0) {
|
||||
process.end(-1, "Can not find class by class name: " + className + ".");
|
||||
|
||||
Reference in New Issue
Block a user