<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-cite-prefix">On 1/26/20 4:58 AM, Frank Muller wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAFA6GnAHSsa1+VXipn_Fq1NnPg_nx3mdtS8N2GUx3s8jGJkS3A@mail.gmail.com">
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<span style="color:rgb(49,49,49);word-spacing:1px">Hi everyone</span><br
style="color:rgb(49,49,49);word-spacing:1px">
<br style="color:rgb(49,49,49);word-spacing:1px">
<span style="color:rgb(49,49,49);word-spacing:1px">I would like to
implement a custom instrumentation module for my Erlang code.</span><br
style="color:rgb(49,49,49);word-spacing:1px">
<span style="color:rgb(49,49,49);word-spacing:1px">Let assume this
function:</span><br style="color:rgb(49,49,49);word-spacing:1px">
<br style="color:rgb(49,49,49);word-spacing:1px">
</blockquote>
<p>You are describing that you need aspects from aspect oriented
programming (that should be the best concept for what you want,
when thinking about the problem). I implemented this in CloudI
(<a class="moz-txt-link-freetext" href="https://cloudi.org">https://cloudi.org</a>) as a list of functions that are executed in
order with separate lists for before and after a callback
function. My approach used the following to represent a function
[1]:</p>
<p>{Module :: atom(), Function :: atom()}</p>
<p>to represent a function of the expected arity (call it arity N),
and:</p>
<p>{{Module :: atom(), Function :: atom()}}</p>
<p>to represent a function of arity 0 that returns a function of
arity N, or a normal Erlang function. Representing the function
as a tuple with atoms allows specifying the function before it is
loaded. Using the arity 0 function indirection allows execution
of source code before the function is created, normally when a
function retains variables created before the function is created
(a closure). Using this approach made it easy to add monitoring
to CloudI services and other things like batch execution of CloudI
services.</p>
<p>Using functions as data (configuration for the source code [2])
avoids source code that lacks transparency, like macros or parse
transforms.<br>
</p>
Best Regards,<br>
Michael<br>
<br>
[1] Example type specification
<a class="moz-txt-link-freetext" href="https://github.com/CloudI/CloudI/blob/7cac9108827ce58008eac7aa24e192c44e2fbfd6/src/lib/cloudi_core/src/cloudi_service_api.erl#L203-L205">https://github.com/CloudI/CloudI/blob/7cac9108827ce58008eac7aa24e192c44e2fbfd6/src/lib/cloudi_core/src/cloudi_service_api.erl#L203-L205</a><br>
[2] Example configuration of aspects
<a class="moz-txt-link-freetext" href="https://github.com/CloudI/CloudI/blob/7cac9108827ce58008eac7aa24e192c44e2fbfd6/src/lib/cloudi_core/src/cloudi_service_api.erl#L429-L434">https://github.com/CloudI/CloudI/blob/7cac9108827ce58008eac7aa24e192c44e2fbfd6/src/lib/cloudi_core/src/cloudi_service_api.erl#L429-L434</a><br>
</body>
</html>