paper-lowrate-iot/g5k/logs/analysis.org
2019-05-20 16:48:17 +02:00

4.9 KiB

Logs Analysis

R Scripts

Generate all plots script

  <<RUtils>>
  data=loadData("./third-try/data.csv")

  data=data%>%filter(simKey=="nbSensors") %>% filter(nbSensors==200)
  ggplot(data,aes(x=time,y=energy,color=nbSensors))+geom_point(position="jitter")+xlab(getLabel("time"))+expand_limits(y=0)#+geom_hline(aes(group=nbSensors,color=nbSensors,yintercept=mean(energy)))
  ggsave("./third-try/plot.png",dpi=180)

/loic/paper-lowrate-iot/media/commit/4045a41e029ed11dde5763455095bd33c7746a72/g5k/logs/third-try/plot.png

R Utils

RUtils is intended to load logs (data.csv) and providing simple plot function for them.

  library("tidyverse")

  # Fell free to update the following
  labels=c(time="Time (s)")

  loadData=function(path){
    data=read_csv(path)
  }

  # Get label according to varName
  getLabel=function(varName){
    if(is.na(labels[varName])){
      return(varName)
    }
    return(labels[varName])
  }

Plots -> PDF

Merge all plots in plots/ folder into a pdf file.

  orgFile="plots/plots.org"
  <<singleRun>> # To get all default arguments

  # Write helper function
  function write {
      echo "$1" >> $orgFile
  }

  echo "#+TITLE: Analysis" > $orgFile
  write "#+LATEX_HEADER: \usepackage{fullpage}"
  write "#+OPTIONS: toc:nil"
  # Default arguments
  write '\begin{center}'
  write '\begin{tabular}{lr}'
  write 'Parameters & Values\\'
  write '\hline'
  write "sensorsPktSize & ${sensorsPktSize} bytes\\\\"
  write "sensorsSendInterval & ${sensorsSendInterval}s\\\\"
  write "sensorsNumber & ${sensorsNumber}\\\\"
  write "nbHop & ${nbHop}\\\\"
  write "linksBandwidth & ${linksBandwidth}Mbps\\\\"
  write "linksLatency & ${linksLatency}ms\\\\"
  write '\end{tabular}'
  write '\newline'
  write '\end{center}'

  for plot in $(find plots/ -type f -name "*.png")
  do
      write "\includegraphics[width=0.5\linewidth]{$(basename ${plot})}"
  done

  # Export to pdf
  emacs $orgFile --batch -f org-latex-export-to-pdf --kill

CSVs -> CSV

Merge all energy file into one (and add additional fields).

  #!/bin/bash

  whichLog="third-try"


  logFile="$(dirname $(readlink -f $0))"/$whichLog/simLogs.txt
  dataFile=$(dirname "$logFile")/data.csv


  getValue () {
      line=$(echo "$1" | grep "Simulation para"|sed "s/Simulation parameters: //g")
      key=$2
      echo "$line"|awk 'BEGIN{RS=" ";FS=":"}"'$key'"==$1{gsub("\n","",$0);print $2}'
  }

  ##### Add extract info to energy #####
  IFS=$'\n'
  for cmd in $(cat $logFile|grep "Simulation parameters")
  do
      nodeName=$(getValue $cmd serverNodeName)
      from=$(getValue $cmd simStart)
      to=$(getValue $cmd simEnd)
      vmSize=$(getValue $cmd vmSize)
      nbSensors=$(getValue $cmd nbSensors)
      simKey=$(getValue $cmd simKey)
      csvFile="$whichLog/${simKey}_${vmSize}VMSIZE_${nbSensors}NBSENSORS_${from}${to}.csv"
      tmpFile=${csvFile}_tmp
      echo ts,energy,simKey,vmSize,nbSensors,time > $tmpFile
      minEnergy=$(tail -n+2 $csvFile|awk -F"," 'BEGIN{min=0}$1<min||min==0{min=$1}END{print(min)}') # To compute ts field
      tail -n+2 ${csvFile} | awk -F"," '{print $0",'$simKey','$vmSize','$nbSensors',"$1-'$minEnergy'}' >> $tmpFile
  done


  ##### File dataFile #####
  echo ts,energy,simKey,vmSize,nbSensors,time > $dataFile
  for tmpFile in $(find ${whichLog}/*_tmp -type f)
  do
      tail -n+2 $tmpFile >> $dataFile
      rm $tmpFile # Pay attention to this line :D
  done

Custom Plots

  <<RUtils>>

  data%>%filter(simKey=="SENDINTERVAL",sensorsNumber==20) %>% ggplot(aes(x=sensorsSendInterval,y=networkEnergy))+xlab(getLabel("sensorsSendInterval"))+ylab(getLabel("networkEnergy"))+
  geom_line()+labs(title="For 20 sensors")
  ggsave("plots/sensorsSendInterval-net.png",dpi=80)

/loic/paper-lowrate-iot/media/commit/4045a41e029ed11dde5763455095bd33c7746a72/g5k/logs/plots/sensorsSendInterval-net.png

  <<RUtils>>
  data%>%filter(simKey=="SENDINTERVAL",sensorsNumber==20) %>% ggplot(aes(x=sensorsSendInterval,y=sensorsEnergy))+xlab(getLabel("sensorsSendInterval"))+ylab(getLabel("sensorsEnergy"))+
  geom_line() +     geom_line()+labs(title="For 20 sensors")
  ggsave("plots/sensorsSendInterval-wifi.png",dpi=80)

/loic/paper-lowrate-iot/media/commit/4045a41e029ed11dde5763455095bd33c7746a72/g5k/logs/plots/sensorsSendInterval-wifi.png

/loic/paper-lowrate-iot/media/commit/4045a41e029ed11dde5763455095bd33c7746a72/g5k/logs/plots/sensorsSendInterval.png