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:'richard@example.com',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?
It looks like you're trying to parse a Chrome heap dump file, which is a JSON file that contains information about the objects in the JavaScript heap at a certain point in time.
The heap dump file has a specific structure, with the top-level object containing several properties that provide information about the state of the heap at the time the heap dump was taken. Some of the properties you might see in a heap dump file include:
snapshot: This property contains information about the objects in the heap, including their sizes, types, and relationships to one another.
meta: This property contains metadata about the heap dump, including information about the version of Chrome that generated the dump, the platform it was running on, and the command-line flags that were passed to the browser at startup.
trace_function_info: This property contains information about the functions that are present in the heap at the time the heap dump was taken.
To parse a heap dump file, you'll need to read the file into memory and then parse it as a JSON object. From there, you can access the various properties of the heap dump and extract the information you're interested in.
As for standard heap dump formats, there isn't really a standard format for heap dumps that is used across all JavaScript engines. Each engine has its own format for heap dumps, and the specifics of the format can vary widely from one engine to another. However, many engines do provide APIs or command-line tools that allow you to generate heap dumps and then analyze them, so you may be able to use those tools to get the information you