package eu.dnetlib.r2d2;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.LoggerFactory;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.perf4j.LoggingStopWatch;
import org.perf4j.StopWatch;
import org.perf4j.commonslog.CommonsLogStopWatch;
import org.perf4j.log4j.Log4JStopWatch;
import org.perf4j.slf4j.Slf4JStopWatch;

@Aspect
public class DaoProfilingAspect {
	private static final Log log = LogFactory.getLog(DaoProfilingAspect.class); // NOPMD by marko on 11/24/08 5:02 PM

	@Around("daoMethod() || scholarlynk()")
	public Object profile(ProceedingJoinPoint pjp) throws Throwable {

		StopWatch stopWatch = ProfilingLogger.newStopWatch(pjp);
		try {
			Object retVal = pjp.proceed();
			return retVal;
		} finally {
			stopWatch.stop();
		}

	}

	@Pointcut("within(eu.dnetlib.r2d2.neo4j.dao.Neo4J*Dao)")
	public void daoMethod() {
	}
	
	@Pointcut("execution(* eu.dnetlib.r2d2.ScholarlynkImpl.*(..))")
	public void scholarlynk() {
	}
	
//	@Pointcut("execution(* eu.dnetlib.r2d2.accesstime.AccessTimeSaver.*(..))")
//	public void accessTimeSaving() {
//	}
}
