[erlang-questions] Instrumentation

Tim Watson watson.timothy@REDACTED
Mon Dec 5 13:14:42 CET 2011


Hi Michal,

I did look at ennotation, it was one of those places I found inspiration! :)

One of the things I wanted to do was move away from macros towards module
attributes instead. These are discoverable at runtime (using
Mod:module_info/1) which makes them available for other tools to use as
well. I also find reading a module annotation a bit easier on the eye than
a macro, although obviously that's just a personal preference. I also
preserve the original code (by renaming and re-exporting the function),
which means that during tracing, debugging, logging, etc - the module in
which the originating code lives (i.e., the annotation callback module vs
the annotated production code) is preserved, which I find preferable.

Another thing I wanted to do (which I mentioned in the previous post) is
provide match specification based mappings between annotations and code,
and to provide an API for runtime code instrumentation as well as the
option of doing it at compile time with a parse transform.

As you've built a conceptually very similar framework (which is much more
mature than my effort) I would be very keen to hear your thoughts about
whether declarative weaving/advising might be useful!

Cheers,

Tim

On 5 December 2011 11:08, Michał Ptaszek <
michal.ptaszek@REDACTED> wrote:

> Hi Tim,
>
> you might want to take a look at ennotation: it's
> something I've derived from erlang-web, but which has
> been reimplemented from scratch.
>
> https://github.com/paulgray/ennotation
>
> Best regards,
> Michal Ptaszek
>
>
> ----- Original Message -----
> > There have been a few conversations about instrumentation libraries
> > on the
> > list, and I've been experimenting with the features Ulf recently
> > added to
> > parse_trans. I've worked up a simple annotations library, that let's
> > you
> > put attributes/annotations on specific functions and attach behaviour
> > to
> > them in the form of an implementation module. The current framework
> > is very
> > crude and relies on a compile time parse transform, though obviously
> > it'll
> > be relatively trivial to implement runtime code changes as well.
> >
> > The purpose of this prototyping was to play around with some of the
> > ideas
> > in Aspect Oriented Programming, and the library allows you to write
> > code
> > that executes before, after or around an annotated function. This is
> > done
> > without macros, which feels a bit neater to me than the approach used
> > in
> > erlang-web. In addition to the library, I've made a small reference
> > project
> > which implements a simple function memoization annotation using ets
> > as a
> > cache. The implementation of the annotation itself is very simple:
> >
> > -module(memoize).
> > -annotation('function').  %% scoped to functions
> > -export([init/1]).
> > -export([around_advice/4]).
> >
> > init(Module) ->
> >     ets:new(Module, [ordered_set, public, named_table,
> >                      {write_concurrency,true},
> >                      {read_concurrency,true}, compressed]),
> >     ok.
> >
> > around_advice(_A, M, F, Inputs) ->
> >     case ets:lookup(M, {F, Inputs}) of
> >         [] ->
> >             Result = annotation:call_advised(M, F, Inputs),
> >             true = ets:insert_new(M, {{F, Inputs}, Result}),
> >             Result;
> >         [{_, Memoized}] ->
> >             Memoized
> >     end.
> >
> > And the usage of the annotation is very simple too:
> >
> > -module(fib_mem).
> > -export([start_memoize/0, fib/1]).
> > -include_lib("annotations/include/annotations.hrl").
> >
> > start_memoize() ->
> >     memoize:init(?MODULE).
> >
> > -memoize(ets).
> > fib(0) -> 0;
> > fib(1) -> 1;
> > fib(N) -> fib(N - 1) + fib(N - 2).
> >
> > --------------------
> >
> > As I said, the implementation is very crude but I hope that the
> > concepts
> > will trigger some discussion about whether this is a useful
> > contribution
> > and in what directions it ought to go.
> >
> > Code is here: https://github.com/hyperthunk/annotations
> > Memoize is here: https://github.com/nebularis/memoize
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20111205/9c5eda47/attachment.htm>


More information about the erlang-questions mailing list