Skip to content

Commit

Permalink
Instrumenter to observe behavior of nodes with UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Sep 18, 2023
1 parent 7ba1621 commit 99cb39e
Show file tree
Hide file tree
Showing 10 changed files with 572 additions and 360 deletions.
28 changes: 28 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ type Unresolved_Symbol
scope : Any
scope self = get_unresolved_symbol_scope self.value

## ADVANCED
GROUP Metadata

Starts building an instrumentation for a given node
instrument : Instrumentor
instrument self = Instrumentor.Value (instrumentor_builtin "newBuilder" [ self.value ])

type Error
## PRIVATE
ADVANCED
Expand Down Expand Up @@ -561,3 +568,24 @@ get_short_type_name typ = @Builtin_Method "Meta.get_short_type_name"
- constructor: the constructor to get the declaring type of.
get_constructor_declaring_type : Any -> Any
get_constructor_declaring_type constructor = @Builtin_Method "Meta.get_constructor_declaring_type"

instrumentor_builtin op args = @Builtin_Method "Meta.instrumentor_builtin"

# Builder to create instrumentation for a function
type Instrumentor
Value impl
on_enter self (fn : Text -> Any | Nothing) =
instrumentor_builtin "onEnter" [ self.impl, fn ]
self
on_return self (fn : Text -> Any -> Nothing) =
instrumentor_builtin "onReturn" [ self.impl, fn ]
self
on_function self (fn : Text -> Any | Nothing) =
instrumentor_builtin "onFunction" [ self.impl, fn ]
self
on_exception self (fn : Any -> Nothing) =
instrumentor_builtin "onException" [ self.impl, fn ]
self
activate self =
instrumentor_builtin "activate" [ self.impl ]
self
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.enso.polyglot.debugger;

import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.instrumentation.EventBinding;
import com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory;
import com.oracle.truffle.api.interop.TruffleObject;
import java.util.UUID;

public interface IdExecutionService {
String INSTRUMENT_ID = "id-value-extractor";

public interface Callbacks {
/**
* Finds out previously computed result for given id. If a result is returned, then the
* execution of given node is skipped and the value is returned back.
*
* @param nodeId identification of the node to be computed
* @return {@code null} should the execution of the node be performed; any other value to skip
* the execution and return the value as a result.
*/
Object findCachedResult(UUID nodeId);

/**
* Notifies when an execution of a node is over.
*
* @param nodeId identification of the node to be computed
* @param result the just computed result
* @param isPanic was the result a panic?
* @param nanoElapsedTime how long it took to compute the result?
*/
void updateCachedResult(UUID nodeId, Object result, boolean isPanic, long nanoElapsedTime);

/**
* Notification when a returned value is a function.
*
* @param nodeId identification of the node to be computed
* @param result info about function call
* @return {@code null} should the execution of the node be performed; any other value to skip
* the execution and return the value as a result.
*/
Object onFunctionReturn(UUID nodeId, TruffleObject result);

/**
* Notification on an exception.
*
* @param e the reported exception
*/
void onExceptionalCallback(Exception e);
}

/**
* Attach a new event node factory to observe identified nodes within given function.
*
* @param module module that contains the code
* @param entryCallTarget the call target being observed.
* @param callbacks the interface to receive notifications
* @param timer the execution timer.
* @return a reference to the attached event node factory.
*/
EventBinding<ExecutionEventNodeFactory> bind(
TruffleObject module, CallTarget entryCallTarget, Callbacks callbacks, Object timer);
}
Loading

0 comments on commit 99cb39e

Please sign in to comment.