Skip to content

Insight scripts

The insight object available to scripts loaded with Elide's --insights flag: the source, enter and return events, their filters, and what each handler receives.

On this page

An Insight script runs before the program and subscribes to its execution events. Load one with the repeatable --insights <FILE> option:

Terminal
bash
elide run --insights=trace.js app.js
javascript
// trace.js
insight.on("enter", (ctx, frame) => {
  console.log("enter", ctx.name, JSON.stringify(frame));
}, { roots: true, rootNameFilter: "add" });

insight.on("return", (ctx, frame) => {
  console.log("return", ctx.name, ctx.returnValue(frame));
}, { roots: true, rootNameFilter: "add" });
utf-8 · javascript · Lines: 8

For function add(a, b) { return a + b; } called as add(1, 2), this prints enter add {"a":1,"b":2,"this":{}} and return add 3.

Events

EventFires whenHandler arguments
sourcea source file is loaded(source) with name, characters, uri
entera matching function, statement or expression starts(ctx, frame)
returna matching function, statement or expression ends(ctx, frame)

insight.on(event, handler, filter) registers a handler for the whole run; insight.off is not supported. insight.id and insight.version identify the API.

Filters

enter and return need at least one of roots, statements or expressions.

KeyValue
rootstrue to match function entries
statementstrue to match each statement
expressionstrue to match each expression
rootNameFiltera regular expression string matched against the function name
sourceFiltera function (source) => boolean; also filters source events

Context and frame

MemberValue
ctx.namefunction name
ctx.source.namefile name
ctx.line, ctx.columnstart position
ctx.characterssource text of the matched node
ctx.returnValue(frame)value returned (in return handlers)
framelocal variables and this, by name

For profiling and a guided example, see Debugging.

Was this page helpful?