Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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);
}
});
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));
}
});
}
return () => {
let profile = profiler.stopProfiling();
new Promise(resolve =>
profile
.export()
.pipe(fs.createWriteStream(name + ".cpuprofile"))
.on("finish", function() {
profile.delete();
resolve();
})
);
};
}
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);
};
router.get('/stop-profiling', async (ctx, next) => {
const result = v8Profiler.stopProfiling('p1')
if (result) {
await writeFile('./samples.cpuprofile', JSON.stringify(result))
ctx.body = 'saved profile'
} else {
ctx.body = 'nothing to show'
}
})