github.com/DARA-Project/GoDist-Scheduler@v0.0.0-20201030134746-668de4acea0d/macro-benchmarks/plot_macro.py (about)

     1  import matplotlib.pyplot as plt
     2  import numpy as np
     3  import pandas as pd
     4  import sys
     5  import os
     6  
     7  def plot_vertical_bars(name, data, xlabels, legend, ylabel,figsize):
     8      N = len(data[0])
     9      indices = np.arange(N)
    10      patterns = ('//', '\\\\', 'o', '+', 'x', '*', '-', 'O', '.')
    11      # width = 1 / len(data)
    12      # This is the fitting width. Right now, lets just hardcode it
    13      if N == 1:
    14          new_indices = np.arange(len(legend))
    15          fig = plt.figure(figsize=figsize)
    16          ax = fig.add_subplot(111)
    17          i = 0
    18          rects = ()
    19          for d in data:
    20              rect = ax.bar([new_indices[i]],d, width=0.5, hatch=patterns[i]) 
    21              rects = rects + (rect[0],)
    22              i += 1
    23  
    24          ax.set_ylabel(ylabel)
    25          ax.set_xticks([])
    26          ax.set_xticklabels([])
    27          ax.set_xlabel(xlabels[0])
    28          ax.set_xlim(new_indices[0]-1, new_indices[len(legend)-1]+1)
    29          ax.legend(rects, legend, ncol=len(data))
    30          plt.savefig(name + ".png", bbox_inches="tight")
    31      if N >= 2:
    32          width = 0.15
    33          fig = plt.figure(figsize=figsize)
    34          ax = fig.add_subplot(111)
    35  
    36          i = 0
    37          rects = ()
    38          for d in data:
    39              rect = ax.bar(indices + width * i, d, width, hatch=patterns[i])
    40              rects = rects + (rect[0],)
    41              i += 1
    42  
    43          ax.set_ylabel(ylabel)
    44          ax.set_xlabel("Number of scheduled actions in the application")
    45          ax.set_xticks(indices + width * (len(data)-1)/2)
    46          ax.set_xticklabels(xlabels)
    47          #ax.legend(rects, legend, loc='lower left', bbox_to_anchor=(0.0,1.01), frameon=False, ncol=int(len(data)/2))
    48          ax.legend(rects, legend, ncol=len(data))
    49          plt.savefig(name + ".png", bbox_inches="tight")
    50  
    51  def get_value(df, name):
    52      runs = pd.to_numeric(df[name])
    53      print(np.mean(runs))
    54      return np.mean(runs)
    55  
    56  def main():
    57      if len(sys.argv) < 2:
    58          print("Usage: python plot_macro.py <list_of_benchmark_files>")
    59          sys.exit(1)
    60      files = sys.argv[1:]
    61      normal = []
    62      record = []
    63      replay = []
    64      names = []
    65      for f in files:
    66          print("Processing",f)
    67          name = os.path.splitext(os.path.basename(f))[0]
    68          df = pd.read_csv(f)
    69          normal_val = get_value(df, "Normal")
    70          record_val = get_value(df, "Record")
    71          replay_val = get_value(df, "Replay")
    72          normal += [normal_val/normal_val]
    73          record += [record_val/normal_val]
    74          replay += [replay_val/normal_val]
    75      data = []
    76      data += [normal]
    77      data += [record]
    78      data += [replay]
    79      df = pd.read_csv('events.csv')
    80      plot_vertical_bars("Macro_Bench", data, names, ['Go v1.10.4', 'Record', 'Schedule'], 'Slowdown factor', (8,4)) 
    81  
    82  if __name__ == '__main__':
    83      main()