How to use v8-profiler-next - 10 common examples

To help you get started, we’ve selected a few v8-profiler-next 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 ChainSafe / lodestar / packages / benchmark-utils / src / index.ts View on Github external
suite.on('complete', function () {
    if(bench.profile) {
      const profile = profiler.stopProfiling(profileId);
      profile.export((error, result) => {
        if (error) {
          return;
        }
        writeFile(`${dirname(bench.file)}/${profileId}`, result, () => {
          profile.delete();
        });
      });
    }
  });
  // add listeners
github ChainSafe / lodestar / packages / eth2.0-spec-test-util / src / single.ts View on Github external
it(basename(testCaseDirectoryPath), function () {
    const testCase = loadInputFiles(testCaseDirectoryPath, options);
    if(options.shouldSkip && options.shouldSkip(testCase, basename(testCaseDirectoryPath))) {
      return this.skip();
    }
    if(options.shouldError && options.shouldError(testCase)) {
      expect(testFunction.bind(null, testCase, basename(testCaseDirectoryPath))).to.throw;
    } else {
      const profileId = `${name}-${Date.now()}.profile`;
      const profilingDirectory = process.env.GEN_PROFILE_DIR;
      if (profilingDirectory) {
        profiler.startProfiling(profileId);
      }
      const result = testFunction(testCase, basename(testCaseDirectoryPath));
      if (profilingDirectory) {
        const profile = profiler.stopProfiling(profileId);

        generateProfileReport(profile, profilingDirectory, profileId);
      }
      const expected = options.getExpected(testCase);
      options.expectFunc(testCase, expected, result, basename(testCaseDirectoryPath));
    }
  });
}
github ChainSafe / lodestar / packages / eth2.0-spec-test-util / src / multi.ts View on Github external
it(description, function () {
        const inputs = getInput(testCase);
        if (shouldError(testCase, index)) {
          expect(testFunc.bind(null, ...inputs)).to.throw();
        } else {
          const profileId = `${description}-${Date.now()}.profile`;
          if (env.GEN_PROFILE_DIR) {
            profiler.startProfiling(profileId);
          }
          const result = testFunc(...inputs);
          if (env.GEN_PROFILE_DIR) {
            const profile = profiler.stopProfiling(profileId);
            const directory = env.GEN_PROFILE_DIR || __dirname;
            profile.export((error, result) => {
              if (error) {
                return;
              }
              writeFile(`${directory}/${profileId}`, result, () => {
                profile.delete();
              });
            });
          }
          const actual = getActual(result);
          const expected = getExpected(testCase);
github ChainSafe / lodestar / packages / eth2.0-spec-test-util / src / multi.ts View on Github external
it(description, function () {
        const inputs = getInput(testCase);
        if (shouldError(testCase, index)) {
          expect(testFunc.bind(null, ...inputs)).to.throw();
        } else {
          const profileId = `${description}-${Date.now()}.profile`;
          if (env.GEN_PROFILE_DIR) {
            profiler.startProfiling(profileId);
          }
          const result = testFunc(...inputs);
          if (env.GEN_PROFILE_DIR) {
            const profile = profiler.stopProfiling(profileId);
            const directory = env.GEN_PROFILE_DIR || __dirname;
            profile.export((error, result) => {
              if (error) {
                return;
              }
              writeFile(`${directory}/${profileId}`, result, () => {
                profile.delete();
              });
            });
          }
          const actual = getActual(result);
          const expected = getExpected(testCase);
          expectFunc(testCase, expect, expected, actual);
        }
      });
github ChainSafe / lodestar / packages / eth2.0-spec-test-util / src / single.ts View on Github external
it(basename(testCaseDirectoryPath), function () {
    const testCase = loadInputFiles(testCaseDirectoryPath, options);
    if(options.shouldSkip && options.shouldSkip(testCase, basename(testCaseDirectoryPath))) {
      return this.skip();
    }
    if(options.shouldError && options.shouldError(testCase)) {
      expect(testFunction.bind(null, testCase, basename(testCaseDirectoryPath))).to.throw;
    } else {
      const profileId = `${name}-${Date.now()}.profile`;
      const profilingDirectory = process.env.GEN_PROFILE_DIR;
      if (profilingDirectory) {
        profiler.startProfiling(profileId);
      }
      const result = testFunction(testCase, basename(testCaseDirectoryPath));
      if (profilingDirectory) {
        const profile = profiler.stopProfiling(profileId);

        generateProfileReport(profile, profilingDirectory, profileId);
      }
      const expected = options.getExpected(testCase);
      options.expectFunc(testCase, expected, result, basename(testCaseDirectoryPath));
    }
  });
}
github preconstruct / preconstruct / packages / cli / test-utils / index.ts View on Github external
export function profile(name: string) {
  profiler.startProfiling(name, true);

  return () => {
    let profile = profiler.stopProfiling();

    new Promise<void>(resolve =>
      profile
        .export()
        .pipe(fs.createWriteStream(name + ".cpuprofile"))
        .on("finish", function() {
          profile.delete();
          resolve();
        })
    );
  };
}
github preconstruct / preconstruct / packages / cli / test-utils / index.ts View on Github external
return () => {
    let profile = profiler.stopProfiling();

    new Promise<void>(resolve =>
      profile
        .export()
        .pipe(fs.createWriteStream(name + ".cpuprofile"))
        .on("finish", function() {
          profile.delete();
          resolve();
        })
    );
  };
}
github davidmarkclements / 0x / examples / cpu-profiler / index.js View on Github external
router.get('/start-profiling', (ctx, next) => {
  v8Profiler.startProfiling('p1')
  ctx.body = 'started'
})
github ChainSafe / lodestar / packages / benchmark-utils / src / index.ts View on Github external
suite.on('start', function () {
    if(bench.profile) {
      profiler.startProfiling(profileId);
    }
  });
  suite.on('complete', function () {
github auth0 / auth0-instrumentation / lib / profiler.js View on Github external
Profiler.prototype.createProfile = function(timeout, callback) {
  if (typeof timeout === 'function') {
    callback = timeout;
    timeout = 10000;
  }

  const path = `${this.heapshotDir}/${this.serviceName}-profile-${moment().unix().toString()}.cpuprofile`;

  process.send(JSON.stringify({ msg: 'pause_monitoring' }));
  v8Profiler.startProfiling(path, true);

  setTimeout(() => {
    const profile = v8Profiler.stopProfiling(path);
    profile.export((err, result) => {
      if (err) {
        return callback(err);
      }
      fs.writeFileSync(path, result);
      profile.delete();
      setTimeout(function () {
        process.send(JSON.stringify({ msg: 'resume_monitoring' }));
      }, ms('5s'));
      return callback(null, path);
    });
  }, timeout);
};

v8-profiler-next

node bindings for the v8 profiler

MIT
Latest version published 6 months ago

Package Health Score

67 / 100
Full package analysis