-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_watcher_worker.ts
74 lines (62 loc) · 1.48 KB
/
proc_watcher_worker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import CpuinfoParse, { extractAndMergeCpuInfo } from "./cpuinfo_parser.ts";
import { data_pipe } from "./main.ts";
import MeminfoParse from "./meminfo_parser.ts";
import {
readCpuinfo,
readMeminfo,
readPidBinarySymlink,
readPidSmaps,
readProcDir,
} from "./reader.ts";
import PidSmapsParse from "./smaps_parser.ts";
declare global {
interface Window {
postMessage: any;
}
}
// Timeout in ms
const TIMEOUT = 2000;
function callback() {
const pids = readProcDir();
const cpuinfo = readCpuinfo();
const meminfo = readMeminfo();
const parsedMeminfo = MeminfoParse(meminfo);
const parsedCpuInfo = CpuinfoParse(cpuinfo);
const extractedCpuInfo = extractAndMergeCpuInfo(parsedCpuInfo);
let pidsMemUsageAll: any = [];
for (const pid in pids) {
const p = readPidSmaps(pids[pid]);
if (p === "") {
continue;
}
// Pidstat is too big for Deno.kv to store
// so we read only the values we need for each PID
const pidStat = PidSmapsParse(p);
const bin = readPidBinarySymlink(pids[pid])
pidsMemUsageAll.push({
pid: pids[pid],
exe: bin,
meminfo: {
Size: pidStat["Size"].value,
Rss: pidStat["Rss"].value,
Pss: pidStat["Pss"].value,
},
});
}
data_pipe.postMessage([
{
source: "pids",
values: pidsMemUsageAll,
},
{
source: "system",
values: {
cpu: extractedCpuInfo,
meminfo: parsedMeminfo,
}
}
]);
pidsMemUsageAll = [];
setTimeout(callback, TIMEOUT);
}
callback();