enso/tools/enso4igv
Hubert Plociniczak 22fc03ca3d
Fix here leftovers (#3567)
Hooking up Reporting_Stream_Encoder_Spec reveals missing renaming.
Also removed one more `here.` that wasn't run in tests.

Kudos to @radeusgd for finding those!
2022-07-07 12:02:18 +00:00
..
src/main Fix here leftovers (#3567) 2022-07-07 12:02:18 +00:00
pom.xml Enso Integration with Ideal Graph Visualizer (#3533) 2022-06-23 04:43:49 +00:00
README.md Enso Integration with Ideal Graph Visualizer (#3533) 2022-06-23 04:43:49 +00:00

Enso Language Support for NetBeans & Ideal Graph Visualizer

Enso Language Support for IGV

Enso language runtime engine is built on top of GraalVM and its Truffle framework. Enso, as a good citizen of the GraalVM ecosystem, benefits from polyglot capabilities of GraalVM as well as its rich tooling offering. One of such tools is IGV - the Ideal Graph Visualizer - an excellent tool to get insights into behavior of Graal compiler.

This document shows how to use IGV with the Enso language. The command line instructions format is Unix oriented. Use instructions appropriate for your operating system to perform the same on different OS. IGV itself as well as the Enso language support are platform neutral with launch scripts for all major operating systems.

Installation

Visit GraalVM.org download page and continue towards enterprise edition option. There is an Ideal Graph Visualizer option. After clicking through the confirmation dialogs you should get a ZIP - I've just got idealgraphvisualizer-22.1.0.zip and then:

$ unzip idealgraphvisualizer-22.1.0.zip
$ ./idealgraphvisualizer/bin/idealgraphvisualizer --userdir /tmp/emptyuserdir

launches the IGV application. One doesn't have to use the --userdir option, but doing so ensures the newly running IGV process is isolated from any settings left around by previous usage of IGV.

IGV understands Enso when Enso Language Support module is installed. Login to GitHub, follow the GitHub actions link and select a build. Unless you have some special needs choose the latest one. The build summary page provides various information as well as list of artifacts at the bottom. Download the Enso IGV Plugin ZIP file (make sure you are logged into GitHub - artifacts are only available to those logged in). Unzip it and get enso*.nbm file. This file can be installed into IGV (or any other NetBeans based application). Go to Tools/Plugins/Downloaded/Add Plugins and select the NBM file.

Tools/Plugins/Downloaded

Proceed by clicking Install. You may be asked to download TextMate Lexer - a necessary dependency of the Enso support module. Continue through the wizard to finish the installation.

Tools/Plugins/Downloaded

Using the IGV

Get an instance of the Enso runtime engine (see Running Enso) and then launch it with special --dump-graphs option:

enso$ ./built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --dump-graphs --run yourprogram.enso

When executed on GraalVM 21.3.0 these options instruct the Graal/Truffle compiler to dump files into graal_dumps/_sometimestamp_ directory. Generating these files takes a while - make sure yourprogram.enso runs long enough for the system to warmup, compile the code and run at full speed.

Sieve of Eratosthenes Example

As an example you can download sieve.enso which computes hundred thousand of prime numbers repeatedly and measures time of each round. Download the file and launch Enso with --dump-graphs argument:

enso$ ./built-distribution/enso-engine-0.0.0-dev-linux-amd64/enso-0.0.0-dev/bin/enso --dump-graphs --run sieve.enso

Bunch of files in graal_dumps/* subdirectory is going to be generated:

enso$ ls graal_dumps/*/Truffle* | tail -n5
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9889[argument<2>].bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9896[IfThenElseMethodGen@3af870b9_<split-62b6b4f3>]_1.bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9896[IfThenElseMethodGen@3af870b9_<split-62b6b4f3>].bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9935[Primes.next_<split-717d5bdf>]_1.bgv
graal_dumps/2022.06.20.06.18.21.733/TruffleHotSpotCompilation-9935[Primes.next_<split-717d5bdf>].bgv

Let's launch IGV with Enso integration and let's open graph for one of the top-most functions: TruffleHotSpotCompilation*Primes*next*.bgv. Choose compilation phase "Before lowering":

Before Lowering Graph

Now you can inspect the compiler graphs the regular IGV way. Let's locate for example LoadField#FunctionSchema.isFullyApplied node and let's check how it got inlined(you can use search box in the top-right corner)

Inlining Stacktrace

The stack trace shows what methods of the Enso interpreter and Truffle runtime are "inlined on stack" when this node is being compiled. This is all regular IGV functionality, but now we can switch to Enso view:

Enso Source

By choosing the Enso language icon in front of the stack trace combo, the source code of our .enso program is opened and we can analyze what compiler nodes refer to what lines in the our Enso program. Click Navigate to Source icon in the Stack View to get from graph node to source. Select a drop down widget in the editor toolbar to show you what compiler nodes as associated with currently selected line.

Building

The plugin can be rebuilt using Apache Maven. The build is platform independent. The following instructions are for Unix like environment. Switch to this directory and invoke:

enso/tools/enso4igv$ mvn clean install
enso/tools/enso4igv$ ls target/*.nbm
target/enso4igv-1.0-SNAPSHOT.nbm

an NBM file is generated which can be installed into IGV, NetBeans or any other NetBeans based application.