Syllo/nvtop
GitHub: Syllo/nvtop
NVTOP 是一款类似 htop 的跨厂商 GPU 和加速器监控工具,通过交互式终端界面实时展示硬件状态及进程资源占用情况。
Stars: 10445 | Forks: 386
# NVTOP
## NVTOP 是什么?
NVTOP 代表 Neat Videocard TOP,是一个类似 (h)top 的 GPU 和加速器任务监控器。它可以处理多个 GPU,并以类似 htop 的方式打印相关信息。
目前支持的厂商包括 AMD(Linux amdgpu 驱动)、Apple(有限的 M1 和 M2 支持)、华为(Ascend)、Intel(Linux i915/Xe 驱动)、NVIDIA(Linux 专有驱动)、高通 Adreno(Linux MSM 驱动)、博通 VideoCore(Linux v3d 驱动)、瑞芯微、MetaX(MXSML 驱动)和燧原科技(Linux EFML 驱动)。
因为一张图片胜过千言万语:

## 目录
- [NVTOP 选项和交互命令](#nvtop-options-and-interactive-commands)
- [交互式设置窗口](#interactive-setup-window)
- [保存偏好设置](#saving-preferences)
- [NVTOP 手册和命令行选项](#nvtop-manual-and-command-line-options)
- [GPU 支持](#gpu-support)
- [AMD](#amd)
- [Intel](#intel)
- [NVIDIA](#nvidia)
- [Adreno](#adreno)
- [Apple](#apple)
- [Ascend](#ascend)(仅在 910B 上测试)
- [VideoCore](#videocore)
- [Rockchip](#rockchip)
- [MetaX](#metax)
- [Enflame](#enflame)
- [构建](#build)
- [特定发行版安装流程](#distribution-specific-installation-process)
- [Ubuntu / Debian](#ubuntu--debian)
- [Ubuntu Impish (21.10) / Debian buster (stable) 及更新版本(stable)](#ubuntu-impish-2110-debian-buster-stable-and-more-recent)
- [Fedora / Red Hat / CentOS](#fedora--red-hat--centos)
- [OpenSUSE](#opensuse)
- [Arch Linux](#arch-linux)
- [Gentoo](#gentoo)
- [AppImage](#appimage)
- [Snap](#snap)
- [Conda-forge](#conda-forge)
- [Docker](#docker)
- [NVTOP 构建](#nvtop-build)
- [故障排除](#troubleshoot)
- [许可证](#license)
## NVTOP 选项和交互命令
### 交互式设置窗口
NVTOP 内置了一个设置实用程序,提供了一种根据您的需求定制界面的方法。
只需按下 ``F2`` 并选择最适合您的选项。

### 保存偏好设置
您可以通过按下 ``F12`` 来保存在设置窗口中设置的偏好设置。
下次运行 ``nvtop`` 时将加载这些偏好设置。
### NVTOP 手册和命令行选项
NVTOP 附带了手册页!
```
man nvtop
```
要获取快速的命令行参数帮助
```
nvtop -h
nvtop --help
```
## GPU 支持
### AMD
NVTOP 通过暴露的 DRM 和 sysfs 接口,支持使用 `amdgpu` 驱动的 AMD GPU。
AMD 在内核 5.14 中引入了 fdinfo 接口([浏览内核源码](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/gpu/drm/amd/amdgpu/amdgpu_fdinfo.c?h=linux-5.14.y))。
因此,要查看使用 AMD GPU 的进程,您需要版本大于或等于 5.14 的内核。
对最新 GPU 的支持已定期合并到 Linux 内核中,因此请为您的 GPU 使用足够新的内核。
### Intel
NVTOP 支持使用 `i915` 或 `xe` Linux 驱动的 Intel GPU。
Intel 在内核 5.19 中引入了 fdinfo 接口([浏览内核源码](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/gpu/drm/i915/i915_drm_client.c?h=linux-5.19.y))。
因此,要查看使用 Intel GPU 的进程,您需要版本大于或等于 5.19 的内核。
Intel 需要 CAP_PERFMON 或 CAP_SYS_ADMIN 权限来访问总内存使用量,您可以运行 `sudo setcap cap_perfmon=ep nvtop` 来授予必要的权限,或者以 root 用户身份运行 nvtop。
### NVIDIA
*NVML 库*不支持对 Kepler 微架构之前的 GPU 进行某些查询。从 GeForce 600、GeForce 800M 开始的后续产品应该可以正常工作。有关受支持 GPU 的更多信息,请查看 [NVML 文档](http://docs.nvidia.com/deploy/nvml-api/nvml-api-reference.html#nvml-api-reference)。
### Adreno
NVTOP 支持使用 `msm` Linux 驱动的 Adreno GPU。
msm 在内核 6.0 中引入了 fdinfo 接口([浏览内核源码](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/gpu/drm/msm/msm_drv.c?h=linux-6.0.y))。
因此,要查看使用 Adreno GPU 的进程,您需要版本大于或等于 6.0 的内核。
### Apple
NVTOP 包含了一些使用 Metal 对 Apple 的初步支持。这仅在为 Apple 构建时支持,并且为 Apple 构建时仅支持此厂商。
**Apple 支持状态**
- Apple 的支持仍在开发中。可能存在一些错误和限制。
### Ascend
NVTOP 通过 DCMI API(版本 6.0.0)支持 Ascend(在 Altas 800 (910B) 上测试)。
目前,DCMI 仅支持有限的 API,缺少 PCIe 代数、tx/rx 吞吐量信息、最大功耗等信息。
### VideoCore
NVTOP 支持 VideoCore(在 raspberrypi 4B 上测试)。
支持 GPU 频率、温度、利用率、每进程利用率、GPU 内存使用率和 H264 解码利用率。
在非 Raspberry Pi OS 上,您需要使用 `linux-rpi 6.12.y` 及以上内核,并确保存在 `/dev/vcio` 设备。
### Rockchip
NVTOP 支持 Rockchip(在 orangepi 5 plus 上测试)。
支持 NPU 频率、温度、利用率。
### MetaX
NVTOP 通过 MXSML LIBRARY 支持 MetaX(在 MXC500 上测试)。
有关 GPU 的更多信息,请查看 [METAX 文档](https://developer.metax-tech.com/doc/index)
### Enflame
NVTOP 通过 EFML LIBRARY 支持 Enflame GCU(在 Enflame S60、Enflame L300 和 Enflame L600 上测试)
GCU(General Compute Unit,通用计算单元)是一种类似于 GPGPU、用于执行通用计算任务的加速器卡。
## 构建
NVTOP 需要几个库才能显示 GPU 信息:
* 驱动用户界面的 *ncurses* 库。
* 这使屏幕看起来很美观。
* 对于 NVIDIA:随 GPU 驱动程序提供的 *NVIDIA 管理库*(*NVML*)。
* 这用于查询 GPU 信息。
* 对于 AMD:用于通过内核驱动程序查询 AMD GPU 的 libdrm 库。
* 对于 METAX:随 GPU 驱动程序提供的 *MetaX 系统管理库*(*MXSML*)。
* 这用于查询 GPU 信息。
* 对于 Enflame:随 GCU 驱动程序提供的 *Enflame 管理库*(*EFML*)。
## 特定发行版安装流程
### Ubuntu / Debian
如果您的发行版提供了 snap 实用程序,请按照 [snap 安装流程](#snap) 获取最新版本的 `nvtop`。
还可以作为独立应用程序使用 [AppImage](#appimage)。
#### Ubuntu Focal (20.04)、Debian buster (stable) 及更新版本
```
sudo apt install nvtop
```
#### Ubuntu PPA
[Quentin Lienhardt](https://github.com/QuentiumYT) 提供了一个 [支持 Ubuntu 20.04 及更新版本的 PPA](https://launchpad.net/~quentiumyt/+archive/ubuntu/nvtop),其中提供了最新版本的 `nvtop`,启用了对 NVIDIA、AMD 和 Intel 的支持。
```
sudo add-apt-repository ppa:quentiumyt/nvtop
sudo apt install nvtop
```
#### 较旧版本
- AMD 和 Intel 依赖
sudo apt install libdrm-dev libsystemd-dev
# Ubuntu 18.04
sudo apt install libudev-dev
- NVIDIA 依赖
- NVIDIA 驱动程序(参见 [Ubuntu Wiki](https://help.ubuntu.com/community/BinaryDriverHowto/Nvidia) 或 [Ubuntu PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa) 或 [Debian Wiki](https://wiki.debian.org/NvidiaGraphicsDrivers#NVIDIA_Proprietary_Driver))
- NVTOP 依赖
- CMake、ncurses 和 Git
sudo apt install cmake libncurses5-dev libncursesw5-dev git
- NVTOP
- 按照 [NVTOP 构建](#nvtop-build) 操作
### Fedora / Red Hat / CentOS
还可以作为独立应用程序使用 [AppImage](#appimage)。
#### Fedora 36 及更新版本
- sudo dnf install nvtop
#### Red Hat Enterprise Linux 8 和 9
- sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E %{rhel}).noarch.rpm
sudo dnf install nvtop
#### CentOS Stream、Rocky Linux、AlmaLinux
- sudo dnf install -y epel-release
sudo dnf install nvtop
#### Fedora / Red Hat / CentOS 的构建流程:
- AMD 和 Intel 依赖
sudo dnf install libdrm-devel systemd-devel
- NVIDIA 依赖
- NVIDIA 驱动程序,**nvml 库需要 CUDA**(参见 [RPM Fusion](https://rpmfusion.org/Howto/NVIDIA))
- NVTOP 依赖
- CMake、ncurses、C++ 和 Git
sudo dnf install cmake ncurses-devel git gcc-c++
- NVTOP
- 按照 [NVTOP 构建](#nvtop-build) 操作
### OpenSUSE
还可以作为独立应用程序使用 [AppImage](#appimage)。
OpenSUSE 的构建流程:
- AMD 依赖
sudo zypper install libdrm-devel
- NVIDIA 依赖
- NVIDIA 驱动程序(参见 [SUSE 支持数据库](https://en.opensuse.org/SDB:NVIDIA_drivers))
- NVTOP 依赖
- CMake、ncurses 和 Git
sudo zypper install cmake ncurses-devel git
- NVTOP
- 按照 [NVTOP 构建](#nvtop-build) 操作
### Arch Linux
- sudo pacman -S nvtop
### Gentoo
- sudo emerge -av nvtop
### AppImage
AppImage 是一个独立的应用程序。只需下载 AppImage,将其设为可执行并运行即可!
- 前往 [发布页面](https://github.com/Syllo/nvtop/releases/latest) 并下载 `nvtop-x86_64.AppImage`
- # 进入下载位置 ** 路径可能因系统而异 **
cd $HOME/Downloads
# 使 AppImage 可执行
chmod u+x nvtop-x86_64.AppImage
# 享受 nvtop
./nvtop-x86_64.AppImage
如果您对其工作原理感兴趣,请访问 [AppImage 网站](https://appimage.org/)。
### Snap
- snap install nvtop
# 添加在 nvtop 内部终止进程的能力
snap connect nvtop:process-control
# 添加检查 GPU 信息的能力(风扇、PCIe、功耗等)
snap connect nvtop:hardware-observe
# AMDGPU 进程列表支持(读取 /proc/)
snap connect nvtop:system-observe
# 获取每进程 GPU 使用率的临时变通方法(读取 /proc//fdinfo)
snap connect nvtop:kubernetes-support
注意:连接命令允许
### Conda-forge
提供了 [`nvtop` 的 conda-forge feedstock](https://github.com/conda-forge/nvtop-feedstock)。
#### conda / mamba / miniforge
```
conda install --channel conda-forge nvtop
```
#### pixi
```
pixi global install nvtop
```
### Docker
- NVIDIA 驱动程序(同上)
- [nvidia-docker](https://github.com/NVIDIA/nvidia-docker)(参见 [容器工具包安装指南](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker))
- git clone https://github.com/Syllo/nvtop.git && cd nvtop
sudo docker build --tag nvtop .
sudo docker run -it --rm --runtime=nvidia --gpus=all --pid=host nvtop
## NVTOP 构建
```
git clone https://github.com/Syllo/nvtop.git
mkdir -p nvtop/build && cd nvtop/build
cmake .. -DNVIDIA_SUPPORT=ON -DAMDGPU_SUPPORT=ON -DINTEL_SUPPORT=ON
make
# 在系统上全局安装
sudo make install
# 或者,在您选择的目录下无权限安装
# cmake .. -DNVIDIA_SUPPORT=ON -DAMDGPU_SUPPORT=ON -DINTEL_SUPPORT=ON -DCMAKE_INSTALL_PREFIX=/path/to/your/dir
# make
# make install
```
如果您使用 **conda** 作为环境管理器并在构建 NVTOP 时遇到错误,请在调用 `cmake` 之前尝试 `conda deactivate`。
构建系统支持多种构建类型(例如 -DCMAKE_BUILD_TYPE=RelWithDebInfo):
* Release:不带调试信息的二进制文件
* RelWithDebInfo:带有调试信息的二进制文件
* Debug:启用警告标志和地址/未定义清理程序进行编译(用于开发目的)
## 故障排除
- 图表显示效果不佳:
- 验证您安装了 ncurses 库的宽字符版本(Debian / Ubuntu 为 libncurses**w**5-dev),清理构建目录并重新开始构建过程。
- **Putty**:通过在菜单 ``Connection > Data > Terminal Details`` 中将 ``Terminal-type string`` 字段设置为 ``putty``,告诉 putty 不要谎报其功能(`$TERM`)。
## 许可证
NVTOP 获得了 GPLv3 许可证或任何后续版本的许可。
您可以在代码库的 COPYING 文件找到许可证的副本,或
在 GNU 网站 <[www.gnu.org/licenses/](http://www.gnu.org/licenses/)> 上找到。
标签:AMD, Bash脚本, CUDA, GPU 监控, Htop, Intel, Linux 工具, M2, Nvtop, 加速器, 华为昇腾, 客户端加密, 性能分析, 硬件信息, 系统运维, 苹果 M1, 资源管理, 驱动, 高通 Adreno