mirror of
https://gitee.com/arthas/arthas.git
synced 2024-12-02 04:08:34 +08:00
imporve split methodInfo/invokeInfo. #1860
This commit is contained in:
parent
1c9144a5a0
commit
bfaf416c69
@ -2,12 +2,12 @@ package com.taobao.arthas.core.advisor;
|
||||
|
||||
import java.arthas.SpyAPI.AbstractSpy;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.arthas.deps.org.slf4j.Logger;
|
||||
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
|
||||
import com.taobao.arthas.core.shell.system.ExecStatus;
|
||||
import com.taobao.arthas.core.shell.system.ProcessAware;
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
@ -27,7 +27,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
public void atEnter(Class<?> clazz, String methodInfo, Object target, Object[] args) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
|
||||
String[] info = splitMethodInfo(methodInfo);
|
||||
String[] info = StringUtils.splitMethodInfo(methodInfo);
|
||||
String methodName = info[0];
|
||||
String methodDesc = info[1];
|
||||
// TODO listener 只用查一次,放到 thread local里保存起来就可以了!
|
||||
@ -52,7 +52,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
public void atExit(Class<?> clazz, String methodInfo, Object target, Object[] args, Object returnObject) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
|
||||
String[] info = splitMethodInfo(methodInfo);
|
||||
String[] info = StringUtils.splitMethodInfo(methodInfo);
|
||||
String methodName = info[0];
|
||||
String methodDesc = info[1];
|
||||
|
||||
@ -76,7 +76,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
public void atExceptionExit(Class<?> clazz, String methodInfo, Object target, Object[] args, Throwable throwable) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
|
||||
String[] info = splitMethodInfo(methodInfo);
|
||||
String[] info = StringUtils.splitMethodInfo(methodInfo);
|
||||
String methodName = info[0];
|
||||
String methodDesc = info[1];
|
||||
|
||||
@ -99,7 +99,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
@Override
|
||||
public void atBeforeInvoke(Class<?> clazz, String invokeInfo, Object target) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
String[] info = splitInvokeInfo(invokeInfo);
|
||||
String[] info = StringUtils.splitInvokeInfo(invokeInfo);
|
||||
String owner = info[0];
|
||||
String methodName = info[1];
|
||||
String methodDesc = info[2];
|
||||
@ -125,7 +125,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
@Override
|
||||
public void atAfterInvoke(Class<?> clazz, String invokeInfo, Object target) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
String[] info = splitInvokeInfo(invokeInfo);
|
||||
String[] info = StringUtils.splitInvokeInfo(invokeInfo);
|
||||
String owner = info[0];
|
||||
String methodName = info[1];
|
||||
String methodDesc = info[2];
|
||||
@ -151,7 +151,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
@Override
|
||||
public void atInvokeException(Class<?> clazz, String invokeInfo, Object target, Throwable throwable) {
|
||||
ClassLoader classLoader = clazz.getClassLoader();
|
||||
String[] info = splitInvokeInfo(invokeInfo);
|
||||
String[] info = StringUtils.splitInvokeInfo(invokeInfo);
|
||||
String owner = info[0];
|
||||
String methodName = info[1];
|
||||
String methodDesc = info[2];
|
||||
@ -174,15 +174,7 @@ public class SpyImpl extends AbstractSpy {
|
||||
}
|
||||
}
|
||||
|
||||
private String[] splitMethodInfo(String methodInfo) {
|
||||
return methodInfo.split(Pattern.quote("|"));
|
||||
}
|
||||
|
||||
private String[] splitInvokeInfo(String invokeInfo) {
|
||||
return invokeInfo.split(Pattern.quote("|"));
|
||||
}
|
||||
|
||||
private boolean skipAdviceListener(AdviceListener adviceListener) {
|
||||
private static boolean skipAdviceListener(AdviceListener adviceListener) {
|
||||
if (adviceListener instanceof ProcessAware) {
|
||||
ProcessAware processAware = (ProcessAware) adviceListener;
|
||||
ExecStatus status = processAware.getProcess().status();
|
||||
|
@ -956,4 +956,16 @@ public abstract class StringUtils {
|
||||
}
|
||||
return text.substring(pos + after.length());
|
||||
}
|
||||
|
||||
public static String[] splitMethodInfo(String methodInfo) {
|
||||
int index = methodInfo.indexOf('|');
|
||||
return new String[] { methodInfo.substring(0, index), methodInfo.substring(index + 1, methodInfo.length()) };
|
||||
}
|
||||
|
||||
public static String[] splitInvokeInfo(String invokeInfo) {
|
||||
int index1 = invokeInfo.indexOf('|');
|
||||
int index2 = invokeInfo.indexOf('|', index1 + 1);
|
||||
return new String[] { invokeInfo.substring(0, index1), invokeInfo.substring(index1 + 1, index2),
|
||||
invokeInfo.substring(index2 + 1, invokeInfo.length()) };
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package com.taobao.arthas.core.advisor;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.taobao.arthas.core.util.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hengyunabc 2021-07-14
|
||||
*
|
||||
*/
|
||||
public class SpyImplTest {
|
||||
|
||||
@Test
|
||||
public void testSplitMethodInfo() throws Throwable {
|
||||
Assertions.assertThat(StringUtils.splitMethodInfo("a|b")).containsExactly("a", "b");
|
||||
Assertions.assertThat(StringUtils.splitMethodInfo("xxxxxxxxxx|fffffffffff")).containsExactly("xxxxxxxxxx",
|
||||
"fffffffffff");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSplitInvokeInfo() throws Throwable {
|
||||
Assertions.assertThat(StringUtils.splitInvokeInfo("a|b|c")).containsExactly("a", "b", "c");
|
||||
Assertions.assertThat(StringUtils.splitInvokeInfo("xxxxxxxxxx|fffffffffff|yyy")).containsExactly("xxxxxxxxxx",
|
||||
"fffffffffff", "yyy");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user