-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ~ for method-pattern to take value from class-pattern
此功能的用意:使用特殊值 ~ 表示其值从class-pattern获取 目的从stack或trace的输出复制出来不用修改就可直接使用 **增加方便性,以提升效率**
- Loading branch information
Showing
6 changed files
with
60 additions
and
27 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
core/src/main/java/com/taobao/arthas/core/command/monitor200/AbstractMethodBasedCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.taobao.arthas.core.command.monitor200; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import com.taobao.arthas.core.shell.command.CommandProcess; | ||
import com.taobao.middleware.cli.annotations.Argument; | ||
import com.taobao.middleware.cli.annotations.Description; | ||
|
||
/** | ||
* 基于方法命令抽像类. | ||
*/ | ||
public abstract class AbstractMethodBasedCommand extends EnhancerCommand { | ||
|
||
|
||
protected String classPattern; | ||
protected String methodPattern; | ||
|
||
@Argument(argName = "class-pattern", index = 0) | ||
@Description("Path and classname of Pattern Matching") | ||
public void setClassPattern(final String classPattern) { | ||
this.classPattern = classPattern; | ||
} | ||
|
||
@Argument(argName = "method-pattern", index = 1) | ||
@Description("Method of Pattern Matching, ~ means take from class-pattern com.a.C:method or com.a.C.method") | ||
public void setMethodPattern(final String methodPattern) { | ||
this.methodPattern = methodPattern; | ||
} | ||
|
||
@Override | ||
protected void enhance(final CommandProcess process) { | ||
if ("~".equals(methodPattern)) { //smart way | ||
final Pattern smartPattern = Pattern.compile("([.][A-Z][^.]*)([.:])([a-z][^. ]*)$"); | ||
final Matcher matcher = smartPattern.matcher(classPattern); | ||
if (matcher.find()) { | ||
methodPattern = matcher.group(3); | ||
classPattern = matcher.replaceAll("$1"); | ||
process.echoTips("smart way input ==> " + classPattern + " " + methodPattern + "\n"); | ||
} | ||
} | ||
super.enhance(process); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters