Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/next/external/packages/bsp/common/usr/bin/memtester.sh
Views: 3963
#!/bin/sh12# Memory Tester Scripts3# by KaKa4# version = date5VERSION="Fri Oct 19 11:56:57 CST 2007"6# trap for irruptions7#MEMTESTER=${PWD}/memtester8MEMTESTER=/usr/sbin/memtester9PPIDKILL=$$10SIDKILL=$$11trap "pkill -9 -P ${PPIDKILL};kill -9 $$" INT12trap "pkill -9 -P ${PPIDKILL};kill -9 $$" KILL13cat <<-EOF_vpps >&214Version: ${VERSION}15PID: $$16PPIDKILL: ${PPIDKILL}17SIDKILL: ${PPIDKILL}18EOF_vpps19CORE_NUM=$(grep -i ^processor /proc/cpuinfo|wc -l)20MEMTESTERCOPY=${CORE_NUM}21MEM_TOTAL_K=$(awk '/^MemTotal/{print $2}' /proc/meminfo)22MEM_RESERVE_PERCENTAGE=$((1000*50/1024))23MEM_RESERVED=$((MEM_TOTAL_K/1024*MEM_RESERVE_PERCENTAGE/1000))24MEM_TOTAL_TOBETESTED=$((MEM_TOTAL_K/1024-MEM_RESERVED))25MEM_PER_COPY=$((MEM_TOTAL_TOBETESTED/MEMTESTERCOPY))26RUN_DURATION_TIME=027RUN_LOOPS=-128RUN_DURATION_TIME_FLAG=029RUN_LOOPS_FLAG=030DDPERCOPY_TIME=6s31LOGDIR=/root/memtester-log-${$}32mkdir -p ${LOGDIR}3334show_help () {35cat <<HELPEOF >&236Version: ${VERSION}37Usage: $(basename ${0})38-r Directory: the root location of memtester binary file39-c NUMBER: the copies of memtester should be run40-m NUMBER: how many memory should be tested totally (in MB)41-t TIME: duration mode, how long will the tests go42-l NUMBER: loops mode,how many loops will each memtester should go43The option -t and -l are exclusive, which means tests could work44only with 1. duration mode or 2. loops mode45RUN 4 copies memtester with in 24 hours, to test total 4000 MB memory:46$(basename ${0}) -t 24h -c 4 -m 400047RUN 2 copies memtester with in 1 hours, to test total 4000 MB memory:48$(basename ${0}) -t 1h -c 4 -m 400049RUN 4 copies memtester with in 2 loops, to test total 3600 MB memory:50$(basename ${0}) -l 2 -c 4 -m 360051-V/-h/-H: show this info.52HELPEOF53exit 054}5556while getopts :c:m:t:l:r:p:hHVvx OPTION57do58case ${OPTION} in59c)60#echo "-c ${OPTARG}"61MEMTESTERCOPY=${OPTARG}62;;63m)64#echo "-m ${OPTARG} MB"65MEM_TOTAL_TOBETESTED=${OPTARG}66MEM_RESERVED=$((MEM_TOTAL_K/1024-MEM_TOTAL_TOBETESTED))67;;68t)69#echo "-t ${OPTARG}"70[ 0 -ne ${RUN_LOOPS_FLAG} ] && echo "-t and -l are exclusive." && exit 22271RUN_DURATION_TIME=${OPTARG}72RUN_DURATION_TIME_FLAG=173;;74l)75#echo "-l ${OPTARG}"76[ 0 -ne ${RUN_DURATION_TIME_FLAG} ] && echo && echo "-t and -l are exclusive." && show_help && echo && exit 22377RUN_LOOPS=${OPTARG};78RUN_LOOPS_FLAG=179;;80d)81#echo "-r ${OPTARG}"82MEMTESTER=${OPTARG}/memtester83;;84p)85#echo "-p ${OPTARG}"86MEMTESTER=${OPTARG}87;;88V|h|H)89show_help90;;91v)92set -v93;;94x)95set -x96;;97?)98echo "Error...";99echo "?Unknown args..."100exit 224101;;102*)103#echo "*Unknown args..."104esac105done106#exit107[ 0 -eq ${RUN_DURATION_TIME_FLAG} ] && [ 0 -eq ${RUN_LOOPS_FLAG} ] &&108echo && echo "Please specified which mode should we run... -t or -l" &&109show_help && echo && exit 225110MEM_PER_COPY=$((MEM_TOTAL_TOBETESTED/MEMTESTERCOPY))111echo "Mem total: " $((MEM_TOTAL_K/1024)) MB112echo "Core total: "${CORE_NUM}113echo "Memtester copys: " ${MEMTESTERCOPY}114echo "Mem per copy: "${MEM_PER_COPY}115echo "Mem total to used: "${MEM_TOTAL_TOBETESTED} MB116if [ ${MEM_RESERVED} -lt 1 ]; then117echo "Mem reserved: -- No more memory reserved..."118else119echo "Mem reserved: "${MEM_RESERVED} MB120fi121#exit122# GOGOGO123if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]; then124echo "Run within a duration: ${RUN_DURATION_TIME}"125elif [ 0 -ne ${RUN_LOOPS_FLAG} ]; then126echo "Run within a loop: ${RUN_LOOPS}"127fi128129echo "Working directory: " $PWD130echo "Memtester: " ${MEMTESTER}131echo "LOGs directory: " $LOGDIR132echo133echo -n "Jobs started at date: "134date #+%Y/%m/%d\ %H:%M135echo136#exit137########################138# Run testing within a duration time.139if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]; then140# prepareing the sleeping killers141sleep ${RUN_DURATION_TIME}142echo -n "End of testing(TIMEOUT)... "143echo "KILL CHILD" && kill -9 $(pgrep -P ${PPIDKILL} memtester) && echo144"Childen processes - KILLED."145# attention to how the memtesters are forked...146echo "KILL PARENT" && kill $$ && echo "KILLED." &147echo "Finished the memtester"148echo -n "Jobs finished at date: "149date #+%Y/%m/%d\ %H:%M150fi &151echo -n "Waiting (PID: $$) for ${MEMTESTERCOPY}152memtesters(${MEM_PER_COPY}MB for each). "153if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]; then154echo -n "For time: ${RUN_DURATION_TIME} "155fi156157if [ 0 -ne ${RUN_LOOPS_FLAG} ]; then158echo -n "For loops: ${RUN_LOOPS} "159fi160echo "..."161while true162do163MEMTESTER_NUM=0164echo -n "{"165while [ ${MEMTESTER_NUM} -lt ${MEMTESTERCOPY} ]166do167echo -n " ${MEMTESTER_NUM} "168if [ 0 -ne ${RUN_DURATION_TIME_FLAG} ]; then169RUN_LOOPS=0170fi171${MEMTESTER} ${MEM_PER_COPY} ${RUN_LOOPS} 2>&1 >> ${LOGDIR}/${MEMTESTER_NUM}.log &172# set loops = 0 to make memtester run loop infinitely...173# .pogo version will run only one loop by default174sleep ${DDPERCOPY_TIME}175MEMTESTER_NUM=$(expr $MEMTESTER_NUM + 1)176done177echo -n "}"178wait179[ 0 -ne ${RUN_LOOPS_FLAG} ] && break180# memtesters' loops...181done182########################183echo184echo -n "End of testing(Excution ended)... "185pkill -9 -P ${PPIDKILL}186kill $$187echo "Finished the memtester"188echo -n "Jobs finished at date: "189date #+%Y/%m/%d\ %H:%M190191192