v8 API Deep Dive

External Buffer Memory Example

  • we can use that to first filter all Buffers and then get at what's in them
snapshot.requestNodesByName('Uint8Array', onBufferNode)

function onBufferNode(node) {
  let buf = profiler.getObjectByHeapObjectId(node.id)

  if (!Buffer.isBuffer(buf)) {
    if (Object.getPrototypeOf(buf) === Uint8Array.prototype) buf = new Buffer(buf)
    else return
  }

  // Now we can store important information in the buffers array.
  buffers.push({
    buf         : buf,
    length      : buf.length,
    bufferType  : node.name,      // Uint8Array, Buffer or NativeBuffer
    type        : node.type,
    id          : node.id,
    shallowSize : node.shallowSize,
    hash        : hashBuffer(buf)
  })
}