Skip to content

Commit

Permalink
Script for converting \nvidia-smi\ output into CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
mclang committed Aug 29, 2022
1 parent 0e663cf commit 0c535a3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nvidia-smi_logs2csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
# Converts logs created with this `nvidia-smi` command:
# ```
# $ nvidia-smi dmon -s puc -d 1 -o DT | tee -a ~/Documents/Dell-XPS15-logs/nvidia-smi_(date +"%F").log
# ```
# Into proper CSV files WITHOUT unnecessary headers in the middle
#
# NOTE: Square brackets in `tr` command must be escaped!
# TODO: Remove unnecessary semicolon from the beginning of the line
set -e
set -u
shopt -s nullglob

for LOG in *.log; do
CSV="$(basename $LOG .log).csv"
if [[ -e "$CSV" ]]; then
echo "Skipping '$LOG' b/c '$CSV' exists..."
continue
fi
echo "Converting '$LOG' -> '$CSV'"
head -n 2 "$LOG" | tr -s \[#\[:blank:\]\] ';' > "$CSV"
grep -Ev '^#' "$LOG" | tr -s \[#\[:blank:\]\] ';' >> "$CSV"
done

0 comments on commit 0c535a3

Please sign in to comment.