analyze.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import matplotlib.mlab as mlab
  4. import matplotlib.pyplot as plt
  5. import matplotlib.patches as mpatches
  6. import sets
  7. import math
  8. import csv
  9. # List containing all the platform names
  10. platforms = ['cpu', 'gpu-primary', 'gpu-secondary']
  11. # Function that takes as parameter a platform and computes averages and variance of the results, and saves them in two dedicated files (averages.dat and variances.dat)
  12. def computeAverages( platform ):
  13. # Import raw data from file
  14. data = np.genfromtxt('results/' + platform + '/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  15. # We construct a set in which we insert each benchmark name once
  16. nameset = set()
  17. names = data['name']
  18. for name in names:
  19. nameset.add(name)
  20. # Helper dicts to store the results computed in the next loop
  21. timesAverages, powerAverages, timesVariances, powerVariances = {}, {}, {}, {}
  22. # For each benchmark we iterate over the results, take into account the values and save the average and the variance in a corresponding record in the dicts
  23. for benchmarkName in nameset:
  24. # Temporary variables to store the results of the currently analyzed benchmark
  25. times, power = [], []
  26. # For each record we copy the values if the name is equal to the currently analyzed
  27. for record in data:
  28. if benchmarkName == record['name']:
  29. times.append(record['time'])
  30. # Before writing the value we convert it from Watt/hour to mWatt/hour
  31. power.append(record['power']*1000)
  32. # Since the power measurement utility sometimes is not able to get the results from the measurement device, we cleanse the list containing the power measurement values from the invalid (nan) values
  33. cleanedPower = [x for x in power if math.isnan(x) == False]
  34. # We compute the average of time and consumption and store it in the corresponding entries in the dict
  35. timesAverages[benchmarkName] = np.average(times)
  36. powerAverages[benchmarkName] = np.average(cleanedPower)
  37. timesVariances[benchmarkName] = np.std(times)
  38. powerVariances[benchmarkName] = np.std(cleanedPower)
  39. # Write on file the averages
  40. with open('results/' + platform + '/average.csv', 'wb') as csvfile:
  41. filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
  42. for benchmarkName in nameset:
  43. filewriter.writerow([benchmarkName, timesAverages[benchmarkName], powerAverages[benchmarkName]])
  44. # Write on file the variance
  45. with open('results/' + platform + '/stderr.csv', 'wb') as csvfile:
  46. filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
  47. for benchmarkName in nameset:
  48. filewriter.writerow([benchmarkName, timesVariances[benchmarkName], powerVariances[benchmarkName]])
  49. # Execute the average and variance computation for each platform specified in the platforms list
  50. for platform in platforms:
  51. computeAverages(platform)