Skip to content

Commit

Permalink
Documenting use of --heap.dump option in Enso program
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Oct 17, 2024
1 parent 563f116 commit 2afcfa5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/Benchmarks/src/Sieve/Lazy_Sieve.enso
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ main n=Nothing =
@Tail_Call print_nth s.tail (n.if_not_nothing n-1)

compute_and_print_nth nth:Integer|Nothing =
@Tail_Call print_nth primes nth
p = primes
print_nth p nth

compute_and_print_nth n

50 changes: 50 additions & 0 deletions test/Benchmarks/src/Sieve/heap_dump_lazy_sieve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Demo script showing a "serialization" of an Enso atom structure
// to a `.hprof` file which can be opened and analyzed in VisualVM
//
// Based on following tutorial:
// https://www.graalvm.org/jdk21/tools/graalvm-insight/manual/#heap-dumping
//
// Execute from `sbt` as:
// ```
// sbt:enso> runEngineDistribution \
// --vm.D=polyglot.heap.dump=/tmp/sieve.hprof \
// --vm.D=polyglot.insight=Benchmarks/src/Sieve/heap_dump_lazy_sieve.js \
// --run test/Benchmarks/src/Sieve/Lazy_Sieve.enso
// 10000
// ```
//
// This GraalVM script waits for the end execution of `compute_and_print_nth` function
// to store value of its `p` local variable (containing linked list of prime numbers)
// into `/tmp/sieve.hprof` - a GraalVM serialization for Truffle languages!

insight.on(
'return',
(ctx, frame) => {
for (let p in frame) {
print(`found ${p} with ${frame[p]} value`)
}
let value = frame.p
heap.dump({
format: '1.0',
depth: 5000,
events: [
{
stack: [
{
at: ctx,
frame: {
primes: value,
},
},
],
},
],
})
print('Heap dump generated!')
},
{
roots: true,
rootNameFilter: '.*compute_and_print_nth',
},
)

0 comments on commit 2afcfa5

Please sign in to comment.