forked from fanruan/design
Browse Source
1、替换 listener, 从而打印不同的逻辑 2、修复默认的 transformer 的问题。让 Designer-Analyzer 去处理默认的逻辑,而非 Fine-Analyzer 去处理feature/x
Harrison
3 years ago
10 changed files with 118 additions and 26 deletions
@ -0,0 +1,23 @@
|
||||
package com.fr.design.record.analyzer; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.net.bytebuddy.agent.builder.AgentBuilder; |
||||
import com.fr.third.net.bytebuddy.description.type.TypeDescription; |
||||
import com.fr.third.net.bytebuddy.dynamic.DynamicType; |
||||
import com.fr.third.net.bytebuddy.utility.JavaModule; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/03/08 |
||||
**/ |
||||
public class DesignerAnalyzerListener extends AgentBuilder.Listener.Adapter { |
||||
|
||||
@Override |
||||
public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded, DynamicType dynamicType) { |
||||
FineLoggerFactory.getLogger().debug("Designer-Analyzer transform successfully:{}", typeDescription); |
||||
} |
||||
|
||||
@Override |
||||
public void onError(String typeName, ClassLoader classLoader, JavaModule module, boolean loaded, Throwable throwable) { |
||||
FineLoggerFactory.getLogger().error("Designer-Analyzer transform error:" + typeName); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
|
||||
package com.fr.design.record.analyzer.advice; |
||||
|
||||
import com.fr.design.record.analyzer.DesignerAnalyzerAdvice; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.record.analyzer.Metrics; |
||||
import com.fr.third.net.bytebuddy.asm.Advice; |
||||
|
||||
import java.lang.reflect.Method; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/03/08 |
||||
**/ |
||||
public class TimeAdvice implements DesignerAnalyzerAdvice { |
||||
|
||||
|
||||
@Advice.OnMethodEnter |
||||
public static void onMethodEnter(@Advice.Local("startTime") Long startTime) { |
||||
|
||||
startTime = (System.currentTimeMillis()); |
||||
} |
||||
|
||||
@Advice.OnMethodExit(onThrowable = Exception.class) |
||||
public static void onMethodExit(@Advice.Origin Method method, |
||||
@Advice.Local("startTime") Long startTime) { |
||||
|
||||
Metrics metrics = method.getAnnotation(Metrics.class); |
||||
Object prefix; |
||||
String description = metrics.description(); |
||||
if ("".equals(description)) { |
||||
prefix = method.getDeclaringClass().getName() + "#" + method.getName(); |
||||
} else { |
||||
prefix = description; |
||||
} |
||||
FineLoggerFactory.getLogger().info("{} took {} ms.", prefix, System.currentTimeMillis() - startTime); |
||||
} |
||||
} |
@ -0,0 +1,25 @@
|
||||
package com.fr.design.record.analyzer.advice; |
||||
|
||||
import com.fr.intelli.record.MetricRegistry; |
||||
import com.fr.third.javax.persistence.Entity; |
||||
import com.fr.third.net.bytebuddy.asm.Advice; |
||||
import com.fr.third.net.bytebuddy.implementation.bytecode.assign.Assigner; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* created by Harrison on 2022/03/08 |
||||
**/ |
||||
public class TrackAdvice { |
||||
|
||||
@Advice.OnMethodExit(onThrowable = Exception.class) |
||||
public static void onMethodExit(@Advice.Return(readOnly = false, typing = Assigner.Typing.DYNAMIC) Object result) { |
||||
|
||||
if (result != null) { |
||||
Class clazz = result.getClass(); |
||||
if (clazz.getAnnotation(Entity.class) != null || result instanceof List) { |
||||
MetricRegistry.getMetric().submit(result); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue