harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexei Zakharov" <alexei.zakha...@gmail.com>
Subject Re: [classlib] Using Aspects for Tracing
Date Wed, 15 Nov 2006 12:32:07 GMT
> I'm not entirely sure what you mean by application-level logging.

Well, I mean the situation when log calls are scattered around the
code. Something like this:

---
void dataExchange() throws Exception {
    boolean handshakePerformed = false;

    log("in performConnection"); // log point 1
    ...
    for (int i = 0; i < 5; i++) {
         int k = performHandshake();

         if (k == NEED_MORE_DATA) {
             log("server responded: needs more data"); // log point 2
             addSomeDataForServer();
         } else if (k == NEED_MORE_SECURITY) {
             log("server responded: needs more security"); // log point 3
             addMoreSecurity();
         } else if (k == OK) {
             handshakePerformed = true;
             log("handshake OK"); // log point 4
             break;
         }
    }

    if (!handshakePerformed) {
        log("give up: unable to handshake"); // log point 5
        throw new Exception("unable to handshake");
    }

    log("ready to send data"); // log point 6
    ....
    log("leaving performConnection"); // log point 7
}
---

>From your explanation I've understood that aspects can be used for
points one and seven. Is it possible to cover other log points with
aspects? What should be done for this (if so)?

Thanks,

2006/11/14, Sian January <sianjanuary@googlemail.com>:
> Hi Alexei,
>
> I'm not entirely sure what you mean by application-level logging.  It is
> possible to get more fine-grained information using aspects if that's what
> you mean, such as tracing individual methods, logging field reads and
> writes, logging when Exceptions are caught and logging when certain methods
> are called and where from.  You can't use aspects to add logging into the
> middle of a method, unless it's at a well defined point.  If there was some
> specific information you wanted to add at a specific place there's no
> problem using a combination of aspects and hand-coded logging.  Does that
> answer your question at all?
>
> Thanks,
>
> Sian
>
>
> On 14/11/06, Alexei Zakharov <alexei.zakharov@gmail.com> wrote:
> >
> > Sian,
> >
> > Cool! Thanks for this. Can AspectJ be used for something more
> > sophisticated than just tracing? For application-level logging for
> > example?
> >
> > Thanks,
> >
> > 2006/11/14, Sian January <sianjanuary@googlemail.com>:
> > > Hello,
> > >
> > > Following a recent discussion on this list I have been looking into how
> > > aspects could be used for tracing in the Harmony class library code.  I
> > have
> > > been using AspectJ and have written a really simple tracing aspect for
> > the
> > > math module, adapted the build.xml script and written some instructions
> > on
> > > how to apply it.  At the moment the aspect just does entry and exit
> > tracing
> > > and prints to System.out, but this is because it's a first draft - it is
> > > possible to do more targeted tracing and to use frameworks such as
> > > java.util.logging with aspects.
> > >
> > > Steps to follow:
> > >
> > >
> > > 1. Download AspectJ from
> > > http://www.eclipse.org/aspectj/downloads.php
> > >
> > > 2. Copy aspectjrt.jar to /depends/jars/aspectj/
> > >
> > > 3. Copy aspectjtools.jar and aspectjrt.jar to ANT_HOME/lib and if using
> > > Eclipse add both of these to your ant runtime configuration (Window >
> > > Preferences > Ant > Runtime > Add...)
> > >
> > > 4. Edit build file to use iajc* instead of javac and include aspect
> > class
> > > files (or apply the buildxmlpatch.txt to build.xml in the math module)
> > >
> > > 5. Write a tracing aspect (or copy the one attached to
> > > modules\math\src\main\java\org\apache\harmony\tracing)
> > >
> > > 6. Re-build the module
> > >
> > > 7. Make sure to add aspectjrt.jar to the runtime classpath of whatever
> > > program you are running.
> > >
> > >
> > > * - iajc isn't incremental like javac in ant, it will always do a total
> > > rebuild.  Also if you switch from using iajc back to javac you will need
> > to
> > > do a clean before you do a rebuild.
> > > Please also note that it's not possible to use this kind of tracing for
> > any
> > > classes that are depended on by the AspectJ runtime or there will be
> > errors
> > > initializing the classes because of circular dependencies.  However I
> > think
> > > most modules apart from luni should be safe.  Also it's important to not
> > > trace methods that are called (directly or indirectly) by your tracing
> > > methods otherwise you will end up in an endless loop.
> > >
> > > If anyone thinks this information might be useful to have available
> > > somewhere I would be happy to expand it a bit for a web page or a Wiki
> > page.


-- 
Alexei Zakharov,
Intel Enterprise Solutions Software Division

Mime
View raw message