Skip to content

Commit

Permalink
alibaba#730 print sm process failed class name
Browse files Browse the repository at this point in the history
  • Loading branch information
kylixs committed May 9, 2020
1 parent 0476c61 commit a2536bd
Showing 1 changed file with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.lang.reflect.Method;
import java.util.Set;

import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.cli.Completion;
import com.taobao.arthas.core.shell.cli.CompletionUtils;
Expand Down Expand Up @@ -46,6 +48,7 @@
" sm -Ed org\\\\.apache\\\\.commons\\\\.lang\\.StringUtils .*\n" +
Constants.WIKI + Constants.WIKI_HOME + "sm")
public class SearchMethodCommand extends AnnotatedCommand {
private static final Logger logger = LoggerFactory.getLogger(SearchMethodCommand.class);

private String classPattern;
private String methodPattern;
Expand Down Expand Up @@ -92,34 +95,42 @@ public void process(CommandProcess process) {
Set<Class<?>> matchedClasses = SearchUtils.searchClass(inst, classPattern, isRegEx, hashCode);

for (Class<?> clazz : matchedClasses) {
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(constructor).toString();
if (!methodNameMatcher.matching("<init>")) {
continue;
try {
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(constructor).toString();
if (!methodNameMatcher.matching("<init>")) {
continue;
}

if (isDetail) {
process.write(RenderUtil.render(renderConstructor(constructor, clazz), process.width()) + "\n");
} else {
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
}
affect.rCnt(1);
}

if (isDetail) {
process.write(RenderUtil.render(renderConstructor(constructor, clazz), process.width()) + "\n");
} else {
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
for (Method method : clazz.getDeclaredMethods()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(method).toString();
if (!methodNameMatcher.matching(method.getName())) {
continue;
}

if (isDetail) {
process.write(RenderUtil.render(renderMethod(method, clazz), process.width()) + "\n");
} else {
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
}
affect.rCnt(1);
}
affect.rCnt(1);
}

for (Method method : clazz.getDeclaredMethods()) {
String methodNameWithDescriptor = org.objectweb.asm.commons.Method.getMethod(method).toString();
if (!methodNameMatcher.matching(method.getName())) {
continue;
}

if (isDetail) {
process.write(RenderUtil.render(renderMethod(method, clazz), process.width()) + "\n");
} else {
String line = format("%s %s%n", clazz.getName(), methodNameWithDescriptor);
process.write(line);
}
affect.rCnt(1);
} catch (Error e) {
//print failed className
String msg = String.format("process class failed: %s, error: %s", clazz.getName(), e.toString());
logger.error(msg, e);
process.write(msg).write("\n");
throw e;
}
}

Expand Down

0 comments on commit a2536bd

Please sign in to comment.