gtop 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gtop-0.1.0/LICENSE +10 -0
- gtop-0.1.0/PKG-INFO +73 -0
- gtop-0.1.0/README.md +53 -0
- gtop-0.1.0/gtop/__init__.py +0 -0
- gtop-0.1.0/gtop/cli.py +56 -0
- gtop-0.1.0/gtop/collector.py +68 -0
- gtop-0.1.0/gtop/config.py +36 -0
- gtop-0.1.0/gtop/device.py +19 -0
- gtop-0.1.0/gtop/metrics.py +69 -0
- gtop-0.1.0/gtop/visualizer.py +68 -0
- gtop-0.1.0/gtop/visualizer_barplots.py +79 -0
- gtop-0.1.0/gtop.egg-info/PKG-INFO +73 -0
- gtop-0.1.0/gtop.egg-info/SOURCES.txt +17 -0
- gtop-0.1.0/gtop.egg-info/dependency_links.txt +1 -0
- gtop-0.1.0/gtop.egg-info/entry_points.txt +2 -0
- gtop-0.1.0/gtop.egg-info/requires.txt +7 -0
- gtop-0.1.0/gtop.egg-info/top_level.txt +1 -0
- gtop-0.1.0/pyproject.toml +31 -0
- gtop-0.1.0/setup.cfg +4 -0
gtop-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 <copyright holders>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
10
|
+
|
gtop-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gtop
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight CLI tool to monitor GPU
|
|
5
|
+
Author-email: Hossein Ghorbanfekr <hgh.comphys@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/hghcomphys/gpu-monitoring-tool
|
|
8
|
+
Project-URL: Repository, https://github.com/hghcomphys/gpu-monitoring-tool
|
|
9
|
+
Keywords: GPU
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: nvidia-ml-py>=11.450.129
|
|
14
|
+
Requires-Dist: plotext>=5.2.8
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: black; extra == "dev"
|
|
17
|
+
Requires-Dist: isort; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# GPU Monitoring Tool
|
|
22
|
+
|
|
23
|
+
A lightweight CLI tool to monitor GPU.
|
|
24
|
+
|
|
25
|
+
## Motivation
|
|
26
|
+
Current GPU monitoring tools often fall short in two ways:
|
|
27
|
+
|
|
28
|
+
* No PCI throughput metrics: RX and TX metrics are important, as data transfer between CPU and GPU is frequently the computational bottleneck.
|
|
29
|
+
* Inflexible metric selection: Users should be able to customize which metrics they need to measure, rather than being limited to predefined sets.
|
|
30
|
+
|
|
31
|
+
<!--
|
|
32
|
+
## Features
|
|
33
|
+
The following features are planned for this tool:
|
|
34
|
+
|
|
35
|
+
[x] Basic metrics like GPU utilization, memory usage, PCI throughput
|
|
36
|
+
[x] Targeting Nvidia GPUs, with potential extension to AMD GPUs
|
|
37
|
+
* A table of GPU processes
|
|
38
|
+
* User-level customization
|
|
39
|
+
* Lightweight and minimal
|
|
40
|
+
* Multiple GPU support
|
|
41
|
+
-->
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
To install `gtop`, run the following command:
|
|
45
|
+
```bash
|
|
46
|
+
pip install --user gtop
|
|
47
|
+
```
|
|
48
|
+
This will install required dependencies and add `gtop` to your user-specific executable path (`~/.local/bin`).
|
|
49
|
+
You can then run `gtop` directly.
|
|
50
|
+
|
|
51
|
+
To uninstall `gtop`, use the following command:
|
|
52
|
+
```bash
|
|
53
|
+
pip uninstall gtop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Examples
|
|
57
|
+
A screenshot of `gtop` in action is shown below:
|
|
58
|
+
|
|
59
|
+
<img src="docs/images/screenshot.png" alt="demo screemshot" width="700"/>
|
|
60
|
+
|
|
61
|
+
### Text-mode
|
|
62
|
+
Text mode can be enabled via `--text-mode` or `-t` flag:
|
|
63
|
+
```bash
|
|
64
|
+
$ gtop -t
|
|
65
|
+
CollectedMetrics(Time=0.10(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
66
|
+
CollectedMetrics(Time=1.13(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
67
|
+
...
|
|
68
|
+
CollectedMetrics(Time=10.14(s), PCI-TX=0.01(MB/s), PCI-RX=42.37(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
69
|
+
CollectedMetrics(Time=11.18(s), PCI-TX=11.02(MB/s), PCI-RX=0.03(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
gtop-0.1.0/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# GPU Monitoring Tool
|
|
2
|
+
|
|
3
|
+
A lightweight CLI tool to monitor GPU.
|
|
4
|
+
|
|
5
|
+
## Motivation
|
|
6
|
+
Current GPU monitoring tools often fall short in two ways:
|
|
7
|
+
|
|
8
|
+
* No PCI throughput metrics: RX and TX metrics are important, as data transfer between CPU and GPU is frequently the computational bottleneck.
|
|
9
|
+
* Inflexible metric selection: Users should be able to customize which metrics they need to measure, rather than being limited to predefined sets.
|
|
10
|
+
|
|
11
|
+
<!--
|
|
12
|
+
## Features
|
|
13
|
+
The following features are planned for this tool:
|
|
14
|
+
|
|
15
|
+
[x] Basic metrics like GPU utilization, memory usage, PCI throughput
|
|
16
|
+
[x] Targeting Nvidia GPUs, with potential extension to AMD GPUs
|
|
17
|
+
* A table of GPU processes
|
|
18
|
+
* User-level customization
|
|
19
|
+
* Lightweight and minimal
|
|
20
|
+
* Multiple GPU support
|
|
21
|
+
-->
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
To install `gtop`, run the following command:
|
|
25
|
+
```bash
|
|
26
|
+
pip install --user gtop
|
|
27
|
+
```
|
|
28
|
+
This will install required dependencies and add `gtop` to your user-specific executable path (`~/.local/bin`).
|
|
29
|
+
You can then run `gtop` directly.
|
|
30
|
+
|
|
31
|
+
To uninstall `gtop`, use the following command:
|
|
32
|
+
```bash
|
|
33
|
+
pip uninstall gtop
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Examples
|
|
37
|
+
A screenshot of `gtop` in action is shown below:
|
|
38
|
+
|
|
39
|
+
<img src="docs/images/screenshot.png" alt="demo screemshot" width="700"/>
|
|
40
|
+
|
|
41
|
+
### Text-mode
|
|
42
|
+
Text mode can be enabled via `--text-mode` or `-t` flag:
|
|
43
|
+
```bash
|
|
44
|
+
$ gtop -t
|
|
45
|
+
CollectedMetrics(Time=0.10(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
46
|
+
CollectedMetrics(Time=1.13(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
47
|
+
...
|
|
48
|
+
CollectedMetrics(Time=10.14(s), PCI-TX=0.01(MB/s), PCI-RX=42.37(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
49
|
+
CollectedMetrics(Time=11.18(s), PCI-TX=11.02(MB/s), PCI-RX=0.03(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
File without changes
|
gtop-0.1.0/gtop/cli.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import time
|
|
3
|
+
import plotext as plt
|
|
4
|
+
from gtop.collector import collect
|
|
5
|
+
from gtop.config import Config
|
|
6
|
+
from gtop.device import free_device, get_device
|
|
7
|
+
from gtop.visualizer import visualize
|
|
8
|
+
from gtop.metrics import Metrics
|
|
9
|
+
from gtop.collector import CollectedMetricsBuffer
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_arguments():
|
|
13
|
+
parser = argparse.ArgumentParser(description="A basic CLI tool to Monitor GPU.")
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--device-gpu-index",
|
|
16
|
+
"-g",
|
|
17
|
+
type=int,
|
|
18
|
+
default=0,
|
|
19
|
+
help="GPU index to monitor (default: 0)",
|
|
20
|
+
)
|
|
21
|
+
parser.add_argument(
|
|
22
|
+
"--update-interval",
|
|
23
|
+
"-u",
|
|
24
|
+
type=float,
|
|
25
|
+
default=1.0,
|
|
26
|
+
help="Time interval between updates in seconds (default: 1.0)",
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"--text-mode",
|
|
30
|
+
"-t",
|
|
31
|
+
action='store_true',
|
|
32
|
+
help="Enable text mode (default: False)",
|
|
33
|
+
)
|
|
34
|
+
return parser.parse_args()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def main():
|
|
38
|
+
cfg = Config.from_parser(args=parse_arguments())
|
|
39
|
+
handle = get_device(cfg)
|
|
40
|
+
metrics = Metrics.for_device(handle)
|
|
41
|
+
buffer = CollectedMetricsBuffer(size=cfg.collector_buffer_size)
|
|
42
|
+
start_time = time.time()
|
|
43
|
+
try:
|
|
44
|
+
while True:
|
|
45
|
+
collected_metrics = collect(metrics, handle, start_time, cfg)
|
|
46
|
+
buffer.append(collected_metrics)
|
|
47
|
+
visualize(buffer, plt, cfg)
|
|
48
|
+
time.sleep(cfg.update_interval)
|
|
49
|
+
except KeyboardInterrupt:
|
|
50
|
+
pass
|
|
51
|
+
finally:
|
|
52
|
+
free_device()
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
main()
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import time
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
from typing import List
|
|
4
|
+
from gtop.config import Config
|
|
5
|
+
from gtop.device import DeviceHandle
|
|
6
|
+
from gtop.metrics import Metrics
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class CollectedMetrics:
|
|
11
|
+
timestamp: float
|
|
12
|
+
pci_tx: float
|
|
13
|
+
pci_rx: float
|
|
14
|
+
process: float
|
|
15
|
+
memory: float
|
|
16
|
+
|
|
17
|
+
def __repr__(self) -> str:
|
|
18
|
+
return (
|
|
19
|
+
f"{self.__class__.__name__}("
|
|
20
|
+
f"Time={self.timestamp:0.2f}(s)"
|
|
21
|
+
f", PCI-TX={self.pci_tx:0.2f}(MB/s)"
|
|
22
|
+
f", PCI-RX={self.pci_rx:0.2f}(MB/s)"
|
|
23
|
+
f", Process={self.process:0.2f}(%)"
|
|
24
|
+
f", Memory={self.memory:0.2f}(%)"
|
|
25
|
+
")"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class CollectedMetricsBuffer:
|
|
31
|
+
size: int
|
|
32
|
+
buffer: List[CollectedMetrics] = field(default_factory=list)
|
|
33
|
+
|
|
34
|
+
def append(self, item: CollectedMetrics) -> None:
|
|
35
|
+
self.buffer.append(item)
|
|
36
|
+
if len(self.buffer) > self.size:
|
|
37
|
+
self.buffer = self.buffer[-self.size :]
|
|
38
|
+
|
|
39
|
+
def __iter__(self):
|
|
40
|
+
for item in self.buffer:
|
|
41
|
+
yield item
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def last(self) -> CollectedMetrics:
|
|
45
|
+
return self.buffer[-1]
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def first(self) -> CollectedMetrics:
|
|
49
|
+
return self.buffer[0]
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def collect(
|
|
53
|
+
metrics: Metrics,
|
|
54
|
+
handle: DeviceHandle,
|
|
55
|
+
start_time: float,
|
|
56
|
+
cfg: Config,
|
|
57
|
+
) -> CollectedMetrics:
|
|
58
|
+
now = time.time() - start_time
|
|
59
|
+
tx, rx = metrics.pci_throughput.measure()
|
|
60
|
+
process = metrics.gpu_processs.measure()
|
|
61
|
+
mem_used, mem_total = metrics.gpu_memory.measure()
|
|
62
|
+
return CollectedMetrics(
|
|
63
|
+
timestamp=max(now, cfg.collector_min_time_interval),
|
|
64
|
+
pci_tx=tx,
|
|
65
|
+
pci_rx=rx,
|
|
66
|
+
process=process,
|
|
67
|
+
memory=mem_used / mem_total * 100,
|
|
68
|
+
)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from argparse import Namespace
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class Config:
|
|
9
|
+
device_gpu_index: int = 0
|
|
10
|
+
update_interval: float = 1.0
|
|
11
|
+
text_mode: bool = False
|
|
12
|
+
collector_buffer_size: int = 60
|
|
13
|
+
collector_min_time_interval: float = 0.1
|
|
14
|
+
visualizer_plot_size: Optional[tuple[int, int]] = None
|
|
15
|
+
visualizer_plot_theme: Optional[str] = "matrix"
|
|
16
|
+
visualizer_plot_marker: str = "dot"
|
|
17
|
+
visualizer_plot_time_range: float = 60
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def from_parser(
|
|
21
|
+
cls,
|
|
22
|
+
args: Namespace,
|
|
23
|
+
cfg: Optional[Config] = None,
|
|
24
|
+
) -> Config:
|
|
25
|
+
if cfg is None:
|
|
26
|
+
cfg = get_default_config()
|
|
27
|
+
return cls(
|
|
28
|
+
**{
|
|
29
|
+
**cfg.__dict__,
|
|
30
|
+
**{k: v for k, v in vars(args).items() if v is not None},
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_default_config():
|
|
36
|
+
return Config()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pynvml
|
|
3
|
+
from gtop.config import Config
|
|
4
|
+
|
|
5
|
+
DeviceHandle = pynvml.struct_c_nvmlDevice_t
|
|
6
|
+
|
|
7
|
+
def get_device(cfg: Config) -> DeviceHandle:
|
|
8
|
+
try:
|
|
9
|
+
pynvml.nvmlInit()
|
|
10
|
+
handle = pynvml.nvmlDeviceGetHandleByIndex(cfg.device_gpu_index)
|
|
11
|
+
|
|
12
|
+
except pynvml.NVMLError as error:
|
|
13
|
+
print(f"GPU Not Detected! ({error})")
|
|
14
|
+
sys.exit(1)
|
|
15
|
+
return handle
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def free_device() -> None:
|
|
19
|
+
pynvml.nvmlShutdown()
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Protocol
|
|
4
|
+
import pynvml
|
|
5
|
+
|
|
6
|
+
from gtop.device import DeviceHandle
|
|
7
|
+
from typing import Any, Tuple
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class MetricInterface(Protocol):
|
|
11
|
+
def measure() -> Any:
|
|
12
|
+
...
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass
|
|
16
|
+
class PciThroughputMetric(MetricInterface):
|
|
17
|
+
handle: DeviceHandle
|
|
18
|
+
|
|
19
|
+
def measure(self) -> Tuple[float, float]:
|
|
20
|
+
tx = (
|
|
21
|
+
pynvml.nvmlDeviceGetPcieThroughput(
|
|
22
|
+
self.handle,
|
|
23
|
+
pynvml.NVML_PCIE_UTIL_TX_BYTES,
|
|
24
|
+
)
|
|
25
|
+
/ 1024
|
|
26
|
+
)
|
|
27
|
+
rx = (
|
|
28
|
+
pynvml.nvmlDeviceGetPcieThroughput(
|
|
29
|
+
self.handle,
|
|
30
|
+
pynvml.NVML_PCIE_UTIL_RX_BYTES,
|
|
31
|
+
)
|
|
32
|
+
/ 1024
|
|
33
|
+
)
|
|
34
|
+
return tx, rx # MB
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@dataclass
|
|
38
|
+
class GpuProcessMetric(MetricInterface):
|
|
39
|
+
handle: DeviceHandle
|
|
40
|
+
|
|
41
|
+
def measure(self) -> float:
|
|
42
|
+
util = pynvml.nvmlDeviceGetUtilizationRates(self.handle)
|
|
43
|
+
return util.gpu
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class GpuMemoryMetric(MetricInterface):
|
|
48
|
+
handle: DeviceHandle
|
|
49
|
+
|
|
50
|
+
def measure(self) -> Tuple[float, float]:
|
|
51
|
+
mem_info = pynvml.nvmlDeviceGetMemoryInfo(self.handle)
|
|
52
|
+
mem_used = int(mem_info.used / 1024**2)
|
|
53
|
+
mem_total = int(mem_info.total / 1024**2)
|
|
54
|
+
return mem_used, mem_total # MB
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass
|
|
58
|
+
class Metrics:
|
|
59
|
+
pci_throughput: PciThroughputMetric
|
|
60
|
+
gpu_processs: GpuProcessMetric
|
|
61
|
+
gpu_memory: GpuMemoryMetric
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def for_device(cls, handle: DeviceHandle):
|
|
65
|
+
return cls(
|
|
66
|
+
PciThroughputMetric(handle),
|
|
67
|
+
GpuProcessMetric(handle),
|
|
68
|
+
GpuMemoryMetric(handle),
|
|
69
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from gtop.config import Config
|
|
2
|
+
from gtop.collector import CollectedMetricsBuffer
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
PlotHandle = Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def visualize(
|
|
9
|
+
inputs: CollectedMetricsBuffer,
|
|
10
|
+
plt: PlotHandle,
|
|
11
|
+
cfg: Config,
|
|
12
|
+
) -> None:
|
|
13
|
+
if cfg.text_mode:
|
|
14
|
+
printout_metrics(inputs)
|
|
15
|
+
return
|
|
16
|
+
plt.clt()
|
|
17
|
+
plt.cld()
|
|
18
|
+
plt.subplots(1, 2)
|
|
19
|
+
plt.theme(cfg.visualizer_plot_theme)
|
|
20
|
+
plt.plotsize(cfg.visualizer_plot_size)
|
|
21
|
+
# --------------
|
|
22
|
+
plt.subplot(1, 2)
|
|
23
|
+
timestamps = [input.timestamp for input in inputs]
|
|
24
|
+
pci_tx_values = [input.pci_tx for input in inputs]
|
|
25
|
+
pci_rx_values = [input.pci_rx for input in inputs]
|
|
26
|
+
plt.plot(
|
|
27
|
+
timestamps,
|
|
28
|
+
pci_tx_values,
|
|
29
|
+
label="TX",
|
|
30
|
+
marker=cfg.visualizer_plot_marker,
|
|
31
|
+
)
|
|
32
|
+
plt.plot(
|
|
33
|
+
timestamps,
|
|
34
|
+
pci_rx_values,
|
|
35
|
+
label="RX",
|
|
36
|
+
marker=cfg.visualizer_plot_marker,
|
|
37
|
+
)
|
|
38
|
+
plt.title("GPU PCIe Throughput")
|
|
39
|
+
plt.xlabel("Time (s)")
|
|
40
|
+
plt.ylabel("Throughput (MB/s)")
|
|
41
|
+
plt.ylim(0, max(1, max(pci_tx_values + pci_rx_values) * 1.2))
|
|
42
|
+
|
|
43
|
+
# --------------
|
|
44
|
+
plt.subplot(1, 1)
|
|
45
|
+
process_values = [input.process for input in inputs]
|
|
46
|
+
memory_values = [input.memory for input in inputs]
|
|
47
|
+
plt.plot(
|
|
48
|
+
timestamps,
|
|
49
|
+
process_values,
|
|
50
|
+
label="Process",
|
|
51
|
+
marker=cfg.visualizer_plot_marker,
|
|
52
|
+
)
|
|
53
|
+
plt.plot(
|
|
54
|
+
timestamps,
|
|
55
|
+
memory_values,
|
|
56
|
+
label="Memory",
|
|
57
|
+
marker=cfg.visualizer_plot_marker,
|
|
58
|
+
)
|
|
59
|
+
plt.title("GPU Utilization")
|
|
60
|
+
plt.xlabel("Time (s)")
|
|
61
|
+
plt.ylabel("Utilization (%)")
|
|
62
|
+
plt.ylim(0, 100)
|
|
63
|
+
|
|
64
|
+
plt.show()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def printout_metrics(inputs: CollectedMetricsBuffer) -> None:
|
|
68
|
+
print(inputs.last)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from gtop.config import Config
|
|
2
|
+
from gtop.metrics import Metrics
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
PlotHandle = Any
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def visualize(
|
|
9
|
+
metrics: Metrics,
|
|
10
|
+
plt: PlotHandle,
|
|
11
|
+
cfg: Config,
|
|
12
|
+
) -> None:
|
|
13
|
+
plt.clt()
|
|
14
|
+
plt.cld()
|
|
15
|
+
plt.theme(cfg.visualizer_plot_theme)
|
|
16
|
+
plt.plotsize(cfg.visualizer_plot_size)
|
|
17
|
+
plt.subplots(1, 2)
|
|
18
|
+
|
|
19
|
+
# plt.subplot(1, 1)
|
|
20
|
+
# names = [
|
|
21
|
+
# "Process",
|
|
22
|
+
# "Memory",
|
|
23
|
+
# "TX",
|
|
24
|
+
# "RX",
|
|
25
|
+
# ]
|
|
26
|
+
# values = [
|
|
27
|
+
# metrics.util_values[-1],
|
|
28
|
+
# metrics.mem_values[-1],
|
|
29
|
+
# metrics.rx_values[-1],
|
|
30
|
+
# metrics.tx_values[-1],
|
|
31
|
+
# ]
|
|
32
|
+
# plt.simple_bar(
|
|
33
|
+
# names,
|
|
34
|
+
# values,
|
|
35
|
+
# # width=100,
|
|
36
|
+
# title="GPU Utilization",
|
|
37
|
+
# )
|
|
38
|
+
# plt.xlabel("Percentage")
|
|
39
|
+
# plt.xlim(0, 100)
|
|
40
|
+
|
|
41
|
+
# --------------
|
|
42
|
+
plt.subplot(1, 1)
|
|
43
|
+
plt.plot(
|
|
44
|
+
metrics.times,
|
|
45
|
+
metrics.util_values,
|
|
46
|
+
label="Process",
|
|
47
|
+
marker=cfg.visualizer_plot_marker,
|
|
48
|
+
)
|
|
49
|
+
plt.plot(
|
|
50
|
+
metrics.times,
|
|
51
|
+
metrics.mem_values,
|
|
52
|
+
label="Memory",
|
|
53
|
+
marker=cfg.visualizer_plot_marker,
|
|
54
|
+
)
|
|
55
|
+
plt.title("GPU Utilization")
|
|
56
|
+
plt.xlabel("Time (s)")
|
|
57
|
+
plt.ylabel("Utilization (%)")
|
|
58
|
+
plt.ylim(0, 100)
|
|
59
|
+
# --------------
|
|
60
|
+
plt.subplot(1, 2)
|
|
61
|
+
plt.plot(
|
|
62
|
+
metrics.times,
|
|
63
|
+
metrics.tx_values,
|
|
64
|
+
label="TX",
|
|
65
|
+
marker=cfg.visualizer_plot_marker,
|
|
66
|
+
)
|
|
67
|
+
plt.plot(
|
|
68
|
+
metrics.times,
|
|
69
|
+
metrics.rx_values,
|
|
70
|
+
label="RX",
|
|
71
|
+
marker=cfg.visualizer_plot_marker,
|
|
72
|
+
)
|
|
73
|
+
plt.title("GPU PCIe Throughput")
|
|
74
|
+
plt.xlabel("Time (s)")
|
|
75
|
+
plt.ylabel("Throughput (MB/s)")
|
|
76
|
+
plt.ylim(0, max(1, max(metrics.tx_values + metrics.rx_values) * 1.2))
|
|
77
|
+
|
|
78
|
+
plt.sleep(cfg.update_interval)
|
|
79
|
+
plt.show()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gtop
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A lightweight CLI tool to monitor GPU
|
|
5
|
+
Author-email: Hossein Ghorbanfekr <hgh.comphys@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/hghcomphys/gpu-monitoring-tool
|
|
8
|
+
Project-URL: Repository, https://github.com/hghcomphys/gpu-monitoring-tool
|
|
9
|
+
Keywords: GPU
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: nvidia-ml-py>=11.450.129
|
|
14
|
+
Requires-Dist: plotext>=5.2.8
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: black; extra == "dev"
|
|
17
|
+
Requires-Dist: isort; extra == "dev"
|
|
18
|
+
Requires-Dist: pytest; extra == "dev"
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# GPU Monitoring Tool
|
|
22
|
+
|
|
23
|
+
A lightweight CLI tool to monitor GPU.
|
|
24
|
+
|
|
25
|
+
## Motivation
|
|
26
|
+
Current GPU monitoring tools often fall short in two ways:
|
|
27
|
+
|
|
28
|
+
* No PCI throughput metrics: RX and TX metrics are important, as data transfer between CPU and GPU is frequently the computational bottleneck.
|
|
29
|
+
* Inflexible metric selection: Users should be able to customize which metrics they need to measure, rather than being limited to predefined sets.
|
|
30
|
+
|
|
31
|
+
<!--
|
|
32
|
+
## Features
|
|
33
|
+
The following features are planned for this tool:
|
|
34
|
+
|
|
35
|
+
[x] Basic metrics like GPU utilization, memory usage, PCI throughput
|
|
36
|
+
[x] Targeting Nvidia GPUs, with potential extension to AMD GPUs
|
|
37
|
+
* A table of GPU processes
|
|
38
|
+
* User-level customization
|
|
39
|
+
* Lightweight and minimal
|
|
40
|
+
* Multiple GPU support
|
|
41
|
+
-->
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
To install `gtop`, run the following command:
|
|
45
|
+
```bash
|
|
46
|
+
pip install --user gtop
|
|
47
|
+
```
|
|
48
|
+
This will install required dependencies and add `gtop` to your user-specific executable path (`~/.local/bin`).
|
|
49
|
+
You can then run `gtop` directly.
|
|
50
|
+
|
|
51
|
+
To uninstall `gtop`, use the following command:
|
|
52
|
+
```bash
|
|
53
|
+
pip uninstall gtop
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Examples
|
|
57
|
+
A screenshot of `gtop` in action is shown below:
|
|
58
|
+
|
|
59
|
+
<img src="docs/images/screenshot.png" alt="demo screemshot" width="700"/>
|
|
60
|
+
|
|
61
|
+
### Text-mode
|
|
62
|
+
Text mode can be enabled via `--text-mode` or `-t` flag:
|
|
63
|
+
```bash
|
|
64
|
+
$ gtop -t
|
|
65
|
+
CollectedMetrics(Time=0.10(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
66
|
+
CollectedMetrics(Time=1.13(s), PCI-TX=0.00(MB/s), PCI-RX=0.00(MB/s), Process=0.00(%), Memory=2.31(%))
|
|
67
|
+
...
|
|
68
|
+
CollectedMetrics(Time=10.14(s), PCI-TX=0.01(MB/s), PCI-RX=42.37(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
69
|
+
CollectedMetrics(Time=11.18(s), PCI-TX=11.02(MB/s), PCI-RX=0.03(MB/s), Process=100.00(%), Memory=3.74(%))
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
gtop/__init__.py
|
|
5
|
+
gtop/cli.py
|
|
6
|
+
gtop/collector.py
|
|
7
|
+
gtop/config.py
|
|
8
|
+
gtop/device.py
|
|
9
|
+
gtop/metrics.py
|
|
10
|
+
gtop/visualizer.py
|
|
11
|
+
gtop/visualizer_barplots.py
|
|
12
|
+
gtop.egg-info/PKG-INFO
|
|
13
|
+
gtop.egg-info/SOURCES.txt
|
|
14
|
+
gtop.egg-info/dependency_links.txt
|
|
15
|
+
gtop.egg-info/entry_points.txt
|
|
16
|
+
gtop.egg-info/requires.txt
|
|
17
|
+
gtop.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
gtop
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools]
|
|
6
|
+
py-modules = ["gtop"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "gtop"
|
|
10
|
+
version = "0.1.0"
|
|
11
|
+
description = "A lightweight CLI tool to monitor GPU"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
authors = [{ name = "Hossein Ghorbanfekr", email = "hgh.comphys@gmail.com" }]
|
|
14
|
+
license = "MIT"
|
|
15
|
+
license-files= ["LICENSE"]
|
|
16
|
+
keywords = ["GPU"]
|
|
17
|
+
dependencies = [
|
|
18
|
+
'nvidia-ml-py>=11.450.129',
|
|
19
|
+
'plotext>=5.2.8',
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.8"
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
dev = ["black", "isort", "pytest"]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://github.com/hghcomphys/gpu-monitoring-tool"
|
|
28
|
+
Repository = "https://github.com/hghcomphys/gpu-monitoring-tool"
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
gtop = "gtop.cli:main"
|
gtop-0.1.0/setup.cfg
ADDED