Ver Fonte

SCRIPTS: Added analyze script to compute final results

Added a python script that takes all the raw data corresponding to the
measurements, computes averages and variances and saves in two files
(average.csv and variance.csv) the results. This data will be in turn
use by the plot script to create the charts.

Some minor fixed to the plot script.
Andrea Gussoni há 8 anos atrás
pai
commit
6da79bc521
2 ficheiros alterados com 80 adições e 3 exclusões
  1. 69 0
      utils/analyze.py
  2. 11 3
      utils/plot.py

+ 69 - 0
utils/analyze.py

@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+import numpy as np
+import matplotlib.mlab as mlab
+import matplotlib.pyplot as plt
+import matplotlib.patches as mpatches
+import sets
+import math
+import csv
+
+# List containing all the platform names
+platforms = ['cpu', 'gpu-primary', 'gpu-secondary']
+
+# 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)
+def computeAverages( platform ):
+
+    # Import raw data from file
+    data = np.genfromtxt('results/' + platform + '/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
+
+    # We construct a set in which we insert each benchmark name once
+    nameset = set()
+    names = data['name']
+    for name in names:
+        nameset.add(name)
+
+    # Helper dicts to store the results computed in the next loop
+    timesAverages = {}
+    powerAverages = {}
+    timesVariances = {}
+    powerVariances = {}
+
+    # 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
+    for benchmarkName in nameset:
+
+        # Temporary variables to store the results of the currently analyzed benchmark
+        times = []
+        power = []
+
+        # For each record we copy the values if the name is equal to the currently analyzed
+        for record in data:
+            if benchmarkName == record['name']:
+                times.append(record['time'])
+                power.append(record['power'])
+
+        # 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
+        cleanedPower = [x for x in power if math.isnan(x) == False]
+
+        # We compute the average of time and consumption and store it in the corresponding entries in the dict
+        timesAverages[benchmarkName] = np.average(times)
+        powerAverages[benchmarkName] = np.average(cleanedPower)
+        timesVariances[benchmarkName] = np.var(times)
+        powerVariances[benchmarkName] = np.var(cleanedPower)
+
+    # Write on file the averages
+    with open('results/' + platform + '/average.csv', 'wb') as csvfile:
+        filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
+
+        for benchmarkName in nameset:
+            filewriter.writerow([benchmarkName, timesAverages[benchmarkName], powerAverages[benchmarkName]])
+
+    # Write on file the variance
+    with open('results/' + platform + '/variance.csv', 'wb') as csvfile:
+        filewriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
+
+        for benchmarkName in nameset:
+            filewriter.writerow([benchmarkName, timesVariances[benchmarkName], powerVariances[benchmarkName]])
+
+# Execute the average and variance computation for each platform specified in the platforms list
+for platform in platforms:
+    computeAverages(platform)

+ 11 - 3
utils/plot.py

@@ -5,9 +5,15 @@ import matplotlib.pyplot as plt
 import matplotlib.patches as mpatches
 
 # Import data from file
-data_cpu = np.genfromtxt('results/cpu/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
-data_gpu_primary = np.genfromtxt('results/gpu-primary/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
-data_gpu_secondary = np.genfromtxt('results/gpu-secondary/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
+data_cpu = np.genfromtxt('results/cpu/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
+data_gpu_primary = np.genfromtxt('results/gpu-primary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
+data_gpu_secondary = np.genfromtxt('results/gpu-secondary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
+
+# We construct a set in which we insert each benchmark name once
+nameset = set()
+names = data_cpu['name']
+for name in names:
+    nameset.add(name)
 
 # Generate an array as placeholder for the x axis (we need to pass from a list to an array to take advantage of range)
 x = range(0, 17)
@@ -36,6 +42,7 @@ green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core
 
 plt.legend(handles=[red_patch, blue_patch, green_patch])
 
+# Save the obtained plot on file
 plt.savefig('times.pdf')
 plt.show()
 
@@ -56,5 +63,6 @@ green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core
 
 plt.legend(handles=[red_patch, blue_patch, green_patch])
 
+# Save the obtained plot on file
 plt.savefig('power.pdf')
 plt.show()