List:Commits« Previous MessageNext Message »
From:John H. Embretsen Date:May 5 2009 3:08pm
Subject:bzr commit into mysql-falcon branch (john.embretsen:386)
View as plain text  
#At bzr+ssh://bk-internal.mysql.com/bzrroot/mysql-falcon/ based on revid:john.embretsen@stripped

  386 John H. Embretsen	2009-05-05
      Falcon QA scripts: Added script to print machine info (OS, CPU, Memory etc).
      Established "common" directory for scripts/tools of generic nature.

    added:
      common/
      common/README
      common/machine-info.bash
=== added directory 'common'
=== added file 'common/README'
--- a/common/README	1970-01-01 00:00:00 +0000
+++ b/common/README	2009-05-05 15:08:57 +0000
@@ -0,0 +1,6 @@
+This directory is where to put scripts, binaries and tools that may
+be used directly by several different test suites etc. as part of 
+this repository.
+
+This way we avoid maintaining several copies/versions of the scripts/tools.
+

=== added file 'common/machine-info.bash'
--- a/common/machine-info.bash	1970-01-01 00:00:00 +0000
+++ b/common/machine-info.bash	2009-05-05 15:08:57 +0000
@@ -0,0 +1,200 @@
+#!/bin/bash
+
+###################################################################
+#
+# Displays information about the host on which this script is run.
+# CPU info, OS info, Memory, etc.
+#
+###################################################################
+
+PLATFORM=$(uname)
+
+if [ "${PLATFORM}" == "SunOS" ]; then
+    AWK='gawk'
+else
+    AWK='awk'
+fi
+
+# Common commands for all supported platforms:
+
+HOSTNAME=$(uname -n)
+HOSTNAME_FULL=$(cat /etc/hosts | grep ${HOSTNAME} | $AWK -F ' ' '{ print $3 }')
+# If unable to get full hostname this way, just use the simple version
+if [ "x${HOSTNAME_FULL}" == "x" ] || echo ${HOSTNAME_FULL} | grep "localhost" > /dev/null; then
+    HOSTNAME_FULL=${HOSTNAME}
+fi
+
+KERNEL=$(uname -srv)
+MODEL=$(uname -m)
+
+# Platform-specific commands:
+case $PLATFORM in
+
+    Linux)
+
+        ####################################
+        # Linux
+        
+        # Date / time
+        TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S %Z")
+        
+        # OS info
+        if [ -f "/etc/redhat-release" ]; then
+            # Red Hat, Fedora
+            OS_RELEASE=$(cat /etc/redhat-release)
+        elif [ -f "/etc/lsb-release" ] && cat /etc/lsb-release | grep "DISTRIB_DESCRIPTION" > /dev/null; then
+            # Ubuntu / Debian. OS version in lsb-release: "DISTRIB_DESCRIPTION=..."
+            source /etc/lsb-release
+            OS_RELEASE=${DISTRIB_DESCRIPTION}
+        elif [ -f "/etc/SuSE-release" ]; then
+            # SuSE
+            OS_RELEASE=$(cat /etc/SuSE-release | head -1)
+        elif [ -f "/etc/issue" ]; then
+            # Older Debian, SuSE or other linux.
+            OS_RELEASE=$(cat /etc/issue | grep -m1 [a-z])
+        else
+            # Don't know how to read OS release info for this OS
+            OS_RELEASE="Unknown"
+        fi
+        
+        
+        # CPU info
+        CPU_BRAND=$(cat  /proc/cpuinfo | grep -m1 "model name" | awk -F: '{ print $2 }')
+        # trim leading whitespace
+        CPU_BRAND=${CPU_BRAND## }  # trims leading spaces
+        
+        # Number of CPU cores and sockets/chips may be hard to get accurately.
+        # This is especially true for number of cores per chip. Hence, we
+        # base this on the other two numbers (# sockets, # cores) instead of
+        # doing the commented out part (below)
+        
+        # Some machines report non-sequential physical ids in random order. 
+        # So we must count distinct ids.
+        for id in $(cat /proc/cpuinfo | grep "physical id" | awk -F : '{ print $2 }')
+        do
+            # trim leading spaces
+            id=${id## }
+            # insert id into array at index $id in order to remove duplicates.
+            idarray[$id]=$id
+        done
+        NO_CPU_PHYSICAL=${#idarray[@]}  # element count
+        
+        # Doing division instead of this:
+        #NO_VCPU_PER_PHYSICAL=$(cat /proc/cpuinfo | grep -m1 "cpu cores" | awk -F : '{ print $2 }')
+        # Not all machines display # of cpu cores directly.
+        # Try using "siblings" instead if there is no core info..
+        #if [ -z "${NO_VCPU_PER_PHYSICAL}" ]; then
+        #    NO_VCPU_PER_PHYSICAL=$(cat /proc/cpuinfo | grep -m1 "siblings" | awk -F : '{ print $2 }')
+        #    NO_VCPU_PER_PHYSICAL=${NO_VCPU_PER_PHYSICAL## }  # trims leading spaces
+        #    NO_VCPU_PER_PHYSICAL="at least ${NO_VCPU_PER_PHYSICAL}"
+        #else
+        #    NO_VCPU_PER_PHYSICAL=${NO_VCPU_PER_PHYSICAL## }  # trims leading spaces
+        #fi
+        
+        NO_CPU_VIRTUAL=$(cat /proc/cpuinfo | grep processor | wc -l)
+        # ok, just do the math for vcpu (cores) per physical cpu (sockets)
+        let NO_VCPU_PER_PHYSICAL=${NO_CPU_VIRTUAL}/${NO_CPU_PHYSICAL}
+        VCPU_PER_PHYSICAL="Each physical processor seems to have ${NO_VCPU_PER_PHYSICAL} virtual processors"
+        CPU_FREQ=$(cat /proc/cpuinfo | grep -m1 "cpu MHz" | awk -F : '{ print $2 }')
+        CPU_FREQ=${CPU_FREQ## }  # trims leading spaces
+        CACHE=$(cat /proc/cpuinfo | grep -m1 "cache size" | awk -F : '{ print $2 }')
+        CACHE=${CACHE## }  # trims leading spaces
+        INSTR_SET_KERNEL=""
+        
+        
+        # Memory.   TODO: Refactor common code into functions.
+        MEM_TOTAL=$(cat /proc/meminfo | grep "MemTotal" | awk -F: '{ print $2 }')
+        MEM_TOTAL_MB=""
+        MEM_TOTAL_RAW_NUMBER=$(echo ${MEM_TOTAL} | awk -F' ' '{ print $1 }')
+        MEM_TOTAL_UNIT=$(echo ${MEM_TOTAL} | awk -F' ' '{ print $2 }')
+        if [ "${MEM_TOTAL_UNIT}" == "kB" ]; then
+            let m=$(echo "${MEM_TOTAL_RAW_NUMBER}/1024")
+            MEM_TOTAL_MB="($m MB)"
+        fi
+        MEM_FREE=$(cat /proc/meminfo | grep "MemFree" | awk -F: '{ print $2 }')
+        MEM_FREE="${MEM_FREE## }"  # trim leading spaces?
+        MEM_FREE_MB=""
+        MEM_FREE_RAW_NUMBER=$(echo ${MEM_FREE} | awk -F' ' '{ print $1 }')
+        MEM_FREE_UNIT=$(echo ${MEM_FREE} | awk -F' ' '{ print $2 }')
+        if [ "${MEM_FREE_UNIT}" == "kB" ]; then
+            let m=$(echo "${MEM_FREE_RAW_NUMBER}/1024")
+            MEM_FREE_MB="($m MB)"
+        fi
+        ;;
+        
+    SunOS)
+    
+        ####################################
+        # Solaris
+        
+        # TODO: Optimization: Run psrinfo etc. only once, store result in tmp file and read that file.
+
+        # Date / time
+        TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
+        TIMESTAMP="${TIMESTAMP} (${TZ})"
+        
+        # OS
+        # Using sed to remove leading whitespace.
+        OS_RELEASE=$(cat /etc/release | head -1 | sed -e "s/^ *//") # Solaris
+        
+        # CPU info
+        CPU_BRAND=$(psrinfo -pv 1 | tail -1)
+        CPU_BRAND=${CPU_BRAND## }  # trims leading spaces
+        CPU_BRAND=${CPU_BRAND##[[:space:]]}  # trims single leading tab, see bash cookbook (2007) p. 270 (available on books.google.com)
+        NO_CPU_PHYSICAL=$(psrinfo -p)
+        VCPU_PER_PHYSICAL=$(psrinfo -pv | egrep "The physical processor has [0-9]+ virtual processors" | head -1 | sed -e "s/^The/Each/" | sed -e "s/processors.*/processors/")
+        NO_CPU_VIRTUAL=$(psrinfo | wc -l | sed -e "s/^ *//")
+        CPU_FREQ=$(psrinfo -v | grep "processor operates at " | head -1 | gawk '{ print $6 }')
+        CPU_FREQ=${CPU_FREQ## }  # trims leading spaces
+        CACHE="unknown"
+        INSTR_SET_KERNEL=$(isainfo -kv)
+        INSTR_SET_KERNEL="(${INSTR_SET_KERNEL})"
+        
+        # Memory.   TODO: Refactor common code into functions.
+        MEM_TOTAL=$(prtconf | grep "Memory size" | gawk -F: '{ print $2 }')
+        MEM_TOTAL=${MEM_TOTAL## }  # trims leading spaces
+        MEM_TOTAL_MB=""
+        MEM_TOTAL_RAW_NUMBER=$(echo ${MEM_TOTAL} | gawk -F' ' '{ print $1 }')
+        MEM_TOTAL_UNIT=$(echo ${MEM_TOTAL} | gawk -F' ' '{ print $2 }')
+        if [ "${MEM_TOTAL_UNIT}" == "kB" ]; then
+            let m=$(echo "${MEM_TOTAL_RAW_NUMBER}/1024")
+            MEM_TOTAL_MB="($m MB)"
+        fi
+        MEM_FREE=$(vmstat 1 2 | tail -1 | gawk -F' ' '{ print $5 }')
+        #MEM_FREE=${MEM_FREE## }  # trim leading spaces
+        MEM_FREE_MB=""
+        MEM_FREE_RAW_NUMBER=$(echo ${MEM_FREE} | gawk -F' ' '{ print $1 }')
+        # assuming that MEM_FREE unit is Kbytes
+        let m=$(echo "${MEM_FREE_RAW_NUMBER}/1024")
+        MEM_FREE_MB="($m MB)"
+
+
+        # Todo: ZFS version: modinfo | grep zfs....?
+        #                or: zfs upgrade
+        ;;
+    *)
+        echo '[ERROR]: Platform not supported yet. Exiting.'
+        exit 1
+        ;;
+esac
+
+#####################################
+# PRINT INFO
+
+echo
+echo "Machine info for ${HOSTNAME} at ${TIMESTAMP}:"
+echo "-----------------------------------------------------------------------------"
+echo "Host name:    ${HOSTNAME_FULL}"
+echo "OS:           ${OS_RELEASE}"
+echo "Kernel:       ${KERNEL} ${INSTR_SET_KERNEL}"
+echo "CPU:          ${CPU_BRAND}"
+echo "  ${VCPU_PER_PHYSICAL} (all assumed equal)"
+echo "  Physical CPUs (chips, sockets): ${NO_CPU_PHYSICAL}"
+echo "  Total vCPUs (cores, threads):   ${NO_CPU_VIRTUAL}"
+echo "  Clock speed:                    ${CPU_FREQ} MHz"
+echo "  Cache:                          ${CACHE}"
+echo "  Model:                          ${MODEL}"
+echo "Total Memory: ${MEM_TOTAL} ${MEM_TOTAL_MB}"
+echo "Free Memory:  ${MEM_FREE} ${MEM_FREE_MB}"
+echo ""
+


Attachment: [text/bzr-bundle] bzr/john.embretsen@sun.com-20090505150857-37g9u9ksw7vhhmk8.bundle
Thread
bzr commit into mysql-falcon branch (john.embretsen:386) John H. Embretsen5 May