# Plans for Viewing Heap Snapshots?

**URL:** <https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696>\
**Category:** VS Code\
**Created:** [May 11, 2023, 5:27pm UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696 "2023-05-11T17:27:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Post date:** [May 11, 2023, 5:27pm UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696/1 "2023-05-11T17:27:38Z")

</div>

Hello!

I know its a bit early, but with 1.9 out and the ability to view heap snapshots with Chromium, I’m wondering if there are any plans to integrate the ability to view the snapshots in VSCode via the Julia extension?

---

<div class="post-metadata">

**Author:** ![TI36XPro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ti36xpro/32/33658_2.png) [@TI36XPro](https://discourse.julialang.org/u/TI36XPro)\
**Post date:** [December 10, 2023, 3:16pm UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696/2 "2023-12-10T15:16:39Z")

</div>

I just saw that VSCode has added the ability to view [heap snapshots natively](https://code.visualstudio.com/updates/v1_85#_javascript-debugger). It is presented in the context of a JS debugger though.

Is there any possibility to leverage this to view [Julia generated heap snapshots](https://julialang.org/blog/2023/04/julia-1.9-highlights/#heap_snapshot) within VSCode?  
I just tried but I get an error when trying to open the `.heapsnapshot` file that says `Error: invalid profile JSON`.

---

<div class="post-metadata">

**Author:** ![nandoconde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nandoconde/32/19497_2.png) [@nandoconde](https://discourse.julialang.org/u/nandoconde)\
**Post date:** [December 12, 2023, 9:58am UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696/3 "2023-12-12T09:58:15Z")

</div>

@davidanthoff @pfitzseb any news on this front?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [December 12, 2023, 10:41am UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696/4 "2023-12-12T10:41:29Z")

</div>

Not really. [Heapsnapshot has some unrooted objects · Issue #52432 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/52432#issuecomment-1847455643) might cause the UI to fail though.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [September 11, 2024, 9:21pm UTC](https://discourse.julialang.org/t/plans-for-viewing-heap-snapshots/98696/5 "2024-09-11T21:21:31Z")

</div>

FTR this works nowadays:

> <https://github.com/JuliaLang/julia/pull/53833>
>
> \- Fixes https://github.com/JuliaLang/julia/issues/52680
> \- Tidies up streamed fi…les when not explicitly using streamed mode
> 
> Tested against https://github.com/microsoft/vscode-v8-heap-tools/tree/main/v8-heap-parser by copying a julia heapsnapshot into the \`test\` dir as \`basic.heapsnapshot\` and running \`cargo test\`
> 
> Update: This is working, except for the graph view, which appears to be an upstream issue https://github.com/microsoft/vscode-js-profile-visualizer/issues/175
> 
> \---
> 
> Original issues
> 
> With these changes, it still fails, but because of the middle line here
> \`\`\`
> "codelocs",
> "�\\u0003",
> "\<generic memory - malloc\>",
> \`\`\`
> with
> \`\`\`
> failures:
> 
> \---- decoder::tests::test\_basic\_heapsnapshot stdout ----
> thread 'decoder::tests::test\_basic\_heapsnapshot' panicked at v8-heap-parser/src/decoder.rs:574:33:
> expect no errors: Error("invalid unicode code point", line: 6020770, column: 9)
> note: run with \`RUST\_BACKTRACE=1\` environment variable to display a backtrace
> 
> \---- graph::tests::test\_retained\_sizes stdout ----
> thread 'graph::tests::test\_retained\_sizes' panicked at v8-heap-parser/src/graph.rs:719:45:
> expect no errors: Error("invalid unicode code point", line: 6020770, column: 9)
> 
> 
> failures:
> decoder::tests::test\_basic\_heapsnapshot
> graph::tests::test\_retained\_sizes
> \`\`\`
> 
> If I manually empty that string the only test that fails is a content comparison against a fixed reference.
> Does the string sanitizer need fixing or is this some other issue?
> 
> However.. the string-fixed file loads in neither chrome devtools, nor vscode's viewer.
> 
> I'm opening this in case you see the issue, @vilterp @NHDaly

> <https://github.com/JuliaLang/julia/pull/53984>
>
> Followup to https://github.com/JuliaLang/julia/pull/53833
> Fixes a failure seen …in https://github.com/JuliaLang/julia/pull/53974 (below)
> 
> I believe this is the more correct check to make?
> 
> The heapsnapshot generated from this PR is viewable in vscode.
> 
> \`\`\`
> 2024-04-06 09:33:58 EDT From worker 7:	ERROR: Base.InvalidCharError{Char}('\\xc1\\xae')
> 2024-04-06 09:33:58 EDT From worker 7:	Stacktrace:
> 2024-04-06 09:33:58 EDT From worker 7: \[1\] throw\_invalid\_char(c::Char)
> 2024-04-06 09:33:58 EDT From worker 7: @ Base ./char.jl:86
> 2024-04-06 09:33:58 EDT From worker 7: \[2\] UInt32
> 2024-04-06 09:33:58 EDT From worker 7: @ ./char.jl:133 \[inlined\]
> 2024-04-06 09:33:58 EDT From worker 7: \[3\] category\_code
> 2024-04-06 09:33:58 EDT From worker 7: @ ./strings/unicode.jl:339 \[inlined\]
> 2024-04-06 09:33:58 EDT From worker 7: \[4\] isassigned
> 2024-04-06 09:33:58 EDT From worker 7: @ ./strings/unicode.jl:355 \[inlined\]
> 2024-04-06 09:33:58 EDT From worker 7: \[5\] isassigned
> 2024-04-06 09:33:58 EDT From worker 7: @ /cache/build/tester-amdci5-14/julialang/julia-master/julia-41d026beaf/share/julia/stdlib/v1.12/Unicode/src/Unicode.jl:138 \[inlined\]
> 2024-04-06 09:33:58 EDT From worker 7: \[6\] print\_str\_escape\_json(stream::IOStream, s::String)
> 2024-04-06 09:33:58 EDT From worker 7: @ Profile.HeapSnapshot /cache/build/tester-amdci5-14/julialang/julia-master/julia-41d026beaf/share/julia/stdlib/v1.12/Profile/src/heapsnapshot\_reassemble.jl:239
> 2024-04-06 09:33:59 EDT From worker 7: \[7\] (::Profile.HeapSnapshot.var"#5#6"{IOStream})(strings\_io::IOStream)
> 2024-04-06 09:33:59 EDT From worker 7: @ Profile.HeapSnapshot /cache/build/tester-amdci5-14/julialang/julia-master/julia-41d026beaf/share/julia/stdlib/v1.12/Profile/src/heapsnapshot\_reassemble.jl:192
> \`\`\`

I believe the changes were also backported to v1.10.

EDIT: the heap snapshots produces by Julia are now viewable in VS Code (with the `ms-vscode.vscode-js-profile-flame` extension), but _not_ in Chromium:

> <https://github.com/JuliaLang/julia/issues/54414>
>
> \`\`\`
> julia\> using Profile
> 
> julia\> Profile.take\_heap\_snapshot("1.11.heapsnapsho…t")
> "1.11.heapsnapshot"
> \`\`\`
> 
> Trying to load this in Chrome leads to
> 
> \`\`\`
> An error occurred when a call to method 'buildSnapshot' was requested
> TypeError: Cannot read properties of undefined (reading '1')
> at F.name (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:8216)
> at F.rawName (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:38825)
> at F.name (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:39038)
> at F.isDocumentDOMTreesRoot (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:40431)
> at b.isUserRoot (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:35720)
> at b.calculateDistances (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:18912)
> at b.calculateDistances (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:35160)
> at b.initialize (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:14141)
> at new b (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:33684)
> at A.buildSnapshot (devtools://devtools/bundled/devtools-frontend/front\_end/entrypoints/heap\_snapshot\_worker/heap\_snapshot\_worker.js:1:43578)
> \`\`\`
> 
> On 1.10 the same procedure works fine.
