mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
EnhancerAffect print the affected method details when verbose option is true #1195
This commit is contained in:
@@ -132,5 +132,5 @@ public class GlobalOptions {
|
||||
summary = "Option to print verbose information",
|
||||
description = "This option enables print verbose information, default value false."
|
||||
)
|
||||
public static volatile boolean verbose = true;
|
||||
public static volatile boolean verbose = false;
|
||||
}
|
||||
|
||||
@@ -295,7 +295,7 @@ public class Enhancer implements ClassFileTransformer {
|
||||
// enter/exist 总是要插入 listener
|
||||
AdviceListenerManager.registerAdviceListener(inClassLoader, className, methodNode.name, methodNode.desc,
|
||||
listener);
|
||||
affect.mCnt(1);
|
||||
affect.addMethodAndCount(inClassLoader, className, methodNode.name, methodNode.desc);
|
||||
}
|
||||
|
||||
byte[] enhanceClassByteArray = AsmUtils.toBytes(classNode);
|
||||
@@ -351,7 +351,7 @@ public class Enhancer implements ClassFileTransformer {
|
||||
// 将类字节码写入文件
|
||||
try {
|
||||
FileUtils.writeByteArrayToFile(dumpClassFile, data);
|
||||
affect.getClassDumpFiles().add(dumpClassFile);
|
||||
affect.addClassDumpFile(dumpClassFile);
|
||||
} catch (IOException e) {
|
||||
logger.warn("dump class:{} to file {} failed.", className, dumpClassFile, e);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.taobao.arthas.core.util.affect;
|
||||
|
||||
import com.taobao.arthas.core.GlobalOptions;
|
||||
import com.taobao.arthas.core.util.ClassLoaderUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static java.lang.String.format;
|
||||
@@ -25,6 +27,8 @@ public final class EnhancerAffect extends Affect {
|
||||
*/
|
||||
private final Collection<File> classDumpFiles = new ArrayList<File>();
|
||||
|
||||
private final List<String> methods = new ArrayList<String>();
|
||||
|
||||
public EnhancerAffect() {
|
||||
}
|
||||
|
||||
@@ -48,6 +52,16 @@ public final class EnhancerAffect extends Affect {
|
||||
return mCnt.addAndGet(mc);
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录影响的函数,并增加计数
|
||||
* @param mc
|
||||
* @return
|
||||
*/
|
||||
public int addMethodAndCount(ClassLoader classLoader, String clazz, String method, String methodDesc) {
|
||||
this.methods.add(ClassLoaderUtils.classLoaderHash(classLoader) + "|" + clazz.replace('/', '.') + "#" + method + "|" + methodDesc);
|
||||
return mCnt.addAndGet(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取影响类个数
|
||||
*
|
||||
@@ -66,13 +80,8 @@ public final class EnhancerAffect extends Affect {
|
||||
return mCnt.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取dump的Class文件集合
|
||||
*
|
||||
* @return classDumpList
|
||||
*/
|
||||
public Collection<File> getClassDumpFiles() {
|
||||
return classDumpFiles;
|
||||
public void addClassDumpFile(File file) {
|
||||
classDumpFiles.add(file);
|
||||
}
|
||||
|
||||
public ClassFileTransformer getTransformer() {
|
||||
@@ -93,6 +102,12 @@ public final class EnhancerAffect extends Affect {
|
||||
infoSB.append("[dump: ").append(classDumpFile.getAbsoluteFile()).append("]\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (GlobalOptions.verbose && !methods.isEmpty()) {
|
||||
for (String method : methods) {
|
||||
infoSB.append("[Affect method: ").append(method).append("]\n");
|
||||
}
|
||||
}
|
||||
infoSB.append(format("Affect(class count:%d , method count:%d) cost in %s ms.",
|
||||
cCnt(),
|
||||
mCnt(),
|
||||
|
||||
Reference in New Issue
Block a user