Commit feaa3ebe authored by Alexandra Rogova's avatar Alexandra Rogova

replaced process usage with puppeteer usage

parent 02450efe
const puppeteer = require('puppeteer');
var args = require("yargs") var args = require("yargs")
.usage("Usage : load_index.js -saveAs metadata/attachment -file file_path") .usage("Usage : load_index.js -saveAs metadata/attachment -file file_path")
.demandOption(['file']) .demandOption(['file'])
.demandOption(['saveAs']) .demandOption(['saveAs'])
.alias("f", "file") .alias("f", "file")
.alias("s", "saveAs") .alias("s", "saveAs")
.describe("file", "file containing content to put in the index, data must follow the CSV standard") .describe("file", "file containing content to put in the index, data must follow the CSV standard")
.describe("saveAs", "choose whether to save the index as metadata or attachments in the indexeddb") .describe("saveAs", "choose whether to save the index as metadata or attachments in the indexeddb")
.nargs("file", 1) .nargs("file", 1)
.nargs("saveAs", 1) .nargs("saveAs", 1)
.argv; .argv;
if (!(args.saveAs === "metadata" ||args.saveAs === "attachment")){ if (!(args.saveAs === "metadata" ||args.saveAs === "attachment")){
throw 'Unrecognized save as argument'; throw 'Unrecognized save as argument';
} }
var saveAs = args.saveAs; var saveAs = args.saveAs;
var browser; const puppeteer = require('puppeteer');
var browser, page;
const si = require("systeminformation");
var Server = require('ws').Server; var Server = require('ws').Server;
var port = 9030; var port = 9030;
var ws = new Server({port: port}); var ws = new Server({port: port});
ws.on('connection', function(w){ ws.on('connection', function(w){
w.on('message', function(msg){ w.on('message', function(msg){
console.log(msg); console.log(msg);
const used = process.memoryUsage(); page.metrics()
for (let key in used) { .then(function(values){
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`); console.log(values.JSHeapUsedSize / 1024 / 1024);
} si.mem(function(data){
console.log(data.used / 1024 / 1024);
});
browser.close(); browser.close();
}); });
w.on('close', function() { });
ws.close(); w.on('close', function() {
}); ws.close();
});
}); });
(async () => { (async () => {
const used = process.memoryUsage();
for (let key in used) {
console.log(`${key} ${Math.round(used[key] / 1024 / 1024 * 100) / 100} MB`);
}
browser = await puppeteer.launch(); browser = await puppeteer.launch();
const page = await browser.newPage(); page = await browser.newPage();
var metrics = await page.metrics();
console.log(metrics.JSHeapUsedSize / 1024 / 1024);
si.mem(function(data){
console.log(data.used / 1024 / 1024);
});
await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/index_load.html?saveAs='+saveAs); await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/index_load.html?saveAs='+saveAs);
const [fileChooser] = await Promise.all([ const [fileChooser] = await Promise.all([
page.waitForFileChooser(), page.waitForFileChooser(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment