Skip to content

Commit

Permalink
dump command limit option. alibaba#916
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Nov 9, 2019
1 parent b80cd11 commit 53ebd8a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,6 @@ private static class ClassLoaderInfo implements Comparable<ClassLoaderInfo> {
this.classLoader = classLoader;
}

public ClassLoader getClassLoader() {
return classLoader;
}

public String getName() {
if (classLoader != null) {
return classLoader.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
import com.taobao.arthas.core.util.TypeRenderUtils;
import com.taobao.arthas.core.util.affect.RowAffect;
import com.taobao.middleware.cli.annotations.Argument;
import com.taobao.middleware.cli.annotations.DefaultValue;
import com.taobao.middleware.cli.annotations.Description;
import com.taobao.middleware.cli.annotations.Name;
import com.taobao.middleware.cli.annotations.Option;
import com.taobao.middleware.cli.annotations.Summary;
import com.taobao.middleware.logger.Logger;
import com.taobao.text.Color;
import com.taobao.text.Decoration;
import com.taobao.text.ui.Element;
import com.taobao.text.ui.LabelElement;
import com.taobao.text.ui.TableElement;
import com.taobao.text.util.RenderUtil;
Expand Down Expand Up @@ -53,6 +53,8 @@ public class DumpClassCommand extends AnnotatedCommand {

private String directory;

private int limit;

@Argument(index = 0, argName = "class-pattern")
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
Expand All @@ -77,6 +79,13 @@ public void setDirectory(String directory) {
this.directory = directory;
}

@Option(shortName = "l", longName = "limit")
@Description("The limit of dump classes size, default value is 5")
@DefaultValue("5")
public void setLimit(int limit) {
this.limit = limit;
}

@Override
public void process(CommandProcess process) {
RowAffect effect = new RowAffect();
Expand All @@ -94,7 +103,7 @@ public void process(CommandProcess process) {

if (matchedClasses == null || matchedClasses.isEmpty()) {
processNoMatch(process);
} else if (matchedClasses.size() > 5) {
} else if (matchedClasses.size() > limit) {
processMatches(process, matchedClasses);
} else {
processMatch(process, effect, inst, matchedClasses);
Expand Down Expand Up @@ -137,9 +146,9 @@ private void processMatch(CommandProcess process, RowAffect effect, Instrumentat
}

private void processMatches(CommandProcess process, Set<Class<?>> matchedClasses) {
Element usage = new LabelElement("dump -c hashcode " + classPattern).style(Decoration.bold.fg(Color.blue));
process.write("Found more than 5 class for: " + classPattern + ", Please use ");
process.write(RenderUtil.render(usage, process.width()));
process.write(String.format(
"Found more than %d class for: %s, Please Try to specify the classloader with the -c option, or try to use --limit option.\n",
limit, classPattern));

TableElement table = new TableElement().leftCellPadding(1).rightCellPadding(1);
table.row(new LabelElement("NAME").style(Decoration.bold.bold()),
Expand Down

0 comments on commit 53ebd8a

Please sign in to comment.