Logtalk 2.29.1 files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1744 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -56,7 +56,7 @@ Events are automatically generated by the message sending mechanisms for each pu
|
||||
<h2>Profilers as monitors<a id="monitors"></a></h2>
|
||||
|
||||
<p>
|
||||
A monitor is an object that reacts whenever a spied event occurs. The monitor actions are defined by two event handlers: <a title="Consult reference manual" href="../refman/methods/before3.html"><code>before/3</code></a> for <code>before</code> events and <a title="Consult reference manual" href="../refman/methods/after3.html"><code>after/3</code></a> for <code>after</code> events. These predicates are automatically called by the message sending mechanisms when an event registered for the monitor occurs.
|
||||
A monitor is an object that reacts whenever a spied event occurs. The monitor actions are defined by two event handlers: <a title="Consult reference manual" href="../refman/methods/before3.html"><code>before/3</code></a> for <code>before</code> events and <a title="Consult reference manual" href="../refman/methods/after3.html"><code>after/3</code></a> for <code>after</code> events. These predicates are automatically called by the message sending mechanisms when an event registered for the monitor occurs. These event handlers are declared as public predicates in the <code>monitoring</code> built-in protocol.
|
||||
</p>
|
||||
<p>
|
||||
In our example, we need a way to get the current time before and after we process a message. We will assume that we have a <code>time</code> object implementing a <code>cpu_time/1</code> predicate that returns the current CPU time for the Prolog session:
|
||||
@@ -72,7 +72,8 @@ In our example, we need a way to get the current time before and after we proces
|
||||
<p>
|
||||
Our profiler will be named <code>stop_watch</code>. It must define event handlers for the <code>before</code> and <code>after</code> events that will print the event description (object, message, and sender) and the current time:
|
||||
</p>
|
||||
<pre>:- object(stop_watch).
|
||||
<pre>:- object(stop_watch,
|
||||
implements(monitoring)). % event handler predicate declarations
|
||||
|
||||
:- uses(time).
|
||||
|
||||
@@ -128,7 +129,7 @@ This call will abolish all events defined over the object <code>foo</code> assig
|
||||
<li>There are two kinds of events: <code>before</code> events, generated before a message is processed, and <code>after</code> events, generated after the message processing completed successfully.</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>Any object can be declared as a monitor to any event.</li>
|
||||
<li>Any object can be declared as a monitor to any event. A monitor shall reference the <code>monitoring</code> built-in protocol in the object opening directive.</li>
|
||||
</ul>
|
||||
<ul>
|
||||
<li>A monitor defines event handlers, the predicates <a title="Consult reference manual" href="../refman/methods/before3.html"><code>before/3</code></a> and <a title="Consult reference manual" href="../refman/methods/after3.html"><code>after/3</code></a>, that are automatically called by the runtime engine when a spied event occurs.</li>
|
||||
@@ -140,7 +141,7 @@ This call will abolish all events defined over the object <code>foo</code> assig
|
||||
<div class="footer">
|
||||
<div class="copyright">
|
||||
<span>Copyright © <a href="mailto:pmoura@logtalk.org">Paulo Moura</a> — <a href="http://logtalk.org">Logtalk.org</a></span><br/>
|
||||
<span>Last updated on: October 26, 2006</span>
|
||||
<span>Last updated on: December 11, 2006</span>
|
||||
</div>
|
||||
<div class="navbottom">
|
||||
<span><a href="reflection.html">previous</a> | <a href="../glossary.html">glossary</a> | <a href="index.html">next</a></span><br/>
|
||||
|
Reference in New Issue
Block a user