Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

V8 Javascript Heap Dump Schema

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?

like image 642
Schneems Avatar asked Nov 19 '15 18:11

Schneems


People also ask

How do I create a heap dump in Node JS?

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.

How do I take a dump of the V8 heap?

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.

How do I create a heap snapshot in V8?

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.

Should heapdump be created before or after Oom?

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.


1 Answers

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

like image 58
smirnoff Avatar answered Oct 11 '22 19:10

smirnoff