From f68dc801d4941f2b2776fc40c089ea39ef669b85 Mon Sep 17 00:00:00 2001 From: inxi-svn Date: Mon, 3 Nov 2008 22:37:57 +0000 Subject: [PATCH] Fixed broken cache output, fixed bogomips output, created new cpu data function that takes core count and data number and creates correct value for all cores total --- inxi | 89 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/inxi b/inxi index 793db9f..89253a1 100755 --- a/inxi +++ b/inxi @@ -1,8 +1,8 @@ #!/bin/bash ######################################################################## #### Script Name: inxi -#### version: 0.3.8 -#### Date: November 2 2008 +#### version: 0.3.9 +#### Date: November 3 2008 ######################################################################## #### inxi is a fork of infobash, the original bash sys info script by locsmif #### As time permits functionality and recoding will occur. @@ -111,12 +111,13 @@ VERBOSITY_LEVEL=0 # Supported number of verbosity levels, including 0 VERBOSITY_LEVELS=5 -# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$OIFS" +# Clear nullglob, because it creates unpredictable situations with IFS=$'\n' ARR=($VAR) IFS="$ORIGINAL_IFS" # type constructs. Stuff like [rev a1] is now seen as a glob expansion pattern, and fails, and # therefore results in nothing. Tricky as fuck. shopt -u nullglob -# Backup the current Internal Field Seperator -OIFS="$IFS" +## info on bash built in: $IFS - http://tldp.org/LDP/abs/html/internalvariables.html +# Backup the current Internal Field Separator +ORIGINAL_IFS="$IFS" # These two determine separators in single line output, to force irc clients not to break off sections FL1='-' FL2='' @@ -387,7 +388,7 @@ set_color_scheme() done IFS="," script_colors=(${A_COLOR_SCHEMES[$1]}) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" C1="${!script_colors[0]}" C2="${!script_colors[1]}" CN="${!script_colors[2]}" @@ -710,7 +711,7 @@ set_calculated_variables() added_path="$added_path:$path" fi done - IFS="$OIFS" + IFS="$ORIGINAL_IFS" PATH="${PATH}${added_path}" ##echo "PATH='$PATH'" ##/bin/sh -c 'echo "PATH in subshell=\"$PATH\""' @@ -730,8 +731,8 @@ get_cpu_core_count() { ## Because of the upcoming release of cpus with core counts over 6, a count of cores is given after Deca (10) # count the number of processors given - local cpu_core_count=$(grep -c "cpu cores" /proc/cpuinfo| cut -d':' -f2) - local cpu_alpha_count='' + local cpu_core_count=$(grep -ic "cpu cores" /proc/cpuinfo| cut -d':' -f2) + local cpu_alpha_count='' core_count='' if [[ $cpu_core_count -lt 2 ]]; then cpu_core_count=1 @@ -751,8 +752,8 @@ get_cpu_core_count() 10) cpu_alpha_count='Deca';; *) cpu_alpha_count='Multi';; esac - - core_count="$cpu_alpha_count Core" + ## we'll be splitting the output to number of cores/core count string + core_count="$cpu_core_count:$cpu_alpha_count Core" echo "$core_count" } @@ -805,13 +806,13 @@ get_cpu_data() } ' /proc/cpuinfo)) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" for (( i=0; i < ${#A_CPU_DATA[@]} - 1; i++ )) do IFS="," a_cpu_working=(${A_CPU_DATA[i]}) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" unset A_CPU_DATA[i] a_cpu_working[0]=$( sanitize_characters A_NORMAL_BANS "${a_cpu_working[0]}" ) a_cpu_working[0]=$( sanitize_characters A_CPU_BANS "${a_cpu_working[0]}" ) @@ -853,7 +854,7 @@ get_cpu_data() IFS="," a_cpu_working=(${A_CPU_DATA[0]}) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" # For the short line # CPU_MODEL="${CPU2}${CPU2+ }${a_cpu_working[0]}" # clocked at [${CPU[${#CPU[@]}-1]}]" # old CPU2 CPU_MODEL="${a_cpu_working[0]}" @@ -959,7 +960,7 @@ get_graphics_card_data() IFS=$'\n' A_GFX_CARD_DATA=( $( echo "$lspci_data" | gawk -F': ' '/VGA compatible controller/ { print $NF }' ) ) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" for (( i=0; i < ${#A_GFX_CARD_DATA[@]}; i++ )) do A_GFX_CARD_DATA[i]=$( sanitize_characters A_NORMAL_BANS "${A_GFX_CARD_DATA[i]}" ) @@ -1009,7 +1010,7 @@ get_graphics_glx_data() printf("%s\n%s\n%s\n", join(a,", "), join(b,", "), join(c,", ")) } ' ) ) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" # GLXR=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl renderer/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}') # GLXV=$(glxinfo | gawk -F ': ' 'BEGIN {IGNORECASE=1} /opengl version/ && $2 !~ /mesa/ {seen[$2]++} END {for (i in seen) {printf("%s ",i)}}') @@ -1138,7 +1139,7 @@ get_hard_drive_data() } } ' /proc/scsi/scsi)) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" for (( i=0; i < ${#a_total_hdd[@]}; i++ )) do @@ -1255,7 +1256,7 @@ get_networking_data() } } ') ) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" } ## return uptime string @@ -1265,6 +1266,20 @@ get_uptime() echo $( uptime | gawk '{ a = gensub(/^.*up *([^,]*).*$/,"\\1","g",$0); print a }' ) } +## multiply the core count by the data to be calculated, bmips, cache +# args: $1 - string to handle; $2 - cpu count +calculate_multicore_data() +{ + local string_number=$1 string_data='' + + if [ -n "$( egrep -i '( mb| kb)' <<< $1 )" ];then + string_data=" $( awk '{print $2}' <<< $1 )" # add a space for output + string_number=$( awk '{print $1}' <<< $1 ) + fi + string_number=$( echo $string_number $2 | awk '{total = $1*$2; print total}' ) + echo "$string_number$string_data" +} + #### ------------------------------------------------------------------- #### print and processing of output data #### ------------------------------------------------------------------- @@ -1272,12 +1287,12 @@ get_uptime() print_cpu_data() { local cpu_data='' i='' a_cpu_working='' cpu_clock_speed='' cpu_multi_clock_data='' - local bmip_data='' + local bmip_data='' cpu_cache='' ##print_screen_output "A_CPU_DATA[0]=\"${A_CPU_DATA[0]}\"" IFS="," a_cpu_working=(${A_CPU_DATA[0]}) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" # Strange (and also some expected) behavior encountered. # If print_screen_output() uses $1 as the parameter to output to the screen, # then passing " ${ARR[@]} " @@ -1298,13 +1313,15 @@ print_cpu_data() # # Array CPU always has one element: max clockfreq found. Therefore -gt and not -ge # unset cpu_core_count # fi - cpu_data=$( create_print_line "CPU:" "${C1}${cpu_core_count}${C2} ${a_cpu_working[0]}" ) + cpu_data=$( create_print_line "CPU:" "${C1}${cpu_core_count_string}${C2} ${a_cpu_working[0]}" ) if [ "$VERBOSITY_LEVEL" -ge 3 ];then ## this needs to be updated for multicore I believe, bogomips x core count, or something if [ "$B_EXTRA_DATA" == 'true' ];then - bmip_data=" ${C1}bmips${C2} ${a_cpu_working[4]}" + bmip_data=$( calculate_multicore_data "${a_cpu_working[4]}" "$cpu_core_count" ) + bmip_data=" ${C1}bmips${C2} $bmip_data" fi - cpu_data="$cpu_data${C2} ${C1}cache${C2} ${a_cpu_working[2]} ${C1}flags${C2} ($CPU_FLAGS)$bmip_data${CN}" + cpu_cache=$( calculate_multicore_data "${a_cpu_working[2]}" "$cpu_core_count" ) + cpu_data="$cpu_data${C2} ${C1}cache${C2} $cpu_cache ${C1}flags${C2} ($CPU_FLAGS)$bmip_data${CN}" fi if [ "$VERBOSITY_LEVEL" -ge 5 -a "${#A_CPU_DATA[@]}" -gt 2 ] @@ -1323,7 +1340,7 @@ print_cpu_data() do IFS="," a_cpu_working=(${A_CPU_DATA[i]}) - IFS="$OIFS" + IFS="$ORIGINAL_IFS" cpu_multi_clock_data="$cpu_multi_clock_data ${C1}($(( i + 1 )))${C2} ${a_cpu_working[1]} MHz${CN}" if [ "$i" -gt 10 ];then break @@ -1334,23 +1351,6 @@ print_cpu_data() print_screen_output "$cpu_multi_clock_data" fi fi - - ## leave this here in case they release cpus that can run at different speeds per core -# for (( i=1; i < ${#A_CPU_DATA[@]}-1; i++ )) -# do -# IFS="," -# a_cpu_working=(${A_CPU_DATA[i]}) -# IFS="$OIFS" -# cpu_data=$( create_print_line " " "${C1}($(( i + 1 )))${C2} ${a_cpu_working[0]}" ) -# if [ "$VERBOSITY_LEVEL" -ge 3 ];then -# cpu_data="$cpu_data${C2} ${a_cpu_working[2]} cache${C2} ${C1}flags${C2} ($CPU_FLAGS)${CN}" -# fi -# cpu_data="$cpu_data ${C1}clocked at${C2} ${a_cpu_working[1]} MHz${CN}" -# print_screen_output "$cpu_data" -# if [ "$i" -gt 10 ];then -# break -# fi -# done } print_gfx_data() @@ -1487,7 +1487,7 @@ print_short_data() #C1="${C1},1"; C2="${C2},1"; CN="${CN},1" fi fi - short_data="${C1}CPU${CN}[${C2}${cpu_core_count} ${CPU_MODEL} clocked at ${CPU_CLOCK}${CN}] ${C1}Kernel${CN}[${C2}${current_kernel}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${up_time}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${memory}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${hdd_capacity}($hdd_used)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${processes}${FL1}${CN}]" + short_data="${C1}CPU${CN}[${C2}${cpu_core_count_string} ${CPU_MODEL} clocked at ${CPU_CLOCK}${CN}] ${C1}Kernel${CN}[${C2}${current_kernel}${CN}] ${C1}Up${CN}[${C2}${FL2}${FL1}${up_time}${FL1}${CN}] ${C1}Mem${CN}[${C2}${FL2}${FL1}${memory}${FL1}${CN}] ${C1}HDD${CN}[${C2}${FL2}${FL1}${hdd_capacity}($hdd_used)${FL1}${CN}] ${C1}Procs${CN}[${C2}${FL2}${FL1}${processes}${FL1}${CN}]" if [ "$SHOW_IRC" -gt 0 ];then short_data="${short_data} ${C1}Client${CN}[${C2}${IRC_CLIENT}${IRC_CLIENT_VERSION}${CN}]" @@ -1533,7 +1533,8 @@ print_it_out() ## note: remember that in bash, child functions inherit local variables local current_kernel=$( uname -a | gawk '{print $1,$3,$(NF-1)}' ) local processes="$(( $( ps aux | wc -l ) - 1 ))" - local cpu_core_count="$( get_cpu_core_count )" + local cpu_core_count_string="$( get_cpu_core_count | cut -d ':' -f 2 )" + local cpu_core_count="$( get_cpu_core_count | cut -d ':' -f 1 )" local lspci_data='' ## only for verbose needed local up_time="$( get_uptime )" ## assemble data for output @@ -1592,7 +1593,7 @@ if [ "$KONVI" -eq 1 ];then break fi done - IFS="$OIFS" + IFS="$ORIGINAL_IFS" fi ## leave this for debugging dcop stuff if we get that working # print_screen_output "DCPORT: $DCPORT"