Android Open Source - AspectJ-Android-Example Profiling Aspect






From Project

Back to project page AspectJ-Android-Example.

License

The source code is released under:

Apache License

If you think the Android project AspectJ-Android-Example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package android.mobile.peakgames.net.aspectjandroid.aspect;
/*  w w  w  . j  a va  2  s .com*/
import android.util.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class ProfilingAspect {
    private static final String TAG = ProfilingAspect.class.getName();
    private static final long MAX_ELAPSED_TIME = 1000;

    @Pointcut("execution(String android.mobile.peakgames.net.aspectjandroid.AspectActivity.doHttpCall(..))")
    public void doHttpCallEntryPoint() {
    }

    @Pointcut("execution(* android.mobile.peakgames.net.aspectjandroid.AspectActivity.fetchImage(..))")
    public void loadImageEntryPoint() {
    }

    @Around("doHttpCallEntryPoint() || loadImageEntryPoint()")
    public Object doHttpCallMethod(ProceedingJoinPoint joinPoint) {
        Object returnValue = null;

        long beginTime = System.currentTimeMillis();
        try {
            returnValue = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        long endTime = System.currentTimeMillis();
        long elapsedTime = (endTime - beginTime);

        Log.d(TAG, joinPoint.getSignature().getName() + " elapsed " + elapsedTime + " ms");
        if (MAX_ELAPSED_TIME < elapsedTime) {
            Log.e(TAG, joinPoint.getSignature() + " exceeded MAX_ELAPSED_TIME, the process is taking too much time");
        }

        return returnValue;
    }
}




Java Source Code List

android.mobile.peakgames.net.aspectjandroid.ApplicationTest.java
android.mobile.peakgames.net.aspectjandroid.AspectActivity.java
android.mobile.peakgames.net.aspectjandroid.SecureMethod.java
android.mobile.peakgames.net.aspectjandroid.Session.java
android.mobile.peakgames.net.aspectjandroid.aspect.AuthenticationAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.CachingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ExceptionHandlingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.LoggingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ProfilingAspect.java
android.mobile.peakgames.net.aspectjandroid.exception.AuthenticationException.java