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";
const { exec } = require("child_process");
var childProcess = require("child_process");
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 Server = require("ws").Server;
const args = require("yargs")
......@@ -28,9 +26,7 @@ var page;
var n = 0;
var time;
var monitor;
// var ramBefore;
// var memBefore;
var browser_pid;
var pid;
function init_server (){
var port = 9030;
......@@ -70,17 +66,6 @@ async function query (){
} else {
n += 1000;
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([
page.waitForFileChooser(),
page.click("input#load")
......@@ -90,19 +75,26 @@ async function query (){
}
(async () => {
files = cut_file(args.file, 1000);
init_server();
browser = await puppeteer.launch();
browser_pid = browser.process().pid;
page = await browser.newPage();
await page.goto(link);
browser.targets().find(target => target._targetInfo.url === "about:blank").page()
.then(function(p){
p.close();
})
.then(function(){
exec("ps x | grep \"chrome\"", (error, stdout, stderr) => {
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", browser_pid] : ["-p", browser_pid]);
args.r ? ["-r", "-p", pid] : ["-p", pid]);
timeout();
query();
// diskspace.check("C", function (err, result){
// memBefore = result.used/1024/1024;
// timeout();
// query();
// });
})
})
})();
......@@ -12,28 +12,8 @@ import socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
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)
# snapshot = ProcessSnapshot(process)
while (1) :
#snapshot.update_memory_percent()
#client.send(str(snapshot.memory_percent))
client.send(str(process.memory_info().rss))
client.send(str((process.memory_info().rss)))
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