基本上我想知道以一种简单易用的方式显示CPU频率等信息的好方法。我不知道一个很好的linux程序,它以我想要的方式显示它。所以我决定写一个剧本。但似乎这并不容易(我的bash知识不是很好)。
所以我希望获得如下输出:
Core 1: 800 MHz, Temp: 30 C
Core 2: 1500 MHz, Temp: ...
...
第一步,就足够了。
我如何以最简单的方式完成这项工作?
到目前为止我所拥有的:
CpuInfoOutput="$(cat /proc/cpuinfo)"
ProcessorCount="$(echo "${CpuInfoOutput}" | grep processor | tail -1 | grep -o ":.*" | cut -f2- -d: | xargs)"
ProcessorCount=$(expr $ProcessorCount + 1)
echo "CPU Count: ${ProcessorCount}"
for i in $(seq $ProcessorCount)
do
$ProcessorId = $(expr $i - 1)
TODO
echo ${CpuInfoOutput} | grep processor |
done
cat / proc / cpuinfo的输出
processor : 0
vendor_id : AuthenticAMD
cpu family : 16
model : 4
model name : AMD Phenom(tm) II X4 965 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 800.000
cache size : 512 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips : 6837.89
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate
processor : 1
vendor_id : AuthenticAMD
cpu family : 16
model : 4
model name : AMD Phenom(tm) II X4 965 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 2200.000
cache size : 512 KB
physical id : 0
siblings : 4
core id : 1
cpu cores : 4
apicid : 1
initial apicid : 1
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips : 6837.89
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate
processor : 2
vendor_id : AuthenticAMD
cpu family : 16
model : 4
model name : AMD Phenom(tm) II X4 965 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 800.000
cache size : 512 KB
physical id : 0
siblings : 4
core id : 2
cpu cores : 4
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips : 6837.89
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate
processor : 3
vendor_id : AuthenticAMD
cpu family : 16
model : 4
model name : AMD Phenom(tm) II X4 965 Processor
stepping : 3
microcode : 0x10000c8
cpu MHz : 2200.000
cache size : 512 KB
physical id : 0
siblings : 4
core id : 3
cpu cores : 4
apicid : 3
initial apicid : 3
fpu : yes
fpu_exception : yes
cpuid level : 5
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni monitor cx16 popcnt lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt hw_pstate vmmcall npt lbrv svm_lock nrip_save
bugs : tlb_mmatch apic_c1e fxsave_leak sysret_ss_attrs
bogomips : 6837.89
TLB size : 1024 4K pages
clflush size : 64
cache_alignment : 64
address sizes : 48 bits physical, 48 bits virtual
power management: ts ttp tm stc 100mhzsteps hwpstate
编辑:我现在的解决方案:
#!
# print processor MHz values
awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor " processor ":\t" $2 " MHz"}' /proc/cpuinfo
# print GPU clock value
GPU_FREQ=$(awk -F":" '$1~"current engine" {print $2}' /sys/kernel/debug/dri/64/radeon_pm_info)
echo -e "Graphics card:\t$GPU_FREQ"
# print temperatures
CPU_TEMP=$(cat /sys/class/hwmon/hwmon1/device/temp2_input)
GFX_TEMP=$(cat /sys/class/graphics/fb0/device/hwmon/hwmon0/temp1_input)
echo
echo -e "CPU temp:\t$(expr $CPU_TEMP / 1000)" °C
echo -e "Graphics temp:\t$(expr $GFX_TEMP / 1000)" °C
示例输出
Processor 1: 800.000 MHz
Processor 2: 800.000 MHz
Processor 3: 800.000 MHz
Processor 4: 800.000 MHz
Graphics card: 675000 kHz
CPU temp: 35 °C
Graphics temp: 46 °C
目前读取GPU频率的方式真的不太好。但是我没有找到任何其他解决方案来使用Linux的调试功能。所以我需要root访问脚本...
答案 0 :(得分:2)
我认为您会找到awk
更好的解决方案:
awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor #" processor " is running at " $2 "mhz"}' /proc/cpuinfo
这里的awk是将/proc/cpuinfo
的输出与冒号:
分开。如果它找到"处理器"在第一个字段中,它将第二个字段$2
的值存储到变量processor
中。如果它稍后在第一个字段中找到单词" cpu MHz`,则从变量和速度打印出处理器。
在我的系统上:
$ awk -F":" '$1~"processor"{processor=$2+1} $1~"cpu MHz"{print "Processor #" processor " is running at " $2 "mhz"}' /proc/cpuinfo
Processor #1 is running at 2794.500mhz
Processor #2 is running at 1354.500mhz
答案 1 :(得分:0)
您可以尝试以下推荐
grep -w 'processor\|MHz' /proc/cpuinfo | sed 'N;s/\n/,/;s/[\t|:]//g'
在我的系统中,它打印为
processor 0,cpu MHz 2593.993
processor 1,cpu MHz 2593.993
processor 2,cpu MHz 2593.993
processor 3,cpu MHz 2593.993