-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
80 lines (73 loc) · 2.48 KB
/
index.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
75
76
77
78
79
80
/**
* @file index.ts
* @author @2kai2kai2
*
* @copyright Copyright (c) 2023 Kai Orita
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const addon = require("node-gyp-build")(__dirname);
/**
* @param pid Process ID to search for.
* @returns Process user-mode CPU usage time in ms, or 0 if not found.
*/
export function cpuUserTime(pid: number): number {
return addon.cpuUserTime(pid);
}
/**
* @param pid Process ID to search for.
* @returns Process kernel-mode (system-mode) CPU usage time in ms, or 0 if not found.
*/
export function cpuKernelTime(pid: number): number {
return addon.cpuKernelTime(pid);
}
/**
* @param pid Process ID to search for.
* @returns Process total CPU usage time in ms, or 0 if not found.
*/
export function cpuTime(pid: number): number {
return addon.cpuTime(pid);
}
/**
* @param pid Process ID to search for.
* @returns Total usage in bytes. Windows includes shared working set while linux is more strict.
*
* Note that as this includes virtual memory, it will often be extremely high on MacOS.
*/
export function memInfo(pid: number): number {
return addon.memInfo(pid);
}
/**
* @param pid Process ID to search for.
* @returns Resident/working set size in bytes. Windows includes shared working set while linux is more strict.
*
* Depending on operating system, this may be approximate. It represents the total amount of physical memory being used,
* which does not include any vitual memory.
*/
export function memRSS(pid: number): number {
return addon.memRSS(pid);
}
/**
* @param pid Process ID to search for.
* @returns Number of bytes process has read from file.
*/
export function fileRead(pid: number): number {
return addon.fileRead(pid);
}
/**
* @param pid Process ID to search for.
* @returns Number of bytes process has written to file.
*/
export function fileWrite(pid: number): number {
return addon.fileWrite(pid);
}