获取处理器频率
Get processor frequencies
基本上我想知道一种以一种简单易行的方式显示 CPU 频率等信息的好方法。我不知道 linux 的好程序能以我想要的方式显示它。所以我决定写一个脚本。但这似乎也不是那么容易(我的bash知识不是很好)。
所以我想得到这样的输出:
Core 1: 800 MHz, Temp: 30 C
Core 2: 1500 MHz, Temp: ...
...
对于第一步,MHz 就足够了。
如何以最简单的方式完成这项工作?
我目前拥有的:
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
猫的输出/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":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor " processor ":\t" " MHz"}' /proc/cpuinfo
# print GPU clock value
GPU_FREQ=$(awk -F":" '~"current engine" {print }' /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 中的调试工具。所以我需要脚本的根访问权限...
我认为您会找到 awk
更好的解决方案:
awk -F":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor #" processor " is running at " "mhz"}' /proc/cpuinfo
awk 在这里用冒号 :
分割来自 /proc/cpuinfo
的输出。如果它在第一个字段中找到单词 "processor",它会将第二个字段的值 </code> 存储到变量 <code>processor
中。如果它稍后在第一个字段中找到单词“cpu MHz”,则会从变量中打印出处理器以及速度。
在我的系统上:
$ awk -F":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor #" processor " is running at " "mhz"}' /proc/cpuinfo
Processor #1 is running at 2794.500mhz
Processor #2 is running at 1354.500mhz
你可以试试下面的推荐
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
基本上我想知道一种以一种简单易行的方式显示 CPU 频率等信息的好方法。我不知道 linux 的好程序能以我想要的方式显示它。所以我决定写一个脚本。但这似乎也不是那么容易(我的bash知识不是很好)。
所以我想得到这样的输出:
Core 1: 800 MHz, Temp: 30 C
Core 2: 1500 MHz, Temp: ...
...
对于第一步,MHz 就足够了。
如何以最简单的方式完成这项工作?
我目前拥有的:
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
猫的输出/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":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor " processor ":\t" " MHz"}' /proc/cpuinfo
# print GPU clock value
GPU_FREQ=$(awk -F":" '~"current engine" {print }' /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 中的调试工具。所以我需要脚本的根访问权限...
我认为您会找到 awk
更好的解决方案:
awk -F":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor #" processor " is running at " "mhz"}' /proc/cpuinfo
awk 在这里用冒号 :
分割来自 /proc/cpuinfo
的输出。如果它在第一个字段中找到单词 "processor",它会将第二个字段的值 </code> 存储到变量 <code>processor
中。如果它稍后在第一个字段中找到单词“cpu MHz”,则会从变量中打印出处理器以及速度。
在我的系统上:
$ awk -F":" '~"processor"{processor=+1} ~"cpu MHz"{print "Processor #" processor " is running at " "mhz"}' /proc/cpuinfo
Processor #1 is running at 2794.500mhz
Processor #2 is running at 1354.500mhz
你可以试试下面的推荐
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