# /usr/bin/bash

file="/path/to/full/vivo.all.log"

# Output formatting
divider===================================
divider=$divider$divider

header="\n %7s %8s %10s %20s\n"
format=" %7d %8.2f %10.4f %20s\n"

width=50

printf "$header" "calls" "sec" "sec/call" "method" ;
printf "%$width.${width}s\n" "$divider"
# Output formatting - END

total=0

for x in {changeSetUpdate,sparqlConstructQuery,sparqlDescribeQuery,sparqlSelectQuery,sparqlAskQuery,serializeAll,serializeGraph,isEquivalentGraph};
  do 
  count=`grep RDFServiceLogger $file | cut -d' ' -f9,10 | grep -c $x;`
  sum=`grep RDFServiceLogger $file | cut -d' ' -f9,10 | grep $x | cut -d' ' -f1 | paste -sd+ - | bc;`
  if [ ! -z $sum ]
    then
      rate=`echo "${sum}/${count}" | bc -l`
      printf "$format" "$count" "$sum" "$rate" "$x";

      math="${total}+${sum}"
      total=`echo $math | bc`
  fi
done

mins=`echo "${total}/60.0" | bc`
hours=`echo "${total}/3600.0" | bc`
echo "Total time: ${total} sec (~${mins} mins, or ~${hours} hrs)"
