|
|
|
@ -1,18 +1,26 @@
|
|
|
|
|
package com.taobao.arthas.core.command.klass100;
|
|
|
|
|
|
|
|
|
|
import static com.taobao.text.Decoration.bold;
|
|
|
|
|
import static com.taobao.text.ui.Element.label;
|
|
|
|
|
import static java.lang.String.format;
|
|
|
|
|
|
|
|
|
|
import java.lang.instrument.Instrumentation;
|
|
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import com.taobao.arthas.core.command.Constants;
|
|
|
|
|
import com.taobao.arthas.core.shell.cli.CliToken;
|
|
|
|
|
import com.taobao.arthas.core.shell.cli.Completion;
|
|
|
|
|
import com.taobao.arthas.core.shell.cli.CompletionUtils;
|
|
|
|
|
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
|
|
|
|
|
import com.taobao.arthas.core.shell.command.CommandProcess;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.Matcher;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.RegexMatcher;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.WildcardMatcher;
|
|
|
|
|
import com.taobao.arthas.core.util.SearchUtils;
|
|
|
|
|
import com.taobao.arthas.core.util.StringUtils;
|
|
|
|
|
import com.taobao.arthas.core.util.TypeRenderUtils;
|
|
|
|
|
import com.taobao.arthas.core.util.affect.RowAffect;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.Matcher;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.RegexMatcher;
|
|
|
|
|
import com.taobao.arthas.core.util.matcher.WildcardMatcher;
|
|
|
|
|
import com.taobao.middleware.cli.annotations.Argument;
|
|
|
|
|
import com.taobao.middleware.cli.annotations.Description;
|
|
|
|
|
import com.taobao.middleware.cli.annotations.Name;
|
|
|
|
@ -22,21 +30,11 @@ import com.taobao.text.ui.Element;
|
|
|
|
|
import com.taobao.text.ui.TableElement;
|
|
|
|
|
import com.taobao.text.util.RenderUtil;
|
|
|
|
|
|
|
|
|
|
import java.lang.instrument.Instrumentation;
|
|
|
|
|
import java.lang.reflect.Constructor;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import static com.taobao.text.Decoration.bold;
|
|
|
|
|
import static com.taobao.text.ui.Element.label;
|
|
|
|
|
import static java.lang.String.format;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 展示方法信息
|
|
|
|
|
*
|
|
|
|
|
* @author vlinux
|
|
|
|
|
* @author hengyunabc 2019-02-13
|
|
|
|
|
*/
|
|
|
|
|
@Name("sm")
|
|
|
|
|
@Summary("Search the method of classes loaded by JVM")
|
|
|
|
@ -87,8 +85,8 @@ public class SearchMethodCommand extends AnnotatedCommand {
|
|
|
|
|
Set<Class<?>> matchedClasses = SearchUtils.searchClass(inst, classPattern, isRegEx);
|
|
|
|
|
|
|
|
|
|
for (Class<?> clazz : matchedClasses) {
|
|
|
|
|
Set<String> methodNames = new HashSet<String>();
|
|
|
|
|
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
|
|
|
|
|
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(constructor).toString();
|
|
|
|
|
if (!methodNameMatcher.matching("<init>")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -96,17 +94,14 @@ public class SearchMethodCommand extends AnnotatedCommand {
|
|
|
|
|
if (isDetail) {
|
|
|
|
|
process.write(RenderUtil.render(renderConstructor(constructor), process.width()) + "\n");
|
|
|
|
|
} else {
|
|
|
|
|
if (methodNames.contains("<init>")) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
methodNames.add("<init>");
|
|
|
|
|
String line = format("%s->%s%n", clazz.getName(), "<init>");
|
|
|
|
|
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
|
|
|
|
|
process.write(line);
|
|
|
|
|
}
|
|
|
|
|
affect.rCnt(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Method method : clazz.getDeclaredMethods()) {
|
|
|
|
|
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(method).toString();
|
|
|
|
|
if (!methodNameMatcher.matching(method.getName())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -114,11 +109,7 @@ public class SearchMethodCommand extends AnnotatedCommand {
|
|
|
|
|
if (isDetail) {
|
|
|
|
|
process.write(RenderUtil.render(renderMethod(method), process.width()) + "\n");
|
|
|
|
|
} else {
|
|
|
|
|
if (methodNames.contains(method.getName())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
methodNames.add(method.getName());
|
|
|
|
|
String line = format("%s->%s%n", clazz.getName(), method.getName());
|
|
|
|
|
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
|
|
|
|
|
process.write(line);
|
|
|
|
|
}
|
|
|
|
|
affect.rCnt(1);
|
|
|
|
|