Last active
August 9, 2024 22:13
-
-
Save pavelfomin/38b59e044674e14bcee53d1d54b97980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lombok.extern.slf4j.Slf4j; | |
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.springframework.stereotype.Component; | |
@Aspect | |
@Component | |
@Slf4j | |
public class RepositoryProfilerAspect { | |
@Pointcut("execution(public * com.droidablebee.data.repository.*Repository.*(..))") | |
public void monitorRepositoryCalls() { | |
} | |
@Pointcut("execution(public * com.droidablebee.storage.StorageService.*(..))") | |
public void monitorStorageCalls() { | |
} | |
@Around("monitorRepositoryCalls() || monitorStorageCalls()") | |
public Object profile(ProceedingJoinPoint pjp) throws Throwable { | |
long start = System.currentTimeMillis(); | |
Object result = pjp.proceed(); | |
String args = StringUtils.truncate(Arrays.asList(pjp.getArgs()).toString()); | |
log.debug("Method: {}, args: {}, elapsed: {}ms", pjp.getSignature(), args, System.currentTimeMillis() - start); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment