【发布时间】:2019-03-07 11:04:25
【问题描述】:
这个问题是Extracting and Processing GPUTemperature Information Using Regexp的延续
基本上,我想使用传感器命令和脚本(如 gawk 和 bash)提取 GPU 温度信息。
传感器输出示例如下:
amdgpu-pci-0c00
Adapter: PCI adapter
fan1: 1972 RPM
temp1: +50.0°C (crit = +0.0°C, hyst = +0.0°C)
amdgpu-pci-0600
Adapter: PCI adapter
fan1: 1960 RPM
temp1: +47.0°C (crit = +0.0°C, hyst = +0.0°C)
amdgpu-pci-0200
Adapter: PCI adapter
fan1: 1967 RPM
temp1: +52.0°C (crit = +0.0°C, hyst = +0.0°C)
pch_skylake-virtual-0
Adapter: Virtual device
temp1: +33.0°C
amdgpu-pci-0900
Adapter: PCI adapter
fan1: 1893 RPM
temp1: +51.0°C (crit = +0.0°C, hyst = +0.0°C)
amdgpu-pci-0300
Adapter: PCI adapter
fan1: 1992 RPM
temp1: +53.0°C (crit = +0.0°C, hyst = +0.0°C)
coretemp-isa-0000
Adapter: ISA adapter
Package id 0: +24.0°C (high = +80.0°C, crit = +100.0°C)
Core 0: +23.0°C (high = +80.0°C, crit = +100.0°C)
Core 1: +21.0°C (high = +80.0°C, crit = +100.0°C)
我想根据总线 ID 的升序打印每个 GPU 的标签和温度。例如,根据前面的输出,第一个 GPU,GPU0,将是带有标签 amdgpu-pci-0200 的那个,GPU1 将是 amdgpu-pci-0300,直到最后一个 GPU4 是 amdgpu-pci-0c00。这不包括 coretemp-isa-0000,因为它不是 GPU。不管总线ID是连续的还是跳过的,我都想按升序标记它。
以下 bash 代码将在不正确排序的情况下提取所有 GPU 临时文件。
#!/bin/bash
while [ 1 ]
do
temp=( $( sensors | IFS=$'\n' gawk 'BEGIN{ RS="\n\n"} { if($0 ~ /amdgpu/) print $0 }' | gawk 'BEGIN{ FS="[+.]" } { if($1 ~ /temp1:/) print $2 }' ))
let j=0
for i in "${temp[@]}"
do
echo -en "GPU $j temp is $i \r "
j=$(($j +1))
sleep 1
done
done
我该如何解决?
问候
【问题讨论】:
-
假设
Example of sensors output will be like this:是您寻求帮助的工具的输入,请提供您尝试编写的脚本的准确预期输出。解释我们如何知道coretemp-isa-0000不是GPU,为什么在你的shell 脚本中有一个sleep 1,以及为什么它被放置在sensors输出的数组内容的循环中而不是周围的无限循环中。 -
GPU temp 是带有 GPU 文本的那个,而 coretemp-isa-0000 没有它。显然,您在编辑后的答案中发现了这一点。脚本无限运行,不断告诉温度,这就是为什么操作员需要 1 秒延迟才能读取它。