perf module to run a set of tests to track leak. vm, buffer, crypto, nexttick leak tests based on existing tests

This commit is contained in:
Jean-Francois 2013-11-22 16:15:54 +01:00
parent 010ef0353c
commit 2e10d3d79e
6 changed files with 148 additions and 43 deletions

View File

@ -155,9 +155,7 @@ for(var i = 0; i < algos.length; i++){
}
function log(txt) {
if (!global.silent) {
print(txt);
}
console.log(txt);
}
function doTest(algo){

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
var perf = require("../perf/common-perf");
var path = require("path");
var simpleRoot = path.join(__dirname, '../../../../test/simple');
perf.startPerfFromTests(simpleRoot, ["test-buffer", "test-readdouble",
"test-readfloat", "test-readint", "test-readuint", "test-write"], 100);

View File

@ -25,35 +25,7 @@
var perf = require("../perf/common-perf");
var module = require("module");
var path = require("path");
var fs = require("fs");
var file = path.join(__dirname, '../crypto/test-crypto.js');
var testRoot = path.join(__dirname, '../crypto');
var cryptoRoot = path.join(__dirname, '../../../../test/crypto');
var files = fs.readdirSync(cryptoRoot);
var cryptoFiles = [];
files.map(function(item) {
if(item.indexOf("test-crypto") == 0) {
cryptoFiles.push(path.join(cryptoRoot, item));
}
})
perf.startPerf(crypto, 20);
function crypto() {
perf.actionStart();
global.silent = true;
// load/execute all crypto tests
cryptoFiles.map(function(f) {
print(f);
require(f);
delete module.Module._cache[f];
})
// load continuously the test-crypto.js, it is synchronous.
require(file);
// otherwise common will find it and fail.
delete global.silent;
delete module.Module._cache[file];
if (perf.canContinue()) {
setImmediate(crypto);
}
}
perf.startPerfFromTests([testRoot, cryptoRoot], ["test-crypto"], 100);

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
var perf = require("../perf/common-perf");
var path = require("path");
var simpleRoot = path.join(__dirname, '../../../../test/simple');
perf.startPerfFromTests(simpleRoot, "test-next-tick", 100);

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
var perf = require("../perf/common-perf");
var path = require("path");
var simpleRoot = path.join(__dirname, '../../../../test/simple');
perf.startPerfFromTests(simpleRoot, ["test-vm", "test-script"], 100);

View File

@ -27,13 +27,15 @@ var count = 0;
var go = true;
var util = require('util');
var memStart;
var log = console.log;
function startPerf(fstart, time) {
start = process.hrtime();
setTimeout(function() {
go = false;
}, time * 1000);
fstart();
console.log("Perf test started.");
log("Perf test started.");
}
exports.startPerf = startPerf;
function round(n) {
@ -69,23 +71,23 @@ function forceGC() {
function dumpResults() {
var end = process.hrtime();
process.stdout.write('\n');
console.log('num of actions %d ', count);
log('num of actions %d ', count);
var elapsed = [end[0] - start[0], end[1] - start[1]];
var ns = elapsed[0] * 1E9 + elapsed[1];
var nsper = round(ns / count);
console.log('%d ns per action (lower is better)', nsper);
log('%d ns per action (lower is better)', nsper);
var readsper = round(count / (ns / 1E9));
console.log('%d actions per sec (higher is better)', readsper);
log('%d actions per sec (higher is better)', readsper);
}
exports.dumpResults = dumpResults;
function canContinue() {
if (!go) {
dumpResults();
console.log("Ending...");
log("Ending...");
forceGC();
var memEnd = captureMemory();
console.log("Memory after gc \n" + memToString(memEnd));
console.log("Heap Diff " + diffMemory(memStart, memEnd));
log("Memory after gc \n" + memToString(memEnd));
log("Heap Diff " + diffMemory(memStart, memEnd));
process.exit(0);
}
return true;
@ -93,14 +95,56 @@ function canContinue() {
exports.canContinue = canContinue;
function actionStart() {
if(count == 5) {
console.log("Capturing mem...")
log("Capturing mem...")
forceGC();
memStart = captureMemory()
console.log("mem " + memToString(memStart));
log("mem " + memToString(memStart));
}
count++;
if (!(count % 1000)) {
process.stdout.write('.');
}
}
exports.actionStart = actionStart;
exports.actionStart = actionStart;
// Automated execution of exiting tests
var fs = require("fs")
var path = require("path")
var module = require("module");
var testFiles = [];
function startPerfFromTests(rootDirs, radicals, time) {
if(!Array.isArray(rootDirs)) {
rootDirs = [rootDirs]
}
if(!Array.isArray(radicals)) {
radicals = [radicals]
}
rootDirs.map(function(rootDir) {
var files = fs.readdirSync(rootDir);
files.map(function(item) {
radicals.map(function(radical) {
if(item.indexOf(radical) == 0) {
testFiles.push(path.join(rootDir, item));
}
});
})
});
log("Run files:\n" + testFiles);
console.log = function() {}
startPerf(run, time)
}
exports.startPerfFromTests = startPerfFromTests;
function run() {
actionStart();
// load/execute all tests
testFiles.map(function(f) {
require(f);
delete module.Module._cache[f];
})
if (canContinue()) {
setImmediate(run);
}
}