Fixes to ProcessStats() and the associated calls (#820)
Changes to the 'ProcessStats()' function to pull and compute system load values with better accuracy Changes to the 'MonitorMode()' function to display the system load values with better accuracy [call ProcessStats() and load values through the $procStats variable]
This commit is contained in:
parent
edd32a15ec
commit
494c3811b8
@ -268,6 +268,7 @@ MonitorMode() {
|
||||
LastIrqStat=0
|
||||
LastSoftIrqStat=0
|
||||
LastCpuStatCheck=0
|
||||
LastTotal=0
|
||||
|
||||
SleepInterval=${interval:-5}
|
||||
|
||||
@ -307,14 +308,17 @@ MonitorMode() {
|
||||
biglittle)
|
||||
BigFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
LittleFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
echo -e "\n$(date "+%H:%M:%S"): $(printf "%4s" ${BigFreq})/$(printf "%4s" ${LittleFreq})MHz $(printf "%5s" ${LoadAvg}) $(ProcessStats)\c"
|
||||
ProcessStats
|
||||
echo -e "\n$(date "+%H:%M:%S"): $(printf "%4s" ${BigFreq})/$(printf "%4s" ${LittleFreq})MHz $(printf "%5s" ${LoadAvg}) ${procStats}\c"
|
||||
;;
|
||||
normal)
|
||||
CpuFreq=$(awk '{printf ("%0.0f",$1/1000); }' </sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq) 2>/dev/null
|
||||
echo -e "\n$(date "+%H:%M:%S"): $(printf "%4s" ${CpuFreq})MHz $(printf "%5s" ${LoadAvg}) $(ProcessStats)\c"
|
||||
ProcessStats
|
||||
echo -e "\n$(date "+%H:%M:%S"): $(printf "%4s" ${CpuFreq})MHz $(printf "%5s" ${LoadAvg}) ${procStats}\c"
|
||||
;;
|
||||
notavailable)
|
||||
echo -e "\n$(date "+%H:%M:%S"): --- $(printf "%5s" ${LoadAvg}) $(ProcessStats)\c"
|
||||
ProcessStats
|
||||
echo -e "\n$(date "+%H:%M:%S"): --- $(printf "%5s" ${LoadAvg}) ${procStats}\c"
|
||||
;;
|
||||
esac
|
||||
if [ "X${SocTemp}" != "Xn/a" ]; then
|
||||
@ -364,30 +368,37 @@ ProcessStats() {
|
||||
IOWaitLoad=$5
|
||||
IrqCombinedLoad=$6
|
||||
else
|
||||
set $(awk -F" " '/^cpu / {print $2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8}' </proc/stat)
|
||||
UserStat=$1
|
||||
NiceStat=$2
|
||||
SystemStat=$3
|
||||
IdleStat=$4
|
||||
IOWaitStat=$5
|
||||
IrqStat=$6
|
||||
SoftIrqStat=$7
|
||||
|
||||
procStatLine=(`sed -n 's/^cpu\s//p' /proc/stat`)
|
||||
UserStat=${procStatLine[0]}
|
||||
NiceStat=${procStatLine[1]}
|
||||
SystemStat=${procStatLine[2]}
|
||||
IdleStat=${procStatLine[3]}
|
||||
IOWaitStat=${procStatLine[4]}
|
||||
IrqStat=${procStatLine[5]}
|
||||
SoftIrqStat=${procStatLine[6]}
|
||||
|
||||
Total=0
|
||||
for eachstat in ${procStatLine[@]}; do
|
||||
Total=$(( ${Total} + ${eachstat} ))
|
||||
done
|
||||
|
||||
UserDiff=$(( ${UserStat} - ${LastUserStat} ))
|
||||
NiceDiff=$(( ${NiceStat} - ${LastNiceStat} ))
|
||||
SystemDiff=$(( ${SystemStat} - ${LastSystemStat} ))
|
||||
IdleDiff=$(( ${IdleStat} - ${LastIdleStat} ))
|
||||
IOWaitDiff=$(( ${IOWaitStat} - ${LastIOWaitStat} ))
|
||||
IrqDiff=$(( ${IrqStat} - ${LastIrqStat} ))
|
||||
SoftIrqDiff=$(( ${SoftIrqStat} - ${LastSoftIrqStat} ))
|
||||
|
||||
Total=$(( ${UserDiff} + ${NiceDiff} + ${SystemDiff} + ${IdleDiff} + ${IOWaitDiff} + ${IrqDiff} + ${SoftIrqDiff} ))
|
||||
CPULoad=$(( ( ${Total} - ${IdleDiff} ) * 100 / ${Total} ))
|
||||
UserLoad=$(( ${UserDiff} *100 / ${Total} ))
|
||||
SystemLoad=$(( ${SystemDiff} *100 / ${Total} ))
|
||||
NiceLoad=$(( ${NiceDiff} *100 / ${Total} ))
|
||||
IOWaitLoad=$(( ${IOWaitDiff} *100 / ${Total} ))
|
||||
IrqCombinedLoad=$(( ( ${IrqDiff} + ${SoftIrqDiff} ) *100 / ${Total} ))
|
||||
diffIdle=$(( ${IdleStat} - ${LastIdleStat} ))
|
||||
diffTotal=$(( ${Total} - ${LastTotal} ))
|
||||
diffX=$(( ${diffTotal} - ${diffIdle} ))
|
||||
CPULoad=$(( ${diffX}* 100 / ${diffTotal} ))
|
||||
UserLoad=$(( ${UserDiff}* 100 / ${diffTotal} ))
|
||||
SystemLoad=$(( ${SystemDiff}* 100 / ${diffTotal} ))
|
||||
NiceLoad=$(( ${NiceDiff}* 100 / ${diffTotal} ))
|
||||
IOWaitLoad=$(( ${IOWaitDiff}* 100 / ${diffTotal} ))
|
||||
IrqCombined=$(( ${IrqDiff} + ${SoftIrqDiff} ))
|
||||
IrqCombinedLoad=$(( ${IrqCombined}* 100 / ${diffTotal} ))
|
||||
|
||||
LastUserStat=${UserStat}
|
||||
LastNiceStat=${NiceStat}
|
||||
@ -396,9 +407,9 @@ ProcessStats() {
|
||||
LastIOWaitStat=${IOWaitStat}
|
||||
LastIrqStat=${IrqStat}
|
||||
LastSoftIrqStat=${SoftIrqStat}
|
||||
LastTotal=${Total}
|
||||
fi
|
||||
echo -e "$(printf "%3s" ${CPULoad})%$(printf "%4s" ${SystemLoad})%$(printf "%4s" ${UserLoad})%$(printf "%4s" ${NiceLoad})%$(printf "%4s" ${IOWaitLoad})%$(printf "%4s" ${IrqCombinedLoad})%"
|
||||
|
||||
procStats=$(echo -e "$(printf "%3s" ${CPULoad})%$(printf "%4s" ${SystemLoad})%$(printf "%4s" ${UserLoad})%$(printf "%4s" ${NiceLoad})%$(printf "%4s" ${IOWaitLoad})%$(printf "%4s" ${IrqCombinedLoad})%")
|
||||
} # ProcessStats
|
||||
|
||||
MonitorIO() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user