Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] AspectJ profiling

Hi,

These examples might help too:

[1] http://dev.eclipse.org/viewcvs/index.cgi/org.aspectj/modules/tests/product/testScripts/cmdline11/profile/Profile.java?rev=HEAD&cvsroot=Technology_Project&content-type=text/vnd.viewcvs-markup
--------------------------------------------------------------------------------------------------------
package profile;

import org.aspectj.lang.*;

/**
 * Profile execution time of join points
 * by making a concrete aspect which defines <tt>targets()</tt>,
 * if not <code>register(JoinPoint)</code>
 * and <code>signal(Object, long, long)</code>.
 */
public abstract aspect Profile {

    /**
     * Identify join points to profile.
     * Those within the lexical extent of Profile
     * or its subtypes will be excluded from profiling.
     */
    protected abstract pointcut targets();

    Object around() : targets() && !within(Profile+) {
        final Object key = register(thisJoinPoint);
        final long startTime = System.currentTimeMillis();
        try {
            return proceed();
        } finally {
            signal(key, startTime, System.currentTimeMillis());
        }
    }
    protected Object register(JoinPoint jp) {
        return Thread.currentThread().getName() + " -- " + jp;
    }
    protected void signal(Object key, long start, long end) {
        long duration = end - start;
        String tag = (duration == 0 ? "none" : duration < 100 ? "fast"
: "slow");
        //System.err.println(duration + " " + start + " - " + end + ": " + key);
        System.err.println(tag + ": " + key);
    }
}

[2] http://dev.eclipse.org/viewcvs/index.cgi/org.aspectj/modules/tests/product/testScripts/cmdline11/myprofile/MyProfile.java?rev=HEAD&cvsroot=Technology_Project&content-type=text/vnd.viewcvs-markup
--------------------------------------------------------------------------------------------------------
package myprofile;

import profile.Profile;

public aspect MyProfile extends Profile {
    protected pointcut withinSystemClasses() :
        within(java..*) || within(javax..*) || within(com.sun..*);

    /** blunt: target all method executions outside system classes */
    protected pointcut targets() : !withinSystemClasses()
        && execution(* *(..));
}

Regards,
Eduardo

On 3/13/06, Ramnivas Laddad <ramnivas@xxxxxxxxxxxxxxx> wrote:
> Thanks for your positive comments about AspectJ in Action.
>
> See Glassbox Inspector for a profiling solution using AspectJ:
> https://glassbox-inspector.dev.java.net/
>
> -Ramnivas
>
> Raphael Paiva wrote:
> > Someone have a simple Profiling implemented with AspectJ?
> >
> > I read AspectJ in Action(a very good book) and there the
> > author(Ramnivas Laddad) talk about Profiling..
> > I´m search samples in net but i´m don´t finding. :(
> >
> > Can someone help me?
> >
> > Thanks,
> > Raphael Paiva
> >
> >
> > _______________________________________________________
> > Yahoo! Acesso Grátis - Internet rápida e grátis. Instale o discador
> > agora!
> > http://br.acesso.yahoo.com
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
> >
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top