--- tests/nodeinfodata/display.sh | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 tests/nodeinfodata/display.sh diff --git a/tests/nodeinfodata/display.sh b/tests/nodeinfodata/display.sh new file mode 100755 index 0000000..bc260e2 --- /dev/null +++ b/tests/nodeinfodata/display.sh @@ -0,0 +1,101 @@ +#!/bin/sh + +# display.sh - Display nodeinfo test data in a nice way + +# Copyright (C) 2015 Red Hat, Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library. If not, see +# <http://www.gnu.org/licenses/>. + +die() { + typeset message=$1 + + echo "$message" >&2 + + exit 1 +} + +list_cpus() { + typeset datadir=$1 + + ls -d "$datadir/cpu/cpu"* | while read o; do + o=${o#*cpu/cpu} + case "$o" in + [0-9]*) + echo "$o" + ;; + esac + done | sort -un +} + +is_online() { + typeset datadir=$1 + typeset cpu=$2 + + typeset ret=1 + + if test -e "$datadir/cpu/cpu$cpu/online"; then + ret=$(cat "$datadir/cpu/cpu$cpu/online") + fi + + # Reverse boolean to use it as return code + case "$ret" in + 0) ret=1 ;; + 1) ret=0 ;; + esac + + return $ret; +} + +main() { + typeset datadir=$1 + typeset threads_per_core=$2 + + if ! test "$#" -eq "2"; then + die "Usage: $SELF DATADIR THREADS_PER_CORE" + fi + if ! test -d "$datadir"; then + die "$datadir: No such directory" + fi + + echo "Threads per core: $threads_per_core" + + echo -n 'Present CPUs: ' + if test -e "$datadir/cpu/present"; then + cat "$datadir/cpu/present" + else + echo 'information not available' + fi + + for cpu in $(list_cpus "$datadir"); do + + mod=$(expr "$cpu" % "$threads_per_core") + if test "$mod" = "0"; then + echo + fi + + if is_online "$datadir" "$cpu"; then + printf " %3d*" "$cpu" + else + printf " %3d " "$cpu" + fi + done + echo + + return 0 +} + +SELF=$0 +main "$@" +exit $? -- 2.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list