github.com/DARA-Project/GoDist-Scheduler@v0.0.0-20201030134746-668de4acea0d/macro-benchmarks/plot_schedule.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 get_column(filename, col_name):
     8      df = pd.read_csv(filename)
     9      return df[col_name]
    10  
    11  def get_value(filename, name):
    12      column = get_column(filename, name)
    13      return np.mean(column)
    14  
    15  def plot_vertical_bars(name, data, xlabels, legend, ylabel,figsize, xlabel=""):
    16      N = len(data[0])
    17      indices = np.arange(N)
    18      patterns = ('//', '\\\\', 'o', '+', 'x', '*', '-', 'O', '.')
    19      # width = 1 / len(data)
    20      # This is the fitting width. Right now, lets just hardcode it
    21      if N == 1:
    22          new_indices = np.arange(len(legend))
    23          fig = plt.figure(figsize=figsize)
    24          ax = fig.add_subplot(111)
    25          i = 0
    26          rects = ()
    27          for d in data:
    28              rect = ax.bar([new_indices[i]],d, width=0.5, hatch=patterns[i]) 
    29              rects = rects + (rect[0],)
    30              i += 1
    31  
    32          ax.set_ylabel(ylabel)
    33          ax.set_xticks([])
    34          ax.set_xticklabels([])
    35          ax.set_xlabel(xlabels[0])
    36          ax.set_xlim(new_indices[0]-1, new_indices[len(legend)-1]+1)
    37          ax.legend(rects, legend, ncol=len(data))
    38          plt.savefig(name + ".png", bbox_inches="tight")
    39      if N >= 2:
    40          width = 0.15
    41          fig = plt.figure(figsize=figsize)
    42          ax = fig.add_subplot(111)
    43  
    44          i = 0
    45          rects = ()
    46          for d in data:
    47              rect = ax.bar(indices + width * i, d, width, hatch=patterns[i])
    48              rects = rects + (rect[0],)
    49              i += 1
    50  
    51          ax.set_ylabel(ylabel)
    52          ax.set_xticks(indices + width * (len(data)-1)/2)
    53          ax.set_xticklabels(xlabels)
    54          if xlabel != "":
    55              ax.set_xlabel(xlabel)
    56          ax.legend(rects, legend, loc='lower left', bbox_to_anchor=(0.0,1.01), frameon=False, ncol=len(data))
    57          #ax.legend(rects, legend, ncol=len(data))
    58          plt.savefig(name + ".png", bbox_inches="tight")
    59  
    60  def line_plot(name, xdata, ydata, xlabel, ylabel, figsize):
    61      fig = plt.figure(figsize=figsize)
    62      ax = fig.add_subplot(111)
    63      ax.plot(xdata, ydata, marker="o")
    64      ax.set_xlabel(xlabel)
    65      ax.set_ylabel(ylabel)
    66      plt.savefig(name + ".png", bbox_inches="tight")
    67  
    68  def main():
    69      if len(sys.argv) < 3:
    70          print("Usage: python plot_schedule.py [option] <events.csv> <rest_of_args>")
    71          sys.exit(1) 
    72      option = sys.argv[1]
    73      print(option)
    74      if option == "mve":
    75          events_file = sys.argv[2]
    76          memory_file = sys.argv[3]
    77          events = get_column(events_file, "Events")
    78          memory = get_column(memory_file, "Memory") / 1024
    79          line_plot("memory_vs_events",events, memory, "Number of Events", "Schedule Size (in KB)", (8,4))
    80      elif option == "time":
    81          events_file = sys.argv[2]
    82          go_vals = []
    83          record_vals = []
    84          replay_vals = []
    85          names = []
    86          for f in sys.argv[2:]:
    87              name = os.path.splitext(os.path.basename(f))[0]
    88              names += [name.split('-')[1]]
    89              go_val = get_value(f, "Normal")
    90              record_val = get_value(f, "Record")
    91              replay_val = get_value(f, "Replay")
    92              go_vals += [go_val/go_val]
    93              record_vals += [record_val/go_val]
    94              replay_vals += [replay_val/go_val]
    95          data = []
    96          data += [go_vals]
    97          data += [record_vals]
    98          data += [replay_vals]
    99          plot_vertical_bars("Replay_ffwd", data, names, ['Go v1.10.4', 'Record', 'Replay'], 'Slowdown factor', (8,4), "Number of iterations for SimpleFileReadIterative")
   100      elif option == "sched":
   101          events_file = sys.argv[2]
   102          go_vals = []
   103          record_vals = []
   104          replay_vals = []
   105          names = []
   106          for f in sys.argv[2:]:
   107              name = os.path.splitext(os.path.basename(f))[0]
   108              names += [name.split('-')[1]]
   109              go_val = get_value(f, "Normal")
   110              record_val = get_value(f, "Record")
   111              replay_val = get_value(f, "Replay")
   112              go_vals += [go_val/go_val]
   113              record_vals += [record_val/go_val]
   114              replay_vals += [replay_val/go_val]
   115          data = []
   116          data += [go_vals]
   117          data += [record_vals]
   118          data += [replay_vals]
   119          plot_vertical_bars("Sched_Replay", data, names, ['Go v1.10.4', 'Record', 'Replay'], 'Slowdown factor', (8,4), "Number of iterations for sharedIntegerChannelIterative")
   120      elif option == "sched_fast":
   121          events_file = sys.argv[2]
   122          go_vals = []
   123          record_vals = []
   124          replay_vals = []
   125          fast_replay_vals = []
   126          names = []
   127          for f in sys.argv[2:]:
   128              name = os.path.splitext(os.path.basename(f))[0]
   129              names += [name.split('-')[1]]
   130              go_val = get_value(f, "Normal")
   131              record_val = get_value(f, "Record")
   132              replay_val = get_value(f, "Replay")
   133              fast_replay_val = get_value(f, "Fast_Replay")
   134              go_vals += [go_val/go_val]
   135              record_vals += [record_val/go_val]
   136              replay_vals += [replay_val/go_val]
   137              fast_replay_vals += [fast_replay_val/go_val]
   138          data = []
   139          data += [go_vals]
   140          data += [record_vals]
   141          data += [replay_vals]
   142          data += [fast_replay_vals]
   143          print(data)
   144          plot_vertical_bars("Sched_Fast_Replay", data, names, ['Go v1.10.4', 'Record', 'Replay', 'Fast Replay'], 'Slowdown factor', (8,4), "Number of iterations for sharedIntegerChannelIterative")
   145      else :
   146          print("Invalid option selected")
   147          sys.exit(1)
   148  
   149  if __name__ == '__main__':
   150      main()