Merge branch 'master' of github.com:alibaba/arthas

pull/539/head
hengyunabc 6 years ago
commit 4c41d6e759

@ -1,5 +1,15 @@
package com.taobao.arthas.core.command.klass100;
import static com.taobao.text.ui.Element.label;
import java.lang.instrument.Instrumentation;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.AnnotatedCommand;
import com.taobao.arthas.core.shell.command.CommandProcess;
@ -17,12 +27,6 @@ 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.security.CodeSource;
import java.util.Set;
import static com.taobao.text.ui.Element.label;
/**
*
*
@ -43,6 +47,14 @@ public class SearchClassCommand extends AnnotatedCommand {
private boolean isRegEx = false;
private Integer expand;
public static String getCodeSource(final CodeSource cs) {
if (null == cs || null == cs.getLocation() || null == cs.getLocation().getFile()) {
return com.taobao.arthas.core.util.Constants.EMPTY_STRING;
}
return cs.getLocation().getFile();
}
@Argument(argName = "class-pattern", index = 0)
@Description("Class name pattern, use either '.' or '/' as separator")
public void setClassPattern(String classPattern) {
@ -78,7 +90,13 @@ public class SearchClassCommand extends AnnotatedCommand {
// TODO: null check
RowAffect affect = new RowAffect();
Instrumentation inst = process.session().getInstrumentation();
Set<Class<?>> matchedClasses = SearchUtils.searchClass(inst, classPattern, isRegEx);
List<Class<?>> matchedClasses = new ArrayList(SearchUtils.searchClass(inst, classPattern, isRegEx));
Collections.sort(matchedClasses, new Comparator() {
@Override
public int compare(Object o1, Object o2) {
return StringUtils.classname((Class) o1).compareTo(StringUtils.classname((Class) o2));
}
});
for (Class<?> clazz : matchedClasses) {
processClass(process, clazz);
@ -127,12 +145,4 @@ public class SearchClassCommand extends AnnotatedCommand {
return table;
}
public static String getCodeSource(final CodeSource cs) {
if (null == cs || null == cs.getLocation() || null == cs.getLocation().getFile()) {
return com.taobao.arthas.core.util.Constants.EMPTY_STRING;
}
return cs.getLocation().getFile();
}
}

@ -1,9 +1,9 @@
package com.taobao.arthas.core.command.monitor200;
import com.taobao.arthas.core.advisor.ReflectAdviceListenerAdapter;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.advisor.Advice;
import com.taobao.arthas.core.advisor.ArthasMethod;
import com.taobao.arthas.core.advisor.ReflectAdviceListenerAdapter;
import com.taobao.arthas.core.shell.command.CommandProcess;
import com.taobao.arthas.core.util.DateUtils;
import com.taobao.arthas.core.util.LogUtil;
import com.taobao.arthas.core.util.StringUtils;
@ -11,9 +11,6 @@ import com.taobao.arthas.core.util.ThreadLocalWatch;
import com.taobao.arthas.core.view.ObjectView;
import com.taobao.middleware.logger.Logger;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author beiwei30 on 29/11/2016.
*/
@ -85,7 +82,7 @@ class WatchAdviceListener extends ReflectAdviceListenerAdapter {
Object value = getExpressionResult(command.getExpress(), advice, cost);
String result = StringUtils.objectToString(
isNeedExpand() ? new ObjectView(value, command.getExpand(), command.getSizeLimit()).draw() : value);
process.write("ts=" + DateUtils.getCurrentDate() + ";result=" + result + "\n");
process.write("ts=" + DateUtils.getCurrentDate() + "; [cost=" + cost + "ms] result=" + result + "\n");
process.times().incrementAndGet();
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
abortProcess(process, command.getNumberOfLimit());

@ -139,7 +139,7 @@ $ thread -b
- java.util.concurrent.ThreadPoolExecutor$Worker@31a6493e
```
> Attention: only `synchronized` blocked threads can be located for now, `JUL` not supported yet.
Attention: only `synchronized` blocked threads can be located for now, while `java.util.concurrent.Lock` not supported yet.
#### thread -i specify the collecting interval

@ -138,7 +138,7 @@ $ thread -b
- java.util.concurrent.ThreadPoolExecutor$Worker@31a6493e
```
> 注意, 目前只支持找出synchronized关键字阻塞住的线程 如果是JUL的锁 目前还不支持。
> 注意, 目前只支持找出synchronized关键字阻塞住的线程 如果是`java.util.concurrent.Lock` 目前还不支持。
#### thread -i, 指定采样时间间隔
@ -162,4 +162,4 @@ $ thread -n 3 -i 1000
Number of locked synchronizers = 1
- java.util.concurrent.ThreadPoolExecutor$Worker@546aeec1
...
```
```

Loading…
Cancel
Save