>  I'll also mention that I don't want to weave rt.jar.

Shame, that would make it rather easy with a pointcut on execution of
FileInputStream+.read(..).

I can imagine your proxy route might work. You can advise the constructor
calls to the various FilterInputStream and FilterOutputStreams, and there
return a proxy with an additional marker interface. Sounds pretty messy
compared to what you are already doing though...  There isn't anything
special in AspectJ to help here, simply around advice on the constructor call
to 'new' and then use cglib to generate the tagged proxy.  If some of those
constructor calls are made inside rt.jar though, you won't be catching
them. (similar to now where you won't be catching calls to read that are
made inside classes within rt.jar)

cheers,
Andy


On 6 November 2013 14:29, Jonathan Mace <[email protected]> wrote:

> Hi everyone,
>
> Love AspectJ.  I work on end-to-end tracing using X-Trace, and AspectJ is
> an awesome mechanism to do some of the tracing that I'm interested in.
>
> I'm trying to profile file accesses; specifically, calls to
> FileInputStream+.read(..) and FileOutputStream+.write(..).  However, in
> many cases, file streams are wrapped in filter classes, such as Buffered
> streams or Data streams.  The specific base classes that provide this
> mechanism are FilterInputStream and FilterOutputStream.  Often, multiple
> filter streams are applied recursively to some base stream, for example new
> DataOutputStream(new BufferedOutputStream(new
> FileOutputStream("myfile.txt")));
>
> Is there a way to define a pointcut that matches any Filter stream, whose
> underlying stream is a File stream?  The naive solution I have so far is:
>
>   Object around(FilterInputStream o): target(o) && call(*
> FilterInputStream+.read(..)) {
>     InputStream base = o;
>     while (base instanceof FilterInputStream)
>       base = ((FilterInputStream) base).in;
>     boolean isFileStream = base instanceof FileInputStream;
>
>     if (isFileStream) {
>       long start = System.nanoTime();
>       Object ret = proceed(o);
>       long duration = System.nanoTime() - start;
>       // do profiling stuff
>       return ret;
>     } else {
>       return proceed(o);
>     }
>   }
>
> I'm worried about the overhead of recursively examining the filter streams
> to determine whether the base stream is a file stream.  I'll also mention
> that I don't want to weave rt.jar.  It would be great if I could insert
> some kind of proxy class when the appropriate Filter instance is created,
> then the pointcut can just look for the proxy class.
>
> Cheers,
>
> Jon
>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users

Reply via email to