Skip to content

Instantly share code, notes, and snippets.

@hiraksarkar
Created October 27, 2020 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiraksarkar/7e295035698c3907c8f6a2b31a28752b to your computer and use it in GitHub Desktop.
Save hiraksarkar/7e295035698c3907c8f6a2b31a28752b to your computer and use it in GitHub Desktop.
extract_json_from_time
#!/usr/bin/bash
tfile=$1
usr=`rg "(\d+\.\d+)user" $tfile -or '$1'`
sys=`rg "(\d+\.\d+)system" $tfile -or '$1'`
elap=`rg "([\d:\.]+)elapsed" $tfile -or '$1'`
mem=`rg "(\d+)maxresident" $tfile -or '$1'`
tot_elap=`echo "$elap" | sed -E 's/(.*):(.+):(.+)/\1*3600+\2*60+\3/;s/(.+):(.+)/\1*60+\2/' | bc`
echo "{ "
echo "\"user\": $usr,"
echo "\"sys\": $sys,"
echo "\"elapsed\": $tot_elap,"
echo "\"mem\": $mem"
echo "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment