tursa-energy-efficiency/2-racks/size-C0/dmon-to-db.sh
2022-09-07 17:31:28 +01:00

31 lines
657 B
Bash
Executable File

#!/usr/bin/env bash
set -uoe pipefail
if (( $# != 3 )); then
echo "usage: $(basename $0) <nvidia-smi dmon log> <database file> <table>" 1>&2
exit 1
fi
log=$1
db=$2
table=$3
sqlite3 -batch ${db} << EOF
DROP TABLE IF EXISTS ${table};
CREATE TABLE ${table} (
sample INTEGER PRIMARY KEY,
timestamp TEXT,
gpu INTEGER,
power INTEGER,
temp_gpu INTEGER,
temp_mem INTEGER,
activity INTEGER,
memory INTEGER,
clock_mem INTEGER,
clock_gpu INTEGER
);
EOF
tmp=$(mktemp)
awk 'BEGIN{n=0} !/^#/{print n"|"$1" "$2"|"$3"|"$4"|"$5"|"$6"|"$7"|"$8"|"$11"|"$12;n++}' ${log} > ${tmp}
sqlite3 -batch ${db} ".import ${tmp} ${table}"