Linux中实现GPU性能实时监测工具:nvitop

2,985 阅读2分钟

引言

  • 使用场景,由于目前测试的项目需要测试GPU占用峰值大小,但是不停的用nvidia-smi来显示不方便,而且测试时候出现了一个程序大多数时候占用峰值为6G,但是偶尔会出现GPU占用达到10G的情况,为了分析原因所以需要一个可以实时监测GPU性能的工具来避免是使用nvidia-smi命令这一诱因。
  • 本文仅作为介绍nvitop的一个基础使用,更多使用方法见参考资料,该文更多为介绍有这么个工具。

nvitop是什么

  • nvitop是一个非常全面的NVIDIA-GPU设备运行状况的实时监控工具,它将GPU利用率,显存占比,卡号使用者,CPU利用率,进程使用时间,命令行等等集于一身,并以差异化的颜色进行个性化展示,安装过程也非常简单,强烈大家推荐使用,让自己在管理服务器的时候事半功倍

[代码地址](GitHub - XuehaiPan/nvitop: An interactive NVIDIA-GPU process viewer and beyond, the one-stop solution for GPU process management.)

[完整的API文档](Welcome to nvitop’s documentation! — nvitop: the one-stop solution for GPU process management. documentation)

界面效果展示如下:

image.png

image.png

安装命令(多种方法但是我只用了pip,其他方法自行测试):

  • 使用pipx进行安装
pipx run nvitop
  • 使用pip3进行安装
pip3 install --upgrade nvitop
  • 使用conda进行安装
conda install -c conda-forge nvitop
  • 从Github拉取最新版本进行安装
pip3 install git+https://github.com/XuehaiPan/nvitop.git#egg=nvitop
  • clone项目并手动安装
git clone --depth=1 https://github.com/XuehaiPan/nvitop.git
cd nvitop
pip3 install .
  • 命令行使用方法:
# Monitor mode (when the display mode is omitted, `NVITOP_MONITOR_MODE` will be used)
$ nvitop  # or use `python3 -m nvitop`

# Automatically configure the display mode according to the terminal size
$ nvitop -m auto     # shortcut: `a` key

# Arbitrarily display as `full` mode
$ nvitop -m full     # shortcut: `f` key

# Arbitrarily display as `compact` mode
$ nvitop -m compact  # shortcut: `c` key

# Specify query devices (by integer indices)
$ nvitop -o 0 1  # only show <GPU 0> and <GPU 1>

# Only show devices in `CUDA_VISIBLE_DEVICES` (by integer indices or UUID strings)
$ nvitop -ov

# Only show GPU processes with the compute context (type: 'C' or 'C+G')
$ nvitop -c

# Use ASCII characters only
$ nvitop -U  # useful for terminals without Unicode support

# For light terminals
$ nvitop --light

# For spectrum-like bar charts (requires the terminal supports 256-color)
$ nvitop --colorful

个人测试结果展示

  • 安装

eb47efe68aceb023ee91fa93637491e.png

  • 实时监控时候的效果:

image.png

  • 退出时候的展示效果

f735e0f072c6aae33b650f3ece7bd9e.png

结尾

  • 该工具同样可以写入程序,但是个人目前用不到,不做更深入介绍,可以看下方参考资料
  • 参考资料