I'm trying to understand the contents of a heapdump generated by google chrome tools. I understand that there is already a in-browser heap dump inspector but I'm interested in writing a CLI that parses a JS heap dump as an exercise. I'm not able to find any docs on the structure of the contents inside of a heap dump. They're human readable but the format isn't very clear from inspecting the file
Here's a random snippet:
"HTMLOptionElement",
"XMLHttpRequestEventTarget",
"about:blank",
"clearModifier",
"resetModifiers",
"/devtools/docs/demos/memory/example1",
"HTMLIFrameElement",
"https://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22search%22%2C%22version%22%3A%221.0%22%2C%22callback%22%3A%22__gcse.scb%22%2C%22style%22%3A%22https%3A%2F%2Fwww.google.com%2Fcse%2Fstyle%2Flook%2Fv2%2Fdefault.css%22%2C%22language%22%3A%22en%22%7D%5D%7D",
"HTMLLinkElement",
"HTMLContentElement",
"window.__SSR = {c: 1.2808007E7 ,si:1,su:1,e:'[email protected]',dn:'Richard Schneeman',a:'bubble',at:'AZW7SXV+1uUcQX+2WIzyelLB5UgBepsr1\\/RV+URJxwIT6BmLmrrThMH0ckzB7mLeFn1SFRtxm\\/1SD16uNnjb0qZxXct8\\x3d',ld:[,[0,12808007,[]\n,1,70]\n]\n,r:'https:\\/\\/developer.chrome.com\\/devtools\\/docs\\/demos\\/memory\\/example1',s:'widget',annd: 2.0 ,bp: {}, id:'http:\\/\\/www.google.com\\/chrome'}; document.addEventListener && document.addEventListener('DOMContentLoaded', function () {gapi.inline.tick('wdc', new Date().getTime());}, false);",
"onLoaded",
"HTMLAllCollection",
"onDocumentKeyDown",
Do docs on the structure of chrome heap dumps exist? Is there a standard javascript heap dump format or does every engine have their own proprietary standard?
Traditionally, in Node.js, we've had two options for creating heap dumps. Using the heapdump module. Attaching a Chrome DevTools instance and using the Memory tab to create a heap snapshot.
Make a dump of the V8 heap for later inspection. The module exports a single writeSnapshot ( [filename], [callback]) function that writes out a snapshot. filename defaults to heapdump-<sec>.<usec>.heapsnapshot when omitted. The function also takes an optional callback function which is called upon completion of the heap dump.
To create a heap snapshot, you can just use v8.getHeapSnapshot (). This returns a readable stream, which you can then pipe to a file, which you can then use in Chrome DevTools. For example, you can make a function like this that you can call whenever you want to create a heap dump file.
when the memory usage grew very volatile, there was no time to create the heapdump before the OoM. That's when i started looking into the V8 SetOOMErrorHandler method, which had a better result.
Unfortunately there's no such thing as standard JS heap format. Quick googling for "v8 heap dump format" gives several results, none of them are super-detailed. There's node.js heapsnapshot parser extension, and v8 source code contains the most up-to-date info: v8-profiler.h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With