EnhancerAffect print the affected method details when verbose option is true #1195

pull/1200/head
hengyunabc 5 years ago
parent 8c18fe430d
commit eb62e0dec2

@ -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();
}
/**
* dumpClass
*
* @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(),

Loading…
Cancel
Save