Skip to content

Instantly share code, notes, and snippets.

@LectomT
Created July 14, 2015 04:30
Show Gist options
  • Save LectomT/91f783b2e3ebc19c300f to your computer and use it in GitHub Desktop.
Save LectomT/91f783b2e3ebc19c300f to your computer and use it in GitHub Desktop.
"이 옵션은 트랜잭션에서 수행되는 메소드 성능 추적이나 특정 메소드에 대한 추적 작업을 사용자 정의로 구현하기 위해 사용한다.
package jennifer.base.profile;
public interface IAdapterCustomMethod
{
public Object start(int originHash, String originFullDescriptor, int hash, String fullDescriptor, Parameter parameter);
public void end(Object returnValue, Object stat, Throwable throwable);
}
메소드 설명
---------------
start(int originHash, String originFullDescriptor, int hash, String fullDescriptor, Parameter parameter)
: 메소드의 시작 시점에 삽입되어 호출되는 메소드이다.
일반적으로 트랜잭션의 수행중에 메소드 성능 추적이나 특정 메소드에 대한 추적을 커스터 마이징 하기위해 사용되기 때문에 구현시에 ActiveObject 에 대한 체크를 해야 한다.
end(Object returnValue, Object stat, Throwable throwable)
: 메소드의 종료 시점에 삽입되어 호출되는 메소드이다.
stat 정보는 start 에서 리턴되는 PiMethod 정보인데 예외로 null 이 리턴 될 수도 있으므로 구현시에 주의 해야 한다.
샘플 구현
---------------
public class SampleCustomMethod implements IAdapterCustomMethod
{
private final ActiveObjectMeter activeObjectMeter = ActiveObjectMeter.getInstance();
private long getCurrentThreadCpuTime(long startCpu)
{
if (ConfigValue.profile_method_cpu)
{
return SysPerf.getCurrentThreadCpuTime() - startCpu;
}
return -1;
}
public Object start(int originHash, String originFullDescriptor, int hash, String fullDescriptor, Parameter parameter)
{
ActiveObject activeObject = activeObjectMeter.get();
if (activeObject != null)
{
PiMethod profileMethod = new PiMethod();
profileMethod.key = originHash;
profileMethod.stime = (int) (System.currentTimeMillis() - activeObject.startTime);
profileMethod.scpu = (int) getCurrentThreadCpuTime(activeObject.startCpu);
AgentText.addMethod(originHash, originFullDescriptor);
activeObject.pushProfile(profileMethod);
return pi;
}
return null;
}
public void end(Object returnValue, Object stat, Throwable throwable)
{
if (stat != null)
{
ActiveObject activeObject = activeObjectMeter.get();
if (activeObject != null)
{
PiMethod profileMethod = (PiMethod) stat;
profileMethod.time = (int) (System.currentTimeMillis() - activeObject.startTime) - profileMethod.stime;
profileMethod.cpu = (int) (getCurrentThreadCpuTime(activeObject.startCpu)) - profileMethod.scpu;
if (throwable != null)
{
String err = ProfileAdapter.getMethod().catchError(throwable);
if (err == null)
{
err = throwable.toString();
}
if (err != null)
{
ActiveObjectErrorRaiser.raise(activeObject, ErrorTypeDef.METHOD_EXCEPTION, err, false);
}
}
activeObject.popProfile(profileMethod);
}
}
}
}
**설정방법**
어뎁터를 구현한 클래스를 jennifer.impl.XXX.jar 형태로 jennifer.jar 와 동일한 위치에 놓으면 별도의 설정 없이 해당 라이브러리를 자동으로 인식한다.
버전관리를 위해서 jennifer.impl.custom-1.0.1.jar 와 같은 형식을 사용하면 편리하다.
jennifer.runtime.custom.SampleCustomMethod
* 기본값 : 없음
* 형식 : 문자열
* 재시작 : 안함
* 지원 버전 : 5.0.8"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment