code: def getUsageStats(filename):
      """
      Function that takes an input file generated from
      statscript.sh with usage stats sampled over certain
      timestamps, and calculates peak and average values
      of different parameters such as compute and memory.
      It uses tabulate library to form the table to display
      the final stats
      """
  
      fp = open(filename, "r+")
      oline = fp.readline()
  
      acpu = 0
      amem = 0
      amemlim = 0
      aneti = 0
      aneto = 0
      ablocki = 0
      ablocko = 0
      count = 0
      mmem = 0
      mcpu = 0
      starttime = 0
      endtime = 0
      name = ""
  
      zero_error = 0
      basic_error = 0
  
      line = fp.readline()
      while line:
          # print (line)
          try:
              line1 = line[:-1].split(" ")
              if line1[2] == "--":
                  break
              cpu = float(line1[2][:-1])
              mem = human2bytes(line1[4])
              memlim = human2bytes(line1[6])
              neti = human2bytes(line1[8])
              neto = human2bytes(line1[10])
              blocki = human2bytes(line1[12])
              blocko = human2bytes(line1[14])
              name = line1[0]
              if starttime == 0:
                  starttime = int(line1[16])
              endtime = int(line1[16])
  
              if cpu == 0.0 and mem == 0:
                  zero_error = 1
                  break
              count += 1
              acpu = acpu + ((cpu - acpu) / count)
              amem = amem + ((mem - amem) / count)
              amemlim = amemlim + ((memlim - amemlim) / count)
              mcpu = max(mcpu, cpu)
              mmem = max(mmem, mem)
              aneti = aneti + ((neti - aneti) / count)
              aneto = aneto + ((neto - aneto) / count)
              ablocki = ablocki + ((blocki - ablocki) / count)
              ablocko = ablocko + ((blocko - ablocko) / count)
  
          except:
              basic_error = 1
  
          line = fp.readline()
  
      if zero_error:
          fp.write(
              "\nEncountered time stamps with 0 CPU and 0 Mem, process has probabaly finished; Hence discarding the timestamp."
          )
      # if basic_error:
      # fp.write("\nAn error occurred when processing this file")
  
      if count == 0:
          fp.write(
              "Profiler could not sample usage stats for the experiment because the sample time is too long compared to the runtime of the experiment or the experiment is too fast and finishes before sampling could start."
          )
  
      fp.write("\nUsage Stats: ")
      print("\nUsage Stats: ")
  
      h = [
          "NAME",
          "AVG CPU %",
          "PEAK CPU",
          "AVG MEM USAGE / LIMIT",
          "PEAK MEM",
          "NET I/O",
          "BLOCK I/O",
          "TOTAL TIME (ms)",
      ]
  
      p = [
          name,
          str(round(acpu, 3)) + "%",
          str(round(mcpu, 3)),
          str(bytes2human(amem, symbols="doc"))
          + " / "
          + str(bytes2human(amemlim, symbols="doc")),
          str(bytes2human(mmem, symbols="doc")),
          str(bytes2human(aneti, symbols="doc"))
          + " / "
          + str(bytes2human(aneto, symbols="doc")),
          str(bytes2human(ablocki, symbols="doc"))
          + " / "
          + str(bytes2human(ablocko, symbols="doc")),
          str(endtime - starttime),
      ]
      fp.write("\n")
      fp.write(tabulate([p], headers=h))
      print(tabulate([p], headers=h))
  
      fp.write(
          "\nRefer to the documentation on how to interpret the results."
      )
      print(
          "Refer to the documentation on how to interpret the results."
      )
      print("\n")
      fp.close()
      return (p, h)
  
imports: import sys
  from tabulate import tabulate
label_desc: Use image node_id 3 for calling a global function with example usage: getUsageStats(filename) and returns: p,  h