#7 add super class interceptor

This commit is contained in:
Jaehong Kim
2014-11-03 11:27:01 +09:00
parent 2ce83eeb3f
commit 84f8903df5
6 changed files with 210 additions and 0 deletions
@@ -0,0 +1,35 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import java.security.ProtectionDomain;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentException;
import com.nhn.pinpoint.profiler.interceptor.bci.NotFoundInstrumentException;
/**
* jedis(redis client) modifier
*
* @author jaehong.kim
*
*/
public class BinaryJedisModifier extends JedisModifier {
public BinaryJedisModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "redis/clients/jedis/BinaryJedis";
}
@Override
protected void beforeAddInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, final InstrumentClass instrumentClass) throws NotFoundInstrumentException, InstrumentException {
// trace endPoint.
instrumentClass.addTraceValue(MapTraceValue.class);
}
}
@@ -0,0 +1,22 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
/**
* RedisCluster(nBase-ARC client) modifier
*
* @author jaehong.kim
*
*/
public class BinaryRedisClusterModifier extends RedisClusterModifier {
public BinaryRedisClusterModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "com/nhncorp/redis/cluster/BinaryRedisCluster";
}
}
@@ -0,0 +1,34 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import java.security.ProtectionDomain;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.bootstrap.interceptor.tracevalue.MapTraceValue;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentException;
import com.nhn.pinpoint.profiler.interceptor.bci.NotFoundInstrumentException;
/**
* RedisCluster(nBase-ARC client) modifier
*
* @author jaehong.kim
*
*/
public class BinaryTriplesRedisClusterModifier extends RedisClusterModifier {
public BinaryTriplesRedisClusterModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "com/nhncorp/redis/cluster/triples/BinaryTriplesRedisCluster";
}
@Override
protected void beforeAddInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, final InstrumentClass instrumentClass) throws NotFoundInstrumentException, InstrumentException {
// trace destinationId, endPoint
instrumentClass.addTraceValue(MapTraceValue.class);
}
}
@@ -0,0 +1,22 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
/**
* jedis(redis client) pipeline modifier
*
* @author jaehong.kim
*
*/
public class JedisMultiKeyPipelineBaseModifier extends JedisPipelineBaseModifier {
public JedisMultiKeyPipelineBaseModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "redis/clients/jedis/MultiKeyPipelineBase";
}
}
@@ -0,0 +1,75 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import java.security.ProtectionDomain;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.bootstrap.interceptor.Interceptor;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentClass;
import com.nhn.pinpoint.profiler.interceptor.bci.InstrumentException;
import com.nhn.pinpoint.profiler.interceptor.bci.Method;
import com.nhn.pinpoint.profiler.interceptor.bci.NotFoundInstrumentException;
import com.nhn.pinpoint.profiler.modifier.AbstractModifier;
import com.nhn.pinpoint.profiler.modifier.redis.filter.JedisPipelineMethodNames;
import com.nhn.pinpoint.profiler.modifier.redis.filter.NameBasedMethodFilter;
/**
* jedis(redis client) pipeline modifier
*
* @author jaehong.kim
*
*/
public class JedisPipelineBaseModifier extends AbstractModifier {
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
public JedisPipelineBaseModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "redis/clients/jedis/PipelineBase";
}
@Override
public byte[] modify(ClassLoader classLoader, String className, ProtectionDomain protectedDomain, byte[] classFileBuffer) {
if (logger.isInfoEnabled()) {
logger.info("Modifing. {}", className);
}
byteCodeInstrumentor.checkLibrary(classLoader, className);
try {
final InstrumentClass instrumentClass = byteCodeInstrumentor.getClass(className);
beforeAddInterceptor(classLoader, protectedDomain, instrumentClass);
// method
addMethodInterceptor(classLoader, protectedDomain, instrumentClass);
return instrumentClass.toBytecode();
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to modifier. caused={}", e.getMessage(), e);
}
}
return null;
}
protected void beforeAddInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, final InstrumentClass instrumentClass) throws NotFoundInstrumentException, InstrumentException {
// nothing
}
protected void addMethodInterceptor(ClassLoader classLoader, ProtectionDomain protectedDomain, final InstrumentClass instrumentClass) throws NotFoundInstrumentException, InstrumentException {
final List<Method> declaredMethods = instrumentClass.getDeclaredMethods(new NameBasedMethodFilter(JedisPipelineMethodNames.get()));
for (Method method : declaredMethods) {
final Interceptor methodInterceptor = byteCodeInstrumentor.newInterceptor(classLoader, protectedDomain, "com.nhn.pinpoint.profiler.modifier.redis.interceptor.JedisPipelineMethodInterceptor");
instrumentClass.addInterceptor(method.getMethodName(), method.getMethodParams(), methodInterceptor);
}
}
}
@@ -0,0 +1,22 @@
package com.nhn.pinpoint.profiler.modifier.redis;
import com.nhn.pinpoint.bootstrap.Agent;
import com.nhn.pinpoint.profiler.interceptor.bci.ByteCodeInstrumentor;
/**
* RedisCluster(nBase-ARC client) modifier
*
* @author jaehong.kim
*
*/
public class TriplesRedisClusterModifier extends RedisClusterModifier {
public TriplesRedisClusterModifier(ByteCodeInstrumentor byteCodeInstrumentor, Agent agent) {
super(byteCodeInstrumentor, agent);
}
@Override
public String getTargetClass() {
return "com/nhncorp/redis/cluster/triples/TriplesRedisCluster";
}
}