<html><head></head><body><div class="ydpee6aa264yahoo-style-wrap" style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div></div>
<div dir="ltr" data-setdir="false">On this topic, is there a way to attach instrumentation on the fly in a running system? That can give you a callback onentry and onexit? To profile wall time and perhap do conditional matching / stack trace inspection. To see which calls trigger the slow path for example.</div><div><br></div>
</div><div id="yahoo_quoted_0603051645" class="yahoo_quoted">
<div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
<div>
On Sunday, January 26, 2020, 12:46:57 p.m. EST, Michael Truog <mjtruog@gmail.com> wrote:
</div>
<div><br></div>
<div><br></div>
<div><div id="yiv8359412240"><div>
<div class="yiv8359412240yqt7851941327" id="yiv8359412240yqtfd82624"><div class="yiv8359412240moz-cite-prefix">On 1/26/20 4:58 AM, Frank Muller wrote:<br clear="none">
</div>
<blockquote type="cite">
</blockquote></div></div><div class="yiv8359412240yqt7851941327" id="yiv8359412240yqtfd05866"></div><div><div class="yiv8359412240yqt7851941327" id="yiv8359412240yqtfd81177"><span style="color:rgb(49,49,49);word-spacing:1px;">Hi everyone</span><br clear="none" style="color:rgb(49,49,49);word-spacing:1px;">
<br clear="none" 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 clear="none" style="color:rgb(49,49,49);word-spacing:1px;">
<span style="color:rgb(49,49,49);word-spacing:1px;">Let assume this
function:</span></div><br clear="none" style="color:rgb(49,49,49);word-spacing:1px;">
<br clear="none" style="color:rgb(49,49,49);word-spacing:1px;">
<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 rel="nofollow" shape="rect" class="yiv8359412240moz-txt-link-freetext" target="_blank" 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 clear="none">
</p>
Best Regards,<br clear="none">
Michael<br clear="none">
<br clear="none">
[1] Example type specification
<a rel="nofollow" shape="rect" class="yiv8359412240moz-txt-link-freetext" target="_blank" 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 clear="none">
[2] Example configuration of aspects
<a rel="nofollow" shape="rect" class="yiv8359412240moz-txt-link-freetext" target="_blank" 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><div class="yiv8359412240yqt7851941327" id="yiv8359412240yqtfd47645"><br clear="none">
</div></div></div></div>
</div>
</div></body></html>