update apm-demo

4.0.x
hengyunabc 6 years ago
parent 0583674677
commit 23bec40769

@ -19,6 +19,25 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>arthas-apm-demo</finalName> <finalName>arthas-apm-demo</finalName>
@ -33,31 +52,39 @@
<showDeprecation>true</showDeprecation> <showDeprecation>true</showDeprecation>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId>
<artifactId>maven-assembly-plugin</artifactId>
<executions> <executions>
<execution> <execution>
<phase>package</phase>
<goals> <goals>
<goal>single</goal> <goal>shade</goal>
</goals> </goals>
<phase>package</phase>
<configuration> <configuration>
<descriptorRefs> <createSourcesJar>true</createSourcesJar>
<descriptorRef>jar-with-dependencies</descriptorRef> <shadeSourcesContent>true</shadeSourcesContent>
</descriptorRefs> <artifactSet>
<archive> </artifactSet>
<manifestEntries> <relocations>
<Specification-Title>${project.name}</Specification-Title> <relocation>
<Specification-Version>${project.version}</Specification-Version> <pattern>org.slf4j</pattern>
<Implementation-Title>${project.name}</Implementation-Title> <shadedPattern>${arthas.deps.package}.org.slf4j</shadedPattern>
<Implementation-Version>${project.version}</Implementation-Version> </relocation>
</manifestEntries> <relocation>
</archive> <pattern>ch.qos.logback</pattern>
<shadedPattern>${arthas.deps.package}.ch.qos.logback</shadedPattern>
</relocation>
<relocation>
<pattern>logback.configurationFile</pattern>
<shadedPattern>arthas.logback.configurationFile</shadedPattern>
</relocation>
</relocations>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

@ -1,26 +1,28 @@
package com.taobao.arthas.demo.plugin; package com.taobao.arthas.demo.plugin;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException; import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain; import java.security.ProtectionDomain;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode; import com.alibaba.arthas.deps.org.objectweb.asm.tree.ClassNode;
import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode; import com.alibaba.arthas.deps.org.objectweb.asm.tree.MethodNode;
import com.taobao.arthas.bytekit.asm.MethodProcessor; import com.taobao.arthas.bytekit.asm.MethodProcessor;
import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor; import com.taobao.arthas.bytekit.asm.interceptor.InterceptorProcessor;
import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser; import com.taobao.arthas.bytekit.asm.interceptor.parser.DefaultInterceptorClassParser;
import com.taobao.arthas.bytekit.utils.AsmUtils; import com.taobao.arthas.bytekit.utils.AsmUtils;
import com.taobao.arthas.bytekit.utils.Decompiler;
import com.taobao.arthas.bytekit.utils.MatchUtils; import com.taobao.arthas.bytekit.utils.MatchUtils;
import com.taobao.arthas.plugin.Plugin; import com.taobao.arthas.plugin.Plugin;
import com.taobao.arthas.plugin.PluginActivator; import com.taobao.arthas.plugin.PluginActivator;
import com.taobao.arthas.plugin.PluginContext; import com.taobao.arthas.plugin.PluginContext;
public class DemoPluginActivator implements PluginActivator{ public class DemoPluginActivator implements PluginActivator {
private static final Logger logger = LoggerFactory.getLogger("arthas.apm.demo");
@Override @Override
public boolean enabled(PluginContext context) { public boolean enabled(PluginContext context) {
@ -29,10 +31,8 @@ public class DemoPluginActivator implements PluginActivator{
@Override @Override
public void start(PluginContext context) { public void start(PluginContext context) {
Plugin plugin = context.getPlugin(); Plugin plugin = context.getPlugin();
logger.info("start apm demo, plugin name: {}", plugin.getName());
System.err.println("hello" + plugin.getName());
context.getInstrumentation().addTransformer(new ClassFileTransformer() { context.getInstrumentation().addTransformer(new ClassFileTransformer() {
@ -41,13 +41,14 @@ public class DemoPluginActivator implements PluginActivator{
ProtectionDomain protectionDomain, byte[] classfileBuffer) ProtectionDomain protectionDomain, byte[] classfileBuffer)
throws IllegalClassFormatException { throws IllegalClassFormatException {
if(!className.equals("demo/MathGame")) { if (!className.equals("demo/MathGame")) {
return null; return null;
} }
DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser(); DefaultInterceptorClassParser defaultInterceptorClassParser = new DefaultInterceptorClassParser();
List<InterceptorProcessor> interceptorProcessors = defaultInterceptorClassParser.parse(EnterInterceptor.class); List<InterceptorProcessor> interceptorProcessors = defaultInterceptorClassParser
.parse(EnterInterceptor.class);
ClassNode classNode = AsmUtils.toClassNode(classfileBuffer); ClassNode classNode = AsmUtils.toClassNode(classfileBuffer);
@ -71,24 +72,17 @@ public class DemoPluginActivator implements PluginActivator{
byte[] bytes = AsmUtils.toBytes(classNode); byte[] bytes = AsmUtils.toBytes(classNode);
// try {
// String decompile = Decompiler.decompile(bytes);
// System.err.println(decompile);
// } catch (Throwable e) {
// e.printStackTrace();
// }
return bytes; return bytes;
} }
}); });
} }
@Override @Override
public void stop(PluginContext context) { public void stop(PluginContext context) {
// TODO Auto-generated method stub Plugin plugin = context.getPlugin();
logger.info("start apm demo, plugin name: {}", plugin.getName());
} }
} }

@ -56,7 +56,7 @@
<destName>plugins/core/conf/arthas-plugin.properties</destName> <destName>plugins/core/conf/arthas-plugin.properties</destName>
</file> </file>
<file> <file>
<source>../apm-demo/target/arthas-apm-demo-jar-with-dependencies.jar</source> <source>../apm-demo/target/arthas-apm-demo.jar</source>
<destName>plugins/apm-demo/lib/apm-demo.jar</destName> <destName>plugins/apm-demo/lib/apm-demo.jar</destName>
</file> </file>
<file> <file>

Loading…
Cancel
Save