一、参考资料
nvtop 代码仓库:https://github.com/Syllo/nvtop
二、安装nvtop(源码)
注意事项:旧版本的ubuntu,例如Ubuntu18.04、Ubuntu16.04,需要通过源码安装。
1. 总体步骤
# 安装依赖
sudo apt install cmake libncurses5-dev libncursesw5-dev git
# 下载源码
git clone https://github.com/Syllo/nvtop.git
mkdir -p nvtop/build && cd nvtop/build
# cmake编译
cmake ..
# 编译
make
# 安装
sudo make install
2. cmake编译
yoyo@yoyo:~/360Downloads/nvtop/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Setting build type to 'Release' as none was specified.
-- Looking for cbreak in /usr/lib/x86_64-linux-gnu/libncursesw.so
-- Looking for cbreak in /usr/lib/x86_64-linux-gnu/libncursesw.so - found
-- Found Curses: /usr/lib/x86_64-linux-gnu/libncursesw.so
-- Performing Test HAS_REALLOCARRAY
-- Performing Test HAS_REALLOCARRAY - Failed
-- Found UDev: /usr/lib/x86_64-linux-gnu/libudev.so (found version "229")
-- Libudev stable: TRUE
-- Could NOT find Systemd (missing: SYSTEMD_INCLUDE_DIR) (found version "229")
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Found Libdrm: /usr/lib/x86_64-linux-gnu/libdrm.so (found version "2.4.91")
-- Found libdrm; Enabling support
-- Performing Test compiler_has-Wall
-- Performing Test compiler_has-Wall - Success
-- Performing Test compiler_has-Wextra
-- Performing Test compiler_has-Wextra - Success
-- Performing Test compiler_has-Waddress
-- Performing Test compiler_has-Waddress - Success
-- Performing Test compiler_has-Waggressive-loop-optimizations
-- Performing Test compiler_has-Waggressive-loop-optimizations - Success
-- Performing Test compiler_has-Wbad-function-cast
-- Performing Test compiler_has-Wbad-function-cast - Success
-- Performing Test compiler_has-Wmissing-declarations
-- Performing Test compiler_has-Wmissing-declarations - Success
-- Performing Test compiler_has-Wmissing-parameter-type
-- Performing Test compiler_has-Wmissing-parameter-type - Success
-- Performing Test compiler_has-Wmissing-prototypes
-- Performing Test compiler_has-Wmissing-prototypes - Success
-- Performing Test compiler_has-Wnested-externs
-- Performing Test compiler_has-Wnested-externs - Success
-- Performing Test compiler_has-Wold-style-declaration
-- Performing Test compiler_has-Wold-style-declaration - Success
-- Performing Test compiler_has-Wold-style-definition
-- Performing Test compiler_has-Wold-style-definition - Success
-- Performing Test compiler_has-Wstrict-prototypes
-- Performing Test compiler_has-Wstrict-prototypes - Success
-- Performing Test compiler_has-Wpointer-sign
-- Performing Test compiler_has-Wpointer-sign - Success
-- Performing Test compiler_has-Wdouble-promotion
-- Performing Test compiler_has-Wdouble-promotion - Success
-- Performing Test compiler_has-Wuninitialized
-- Performing Test compiler_has-Wuninitialized - Success
-- Performing Test compiler_has-Winit-self
-- Performing Test compiler_has-Winit-self - Success
-- Performing Test compiler_has-Wstrict-aliasing
-- Performing Test compiler_has-Wstrict-aliasing - Success
-- Performing Test compiler_has-Wsuggest-attribute-const
-- Performing Test compiler_has-Wsuggest-attribute-const - Success
-- Performing Test compiler_has-Wtrampolines
-- Performing Test compiler_has-Wtrampolines - Success
-- Performing Test compiler_has-Wfloat-equal
-- Performing Test compiler_has-Wfloat-equal - Success
-- Performing Test compiler_has-Wshadow
-- Performing Test compiler_has-Wshadow - Success
-- Performing Test compiler_has-Wunsafe-loop-optimizations
-- Performing Test compiler_has-Wunsafe-loop-optimizations - Success
-- Performing Test compiler_has-Wfloat-conversion
-- Performing Test compiler_has-Wfloat-conversion - Success
-- Performing Test compiler_has-Wlogical-op
-- Performing Test compiler_has-Wlogical-op - Success
-- Performing Test compiler_has-Wnormalized
-- Performing Test compiler_has-Wnormalized - Success
-- Performing Test compiler_has-Wdisabled-optimization
-- Performing Test compiler_has-Wdisabled-optimization - Success
-- Performing Test compiler_has-Whsa
-- Performing Test compiler_has-Whsa - Success
-- Performing Test compiler_has-Wunused-result
-- Performing Test compiler_has-Wunused-result - Success
-- Performing Test compiler_has-Werror-implicit-function-declaration
-- Performing Test compiler_has-Werror-implicit-function-declaration - Success
-- Performing Test compiler_has-Wformat
-- Performing Test compiler_has-Wformat - Success
-- Performing Test compiler_has-Wformat-security
-- Performing Test compiler_has-Wformat-security - Success
-- Performing Test linker_has-Wl_-z_relro
-- Performing Test linker_has-Wl_-z_relro - Success
-- Could NOT find GTest (missing: GTEST_LIBRARY GTEST_MAIN_LIBRARY)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/yoyo/360Downloads/nvtop/build
3. make编译
yoyo@yoyo:~/360Downloads/nvtop/build$ make
[ 3%] Building C object src/CMakeFiles/nvtop.dir/nvtop.c.o
[ 7%] Building C object src/CMakeFiles/nvtop.dir/interface.c.o
[ 11%] Building C object src/CMakeFiles/nvtop.dir/interface_layout_selection.c.o
[ 15%] Building C object src/CMakeFiles/nvtop.dir/interface_options.c.o
[ 19%] Building C object src/CMakeFiles/nvtop.dir/interface_setup_win.c.o
[ 23%] Building C object src/CMakeFiles/nvtop.dir/interface_ring_buffer.c.o
[ 26%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo.c.o
[ 30%] Building C object src/CMakeFiles/nvtop.dir/time.c.o
[ 34%] Building C object src/CMakeFiles/nvtop.dir/plot.c.o
[ 38%] Building C object src/CMakeFiles/nvtop.dir/ini.c.o
[ 42%] Building C object src/CMakeFiles/nvtop.dir/get_process_info_linux.c.o
[ 46%] Building C object src/CMakeFiles/nvtop.dir/extract_processinfo_fdinfo.c.o
[ 50%] Building C object src/CMakeFiles/nvtop.dir/info_messages_linux.c.o
[ 53%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_nvidia.c.o
[ 57%] Building C object src/CMakeFiles/nvtop.dir/device_discovery_linux.c.o
[ 61%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_amdgpu.c.o
[ 65%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_amdgpu_utils.c.o
[ 69%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o
[ 73%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm_utils.c.o
[ 76%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_intel.c.o
[ 80%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_panfrost.c.o
[ 84%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_panfrost_utils.c.o
[ 88%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_panthor.c.o
[ 92%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_panthor_utils.c.o
[ 96%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_mali_common.c.o
[100%] Linking C executable nvtop
[100%] Built target nvtop
4. make install 安装
yoyo@yoyo:~/360Downloads/nvtop/build$ sudo make install
Consolidate compiler generated dependencies of target nvtop
[100%] Built target nvtop
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/bin/nvtop
-- Set runtime path of "/usr/local/bin/nvtop" to "/usr/local/lib"
-- Installing: /usr/local/share/man/man1/nvtop.1
-- Installing: /usr/local/share/icons/nvtop.svg
-- Installing: /usr/local/share/applications/nvtop.desktop
-- Installing: /usr/local/share/metainfo/nvtop.metainfo.xml
5. 安装成功
yoyo@yoyo:~/360Downloads/nvtop/build$ nvtop -h
nvtop version 3.1.0
Available options:
-d --delay : Select the refresh rate (1 == 0.1s)
-v --version : Print the version and exit
-c --config-file : Provide a custom config file location to load/save preferences
-p --no-plot : Disable bar plot
-P --no-processes : Disable process list
-r --reverse-abs : Reverse abscissa: plot the recent data left and older on the right
-C --no-color : No colors
line information
-f --freedom-unit : Use fahrenheit
-i --gpu-info : Show bar with additional GPU parametres
-E --encode-hide : Set encode/decode auto hide time in seconds (default 30s, negative = always on screen)
-h --help : Print help and exit
三、安装nvitop
nvitop 文档:https://nvitop.readthedocs.io/en/latest/
pip3 install --upgrade nvitop
四、FAQ
Q:fatal error: libdrm/msm_drm.h: 没有那个文件或目录
yoyo@yoyo:~/360Downloads/nvtop/build$ make
Consolidate compiler generated dependencies of target nvtop
[ 3%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o
/home/yoyo/360Downloads/nvtop/src/extract_gpuinfo_msm.c:31:10: fatal error: libdrm/msm_drm.h: 没有那个文件或目录
#include <libdrm/msm_drm.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
src/CMakeFiles/nvtop.dir/build.make:313: recipe for target 'src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o' failed
make[2]: *** [src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'src/CMakeFiles/nvtop.dir/all' failed
make[1]: *** [src/CMakeFiles/nvtop.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
解决方法:查找 msm_drm.h
文件,修改 nvtop/src/extract_gpuinfo_msm.c
文件。
查找 msm_drm.h
文件:
yoyo@yoyo:~/360Downloads/nvtop/build$ find / -name msm_drm.h
...
...
...
/usr/src/linux-headers-4.15.0-112/include/uapi/drm/msm_drm.h
/usr/src/linux-headers-4.15.0-142/include/uapi/drm/msm_drm.h
/usr/include/drm/msm_drm.h
修改 nvtop/src/extract_gpuinfo_msm.c
文件:
#include <libdrm/msm_drm.h>
修改为
#include <drm/msm_drm.h>
Q:nvtop/src/extract_gpuinfo_msm.c:504:45: error: ‘MSM_PARAM_MAX_FREQ’ undeclared (first use in this function); did you mean ‘MSM_PARAM_GPU_ID’?
yoyo@yoyo:~/360Downloads/nvtop/build$ make
[ 3%] Building C object src/CMakeFiles/nvtop.dir/nvtop.c.o
[ 7%] Building C object src/CMakeFiles/nvtop.dir/interface.c.o
[ 11%] Building C object src/CMakeFiles/nvtop.dir/interface_layout_selection.c.o
[ 15%] Building C object src/CMakeFiles/nvtop.dir/interface_options.c.o
[ 19%] Building C object src/CMakeFiles/nvtop.dir/interface_setup_win.c.o
[ 23%] Building C object src/CMakeFiles/nvtop.dir/interface_ring_buffer.c.o
[ 26%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo.c.o
[ 30%] Building C object src/CMakeFiles/nvtop.dir/time.c.o
[ 34%] Building C object src/CMakeFiles/nvtop.dir/plot.c.o
[ 38%] Building C object src/CMakeFiles/nvtop.dir/ini.c.o
[ 42%] Building C object src/CMakeFiles/nvtop.dir/get_process_info_linux.c.o
[ 46%] Building C object src/CMakeFiles/nvtop.dir/extract_processinfo_fdinfo.c.o
[ 50%] Building C object src/CMakeFiles/nvtop.dir/info_messages_linux.c.o
[ 53%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_nvidia.c.o
[ 57%] Building C object src/CMakeFiles/nvtop.dir/device_discovery_linux.c.o
[ 61%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_amdgpu.c.o
[ 65%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_amdgpu_utils.c.o
[ 69%] Building C object src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o
/home/yoyo/360Downloads/nvtop/src/extract_gpuinfo_msm.c: In function ‘gpuinfo_msm_refresh_dynamic_info’:
/home/yoyo/360Downloads/nvtop/src/extract_gpuinfo_msm.c:504:45: error: ‘MSM_PARAM_MAX_FREQ’ undeclared (first use in this function); did you mean ‘MSM_PARAM_GPU_ID’?
if (gpuinfo_msm_query_param(gpu_info->fd, MSM_PARAM_MAX_FREQ, &clock_val) == 0) {
^~~~~~~~~~~~~~~~~~
MSM_PARAM_GPU_ID
/home/yoyo/360Downloads/nvtop/src/extract_gpuinfo_msm.c:504:45: note: each undeclared identifier is reported only once for each function it appears in
src/CMakeFiles/nvtop.dir/build.make:313: recipe for target 'src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o' failed
make[2]: *** [src/CMakeFiles/nvtop.dir/extract_gpuinfo_msm.c.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'src/CMakeFiles/nvtop.dir/all' failed
make[1]: *** [src/CMakeFiles/nvtop.dir/all] Error 2
Makefile:135: recipe for target 'all' failed
make: *** [all] Error 2
解决方法:根据报错提示,修改 nvtop/src/extract_gpuinfo_msm.c
源码。
if (gpuinfo_msm_query_param(gpu_info->fd, MSM_PARAM_MAX_FREQ, &clock_val) == 0)
修改为
if (gpuinfo_msm_query_param(gpu_info->fd, MSM_PARAM_GPU_ID, &clock_val) == 0)
Q:Could NOT find NVML (missing: NVML_INCLUDE_DIRS)
解决方法:
cmake .. -DNVML_RETRIEVE_HEADER_ONLINE=True