How to use the v8.getHeapStatistics function in v8

To help you get started, we’ve selected a few v8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github t9md / atom-narrow / lib / utils.js View on Github external
function startMeasureMemory (subject, simple = true) {
  if (ignoreSubject.includes(subject)) {
    return () => {}
  }
  console.time(subject)

  const v8 = require('v8')
  const before = v8.getHeapStatistics()
  console.time(subject)
  return function () {
    const after = v8.getHeapStatistics()
    const diff = {}
    for (let key of Object.keys(before)) {
      diff[key] = after[key] - before[key]
    }

    console.info(`= ${subject}`)
    if (simple) {
      console.timeEnd(subject)
      // console.log("diff.used_heap_size", toMB(diff.used_heap_size))
    } else {
      const table = [before, after, diff]
      for (let result of table) {
        for (const key in result) {
github keymetrics / pm2-io-apm / src / metrics / v8.ts View on Github external
this.timer = setInterval(() => {
      const stats = v8.getHeapStatistics()
      // update each metrics that we declared
      for (let metricName in this.metricsDefinitions) {
        if (typeof stats[metricName] !== 'number') continue
        const gauge = this.metricStore.get(metricName)
        if (gauge === undefined) continue
        gauge.set(this.formatMiBytes(stats[metricName]))
      }
      // manually compute the heap usage
      const usage = (stats.used_heap_size / stats.total_heap_size * 100).toFixed(2)
      const usageMetric = this.metricStore.get('heap_used_percent')
      if (usageMetric !== undefined) {
        usageMetric.set(parseFloat(usage))
      }
    }, this.TIME_INTERVAL)
github graalvm / graaljs / test / parallel / test-v8-stats.js View on Github external
'use strict';
require('../common');
const assert = require('assert');
const v8 = require('v8');

const s = v8.getHeapStatistics();
const keys = [
  'does_zap_garbage',
  'heap_size_limit',
  'malloced_memory',
  'number_of_detached_contexts',
  'number_of_native_contexts',
  'peak_malloced_memory',
  'total_available_size',
  'total_heap_size',
  'total_heap_size_executable',
  'total_physical_size',
  'used_heap_size'];
assert.deepStrictEqual(Object.keys(s).sort(), keys);
keys.forEach(function(key) {
  assert.strictEqual(typeof s[key], 'number');
});
github ngnjs / NGN / lib / Health.js View on Github external
get status () {
    return {
      uptime: os.uptime(),
      load: os.loadavg(),
      ram: {
        total: os.totalmem(),
        free: os.freemem(),
        usage: process.memoryUsage()
      },
      cpu: os.cpus(),
      v8: V8.getHeapStatistics()
    }
  }
github blake-regalia / graphy.js / src / main / memory-monitor.js View on Github external
update() {
		this.heap_snapshot.heap_size = v8.getHeapStatistics().used_heap_size;
	}
github CampbellCrowley / SpikeyBot-Discord / src / memWatcher.js View on Github external
check() {
    const mem = v8.getHeapStatistics();
    const limit = mem.heap_size_limit;
    const total = mem.total_heap_size;

    const mult = 1000000;

    const limitHR = Math.round(limit / mult * 100) / 100;
    const totalHR = Math.round(total / mult * 100) / 100;
    const nums = `${total}/${limit}B (${totalHR}/${limitHR}MB)`;
    const thresh =
        `${limit-this._threshold-total} from threshold (${this._threshold})`;

    this.debug(`Heap Snapshot: ${nums} ${thresh}`);

    if (total >= limit - this._threshold) {
      this.suicide();
      return;
github EnMasseProject / enmasse / agent / bin / agent.js View on Github external
setInterval(() => {
                    log.info("Heap statistics : %j", v8.getHeapStatistics());
                }, 60000);
            }).catch((e) => {log.error("Failed to listen ", e)})
github notable / dumper / src / utils.ts View on Github external
return Utils.file.stats ( filePath ).then ( stats => {

        if ( stats.size < 1000000000 && stats.size < ( require ( 'v8' ).getHeapStatistics ().heap_size_limit * .75 ) ) return;

        throw new Error ( 'File too large, try splitting it into smaller ones' );

      });

v8

v8

MIT
Latest version published 9 years ago

Package Health Score

42 / 100
Full package analysis