watch/trace/monitor/tt/stack support verbose option, print ConditionExpress result.

pull/1093/merge
hengyunabc
parent 17b9116630
commit c77a4bcf05

@ -20,6 +20,8 @@ public abstract class AdviceListenerAdapter implements AdviceListener, ProcessAw
private Process process;
private long id = ID_GENERATOR.addAndGet(1);
private boolean verbose;
@Override
public long id() {
return id;
@ -144,4 +146,12 @@ public abstract class AdviceListenerAdapter implements AdviceListener, ProcessAw
process.end();
}
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
}

@ -74,7 +74,11 @@ public class AbstractTraceAdviceListener extends AdviceListenerAdapter {
double cost = threadLocalWatch.costInMillis();
if (--threadBoundEntity.get().deep == 0) {
try {
if (isConditionMet(command.getConditionExpress(), advice, cost)) {
boolean conditionResult = isConditionMet(command.getConditionExpress(), advice, cost);
if (this.isVerbose()) {
process.write("Condition express: " + command.getConditionExpress() + " , result: " + conditionResult + "\n");
}
if (conditionResult) {
// 满足输出条件
if (isLimitExceeded(command.getNumberOfLimit(), process.times().get())) {
// TODO: concurrency issue to abort process

@ -40,12 +40,20 @@ public abstract class EnhancerCommand extends AnnotatedCommand {
protected long listenerId;
protected boolean verbose;
@Option(longName = "listenerId")
@Description("The special listenerId")
public void setListenerId(long listenerId) {
this.listenerId = listenerId;
}
@Option(shortName = "v", longName = "verbose", flag = true)
@Description("Enables print verbose information, default value false.")
public void setVerbosee(boolean verbose) {
this.verbose = verbose;
}
/**
*
*

@ -75,9 +75,10 @@ class MonitorAdviceListener extends AdviceListenerAdapter {
private MonitorCommand command;
private CommandProcess process;
MonitorAdviceListener(MonitorCommand command, CommandProcess process) {
MonitorAdviceListener(MonitorCommand command, CommandProcess process, boolean verbose) {
this.command = command;
this.process = process;
super.setVerbose(verbose);
}
@Override

@ -1,6 +1,7 @@
package com.taobao.arthas.core.command.monitor200;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.AdviceListener;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.CommandProcess;
@ -100,7 +101,7 @@ public class MonitorCommand extends EnhancerCommand {
@Override
protected AdviceListener getAdviceListener(CommandProcess process) {
final AdviceListener listener = new MonitorAdviceListener(this, process);
final AdviceListener listener = new MonitorAdviceListener(this, process, GlobalOptions.verbose || this.verbose);
/*
* handlesuspendtimerresumetimer
*/

@ -22,9 +22,10 @@ public class StackAdviceListener extends AdviceListenerAdapter {
private StackCommand command;
private CommandProcess process;
public StackAdviceListener(StackCommand command, CommandProcess process) {
public StackAdviceListener(StackCommand command, CommandProcess process, boolean verbose) {
this.command = command;
this.process = process;
super.setVerbose(verbose);
}
@Override
@ -53,7 +54,11 @@ public class StackAdviceListener extends AdviceListenerAdapter {
// 本次调用的耗时
try {
double cost = threadLocalWatch.costInMillis();
if (isConditionMet(command.getConditionExpress(), advice, cost)) {
boolean conditionResult = isConditionMet(command.getConditionExpress(), advice, cost);
if (this.isVerbose()) {
process.write("Condition express: " + command.getConditionExpress() + " , result: " + conditionResult + "\n");
}
if (conditionResult) {
// TODO: concurrency issues for process.write
process.write("ts=" + DateUtils.getCurrentDate() + ";" + stackThreadLocal.get() + "\n");
process.times().incrementAndGet();
@ -61,7 +66,7 @@ public class StackAdviceListener extends AdviceListenerAdapter {
abortProcess(process, command.getNumberOfLimit());
}
}
} catch (Exception e) {
} catch (Throwable e) {
logger.warn("stack failed.", e);
process.write("stack failed, condition is: " + command.getConditionExpress() + ", " + e.getMessage()
+ ", visit " + LogUtil.loggingFile() + " for more details.\n");

@ -1,5 +1,6 @@
package com.taobao.arthas.core.command.monitor200;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.AdviceListener;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.CommandProcess;
@ -102,7 +103,7 @@ public class StackCommand extends EnhancerCommand {
@Override
protected AdviceListener getAdviceListener(CommandProcess process) {
return new StackAdviceListener(this, process);
return new StackAdviceListener(this, process, GlobalOptions.verbose || this.verbose);
}
}

@ -40,9 +40,10 @@ public class TimeTunnelAdviceListener extends AdviceListenerAdapter {
// 方法执行时间戳
private final ThreadLocalWatch threadLocalWatch = new ThreadLocalWatch();
public TimeTunnelAdviceListener(TimeTunnelCommand command, CommandProcess process) {
public TimeTunnelAdviceListener(TimeTunnelCommand command, CommandProcess process, boolean verbose) {
this.command = command;
this.process = process;
super.setVerbose(verbose);
}
@Override
@ -75,6 +76,9 @@ public class TimeTunnelAdviceListener extends AdviceListenerAdapter {
boolean match = false;
try {
match = isConditionMet(command.getConditionExpress(), advice, cost);
if (this.isVerbose()) {
process.write("Condition express: " + command.getConditionExpress() + " , result: " + match + "\n");
}
} catch (ExpressException e) {
logger.warn("tt failed.", e);
process.write("tt failed, condition is: " + command.getConditionExpress() + ", " + e.getMessage()

@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.monitor200;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.Advice;
import com.taobao.arthas.core.advisor.AdviceListener;
import com.taobao.arthas.core.advisor.ArthasMethod;
@ -313,7 +314,7 @@ public class TimeTunnelCommand extends EnhancerCommand {
@Override
protected AdviceListener getAdviceListener(CommandProcess process) {
return new TimeTunnelAdviceListener(this, process);
return new TimeTunnelAdviceListener(this, process, GlobalOptions.verbose || this.verbose);
}
// 展示指定记录

@ -12,8 +12,9 @@ public class TraceAdviceListener extends AbstractTraceAdviceListener implements
/**
* Constructor
*/
public TraceAdviceListener(TraceCommand command, CommandProcess process) {
public TraceAdviceListener(TraceCommand command, CommandProcess process, boolean verbose) {
super(command, process);
super.setVerbose(verbose);
}
/**

@ -1,5 +1,6 @@
package com.taobao.arthas.core.command.monitor200;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.AdviceListener;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.command.CommandProcess;
@ -147,7 +148,7 @@ public class TraceCommand extends EnhancerCommand {
@Override
protected AdviceListener getAdviceListener(CommandProcess process) {
if (pathPatterns == null || pathPatterns.isEmpty()) {
return new TraceAdviceListener(this, process);
return new TraceAdviceListener(this, process, GlobalOptions.verbose || this.verbose);
} else {
return new PathTraceAdviceListener(this, process);
}

@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.monitor200;
import com.alibaba.arthas.deps.org.slf4j.Logger;
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.Advice;
import com.taobao.arthas.core.advisor.ArthasMethod;
import com.taobao.arthas.core.advisor.AdviceListenerAdapter;
@ -22,9 +23,10 @@ class WatchAdviceListener extends AdviceListenerAdapter {
private WatchCommand command;
private CommandProcess process;
public WatchAdviceListener(WatchCommand command, CommandProcess process) {
public WatchAdviceListener(WatchCommand command, CommandProcess process, boolean verbose) {
this.command = command;
this.process = process;
super.setVerbose(verbose);
}
private boolean isFinish() {
@ -78,7 +80,11 @@ class WatchAdviceListener extends AdviceListenerAdapter {
try {
// 本次调用的耗时
double cost = threadLocalWatch.costInMillis();
if (isConditionMet(command.getConditionExpress(), advice, cost)) {
boolean conditionResult = isConditionMet(command.getConditionExpress(), advice, cost);
if (this.isVerbose()) {
process.write("Condition express: " + command.getConditionExpress() + " , result: " + conditionResult + "\n");
}
if (conditionResult) {
// TODO: concurrency issues for process.write
Object value = getExpressionResult(command.getExpress(), advice, cost);
String result = StringUtils.objectToString(
@ -89,7 +95,7 @@ class WatchAdviceListener extends AdviceListenerAdapter {
abortProcess(process, command.getNumberOfLimit());
}
}
} catch (Exception e) {
} catch (Throwable e) {
logger.warn("watch failed.", e);
process.write("watch failed, condition is: " + command.getConditionExpress() + ", express is: "
+ command.getExpress() + ", " + e.getMessage() + ", visit " + LogUtil.loggingFile()

@ -2,6 +2,7 @@ package com.taobao.arthas.core.command.monitor200;
import java.util.Arrays;
import com.taobao.arthas.core.GlobalOptions;
import com.taobao.arthas.core.advisor.AdviceListener;
import com.taobao.arthas.core.command.Constants;
import com.taobao.arthas.core.shell.cli.Completion;
@ -182,7 +183,7 @@ public class WatchCommand extends EnhancerCommand {
@Override
protected AdviceListener getAdviceListener(CommandProcess process) {
return new WatchAdviceListener(this, process);
return new WatchAdviceListener(this, process, GlobalOptions.verbose || this.verbose);
}
@Override

Loading…
Cancel
Save