-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlogphicards.sh
executable file
·60 lines (48 loc) · 1.57 KB
/
logphicards.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
# A script to log the cpu watt-usage and temp of xeon-phi cards
# launch on Thinkmate when starting assembly job
# scriptname: logphicards.sh
#
# inspired by http://www.unix.com/shell-programming-and-scripting/
# 223177-shell-script-logging-cpu-memory-usage-linux-process.html
#
# Stephane Plaisance VIB-BITS march-14-2016 v1.0
# fixed small bugs (v1.1; 2016-03-15)
#
# visit our Git: https://github.com/Nucleomics-VIB
usage='# Usage: logphicards.sh
# -t <log-frequency in sec (default 60sec)>'
while getopts "t:h" opt; do
case $opt in
t) timeint=${OPTARG} ;;
h) echo "${usage}" >&2; exit 0 ;;
esac
done
maxmic=5
# repeat loop every x sec
FREQ=${timeint:-60}
# test if time is a valid number
re='^[0-9]+$'
if ! [[ ${FREQ} =~ $re ]] ; then
echo "not an integer number of seconds"
echo "${usage}"
exit 1
fi
# log file name and header
LOG_FILE=Xeon_usage_"$(date +%s)".log
echo -e "logtime\tmic\tcpu_user\tcpuT\tmemT\ttotW" > $LOG_FILE
echo "# logging to $LOG_FILE every $FREQ sec"
echo "# press <Ctrl>-C to stop logging"
# infinite loop will run until ctrl-C is hit
while :; do
for mic in $(eval echo "mic{0..${maxmic}}"); do
t=$(date +%s)
(echo -ne "${t}\t${mic}\t"; micsmc -c ${mic} -t ${mic} -f ${mic} | \
egrep "Device Utilization:|Cpu Temp:|Memory Temp:|Total Power:" | \
awk '{if (FNR==1) {match($0, /([0-9\.]+)/, arr); if(arr[1] != "") print arr[1]}
else {print substr($0, 31, length($0)-29)}}' | \
cut -d "%" -f 1 | cut -d " " -f 1 | transpose -t) >> ${LOG_FILE}
done
sleep ${FREQ}
done
# when the app closes, no additional line will be added to the log file