|
| 1 | + |
| 2 | +/** |
| 3 | + * @file index.d.ts |
| 4 | + * @author @2kai2kai2 |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2025 2kai2kai2 |
| 7 | + * This program is free software: you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation, either version 3 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +/** |
| 22 | + * @param pid Process ID to search for. |
| 23 | + * @returns Process user-mode CPU usage time in ms, or 0 if not found. |
| 24 | + */ |
| 25 | +declare function cpuUserTime(pid: number): number; |
| 26 | + |
| 27 | +/** |
| 28 | + * @param pid Process ID to search for. |
| 29 | + * @returns Process kernel-mode (system-mode) CPU usage time in ms, or 0 if not found. |
| 30 | + */ |
| 31 | +declare function cpuKernelTime(pid: number): number; |
| 32 | + |
| 33 | +/** |
| 34 | + * @param pid Process ID to search for. |
| 35 | + * @returns Process total CPU usage time in ms, or 0 if not found. |
| 36 | + */ |
| 37 | +declare function cpuTime(pid: number): number; |
| 38 | + |
| 39 | +/** |
| 40 | + * @param pid Process ID to search for. |
| 41 | + * @returns Total usage in bytes. Windows includes shared working set while linux is more strict. |
| 42 | + * |
| 43 | + * Note that as this includes virtual memory, it will often be extremely high on MacOS. |
| 44 | + */ |
| 45 | +declare function memInfo(pid: number): number; |
| 46 | + |
| 47 | +/** |
| 48 | + * @param pid Process ID to search for. |
| 49 | + * @returns Resident/working set size in bytes. Windows includes shared working set while linux is more strict. |
| 50 | + * |
| 51 | + * Depending on operating system, this may be approximate. It represents the total amount of physical memory being used, |
| 52 | + * which does not include any vitual memory. |
| 53 | + */ |
| 54 | +declare function memRSS(pid: number): number; |
| 55 | + |
| 56 | +/** |
| 57 | + * @param pid Process ID to search for. |
| 58 | + * @returns Number of bytes process has read from file. |
| 59 | + */ |
| 60 | +declare function fileRead(pid: number): number; |
| 61 | + |
| 62 | +/** |
| 63 | + * @param pid Process ID to search for. |
| 64 | + * @returns Number of bytes process has written to file. |
| 65 | + */ |
| 66 | +declare function fileWrite(pid: number): number; |
| 67 | + |
| 68 | +/** |
| 69 | + * The return type for `NvidiaGPU::utilization` that shows utilization of computing resources. |
| 70 | + * |
| 71 | + * NOTE: currently only contains smUtilization (which is what most people need), |
| 72 | + * but things like video encode/decode accelerator data is not yet implemented. |
| 73 | + */ |
| 74 | +declare interface NvidiaGPUUtilization { |
| 75 | + /** |
| 76 | + * The utilization of the device's Steaming Multiprocessors (SMs) |
| 77 | + * |
| 78 | + * This includes most 3D and compute operations. |
| 79 | + */ |
| 80 | + smUtilization: number |
| 81 | +} |
| 82 | + |
| 83 | +/** |
| 84 | + * A handle for getting process data from a single Nvidia GPU (internally uses [NVML](https://docs.nvidia.com/deploy/nvml-api/nvml-api-reference.html)) |
| 85 | + */ |
| 86 | +declare class NvidiaGPU { |
| 87 | + /** |
| 88 | + * A good entrypoint, will return handles for all Nvidia GPUs on this computer. |
| 89 | + * |
| 90 | + * If the computer does not have Nvidia GPUs (or drivers) it will be an empty array. |
| 91 | + * |
| 92 | + * @throws |
| 93 | + */ |
| 94 | + static allGPUs(): NvidiaGPU[]; |
| 95 | + |
| 96 | + /** |
| 97 | + * @param deviceIdx The index of the GPU to get a handle for. |
| 98 | + * @param pid The process id to search for. |
| 99 | + * |
| 100 | + * @throws An error if `deviceIdx` is invalid or if we do not have permission to access it. |
| 101 | + * @throws |
| 102 | + */ |
| 103 | + constructor(deviceIdx: number, pid: number); |
| 104 | + |
| 105 | + /** |
| 106 | + * Returns the process's compute utilization since the last query |
| 107 | + * (or if the last query was a long time ago/never, since the start of the stored buffer). |
| 108 | + */ |
| 109 | + utilization(): NvidiaGPUUtilization; |
| 110 | +} |
0 commit comments