Commit 78f3a825 authored by Alexandra's avatar Alexandra

now with right pid

parent 81a134d8
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
"use strict"; "use strict";
const { exec } = require("child_process");
var childProcess = require("child_process"); var childProcess = require("child_process");
var cut_file = require("./random_gen").cut_file; var cut_file = require("./random_gen").cut_file;
// var diskspace = require("diskspace");
// var os_utils = require("os-utils");
// var os = require('os');
const puppeteer = require("puppeteer"); const puppeteer = require("puppeteer");
const Server = require("ws").Server; const Server = require("ws").Server;
const args = require("yargs") const args = require("yargs")
...@@ -28,9 +26,7 @@ var page; ...@@ -28,9 +26,7 @@ var page;
var n = 0; var n = 0;
var time; var time;
var monitor; var monitor;
// var ramBefore; var pid;
// var memBefore;
var browser_pid;
function init_server (){ function init_server (){
var port = 9030; var port = 9030;
...@@ -70,17 +66,6 @@ async function query (){ ...@@ -70,17 +66,6 @@ async function query (){
} else { } else {
n += 1000; n += 1000;
time = Date.now(); time = Date.now();
// monitor = childProcess.fork("./unit_tests/monitor.js");
// monitor.on("message", function(msg){
// diskspace.check("C", function (err, result){
// var memUsed = (result.used/1024/1024) - memBefore;
// var ramUsed = parseInt(msg) - ramBefore;
// console.log(ramUsed/1024/1024);
// //process.send(n + "," + ramUsed + "," + memUsed + "\n");
// monitor.kill();
// query();
// });
// });
const [fileChooser] = await Promise.all([ const [fileChooser] = await Promise.all([
page.waitForFileChooser(), page.waitForFileChooser(),
page.click("input#load") page.click("input#load")
...@@ -90,19 +75,26 @@ async function query (){ ...@@ -90,19 +75,26 @@ async function query (){
} }
(async () => { (async () => {
files = cut_file(args.file, 1000); files = cut_file(args.file, 1000);
init_server(); init_server();
browser = await puppeteer.launch(); browser = await puppeteer.launch();
browser_pid = browser.process().pid;
page = await browser.newPage(); page = await browser.newPage();
await page.goto(link); await page.goto(link);
monitor = childProcess.fork("./unit_tests/monitor.js",
args.r ? ["-r", "-p", browser_pid] : ["-p", browser_pid]); browser.targets().find(target => target._targetInfo.url === "about:blank").page()
timeout(); .then(function(p){
query(); p.close();
// diskspace.check("C", function (err, result){ })
// memBefore = result.used/1024/1024; .then(function(){
// timeout(); exec("ps x | grep \"chrome\"", (error, stdout, stderr) => {
// query(); var page_info = stdout.split("\n").find(process => process.includes("--type=renderer"));
// }); pid = page_info.split(" ")[0];
monitor = childProcess.fork("./unit_tests/monitor.js",
args.r ? ["-r", "-p", pid] : ["-p", pid]);
timeout();
query();
})
})
})(); })();
...@@ -12,28 +12,8 @@ import socket ...@@ -12,28 +12,8 @@ import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('localhost', 9040)) client.connect(('localhost', 9040))
# class _Snapshot(object):
# def get(self, property, default=None):
# return getattr(self, property, default)
#
# class ProcessSnapshot(_Snapshot):
# def __init__(self, process=None):
# assert type(process) is psutil.Process
# self.username = process.username()
# self.process_object = process
# self.pid = process.pid
# # Memory percentage
# self.memory_percent = process.memory_percent()
#
# def update_memory_percent(self):
# if self.process_object.is_running():
# self.memory_percent = self.process_object.memory_percent()
process = psutil.Process(args.p) process = psutil.Process(args.p)
# snapshot = ProcessSnapshot(process)
while (1) : while (1) :
#snapshot.update_memory_percent() client.send(str((process.memory_info().rss)))
#client.send(str(snapshot.memory_percent))
client.send(str(process.memory_info().rss))
time.sleep(0.1) time.sleep(0.1)
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