Skip to content
Snippets Groups Projects
Commit 263bc951 authored by Alexander Heidelbach's avatar Alexander Heidelbach
Browse files

updated runtime script for --All and --format functions and got rid of bugs

parent fb7f77b0
Branches
Tags
No related merge requests found
......@@ -9,6 +9,7 @@ import matplotlib as mpl
import matplotlib.gridspec as gridspec
import matplotlib.lines as mlines
import matplotlib.patches as mpatches
import matplotlib.ticker as mticker
from matplotlib.ticker import (FormatStrFormatter, LogFormatter, NullFormatter, ScalarFormatter, AutoMinorLocator, MultipleLocator)
from matplotlib import cm
# We do not want any interactive plotting! Figures are saved to files instead.
......@@ -61,6 +62,8 @@ def main():
# extract correct paths for input and outputfiles
logfiles = get_files(args['logfiles'])
outputpath = args['output']
all_plot = args['All']
fmt = args['format']
# get all the information from logfiles as dict
# dict contains: runtime, runtime_unit, channel, events
......@@ -68,12 +71,12 @@ def main():
# plot all the information
if args['CPUtime']:
plot_elapsed_time(loginformation, outputpath)
plot_elapsed_time(loginformation, outputpath, all_plot, fmt)
if args['Events']:
plot_events_per_hour(loginformation, outputpath)
plot_events_per_hour(loginformation, outputpath, all_plot, fmt)
if not args['CPUtime'] and not args['Events']:
plot_elapsed_time(loginformation, outputpath)
plot_events_per_hour(loginformation, outputpath)
plot_elapsed_time(loginformation, outputpath, all_plot, fmt)
plot_events_per_hour(loginformation, outputpath, all_plot, fmt)
exit(0)
......@@ -86,9 +89,16 @@ def arguments():
parser.add_argument('logfiles', nargs='+', type=str, help='Either input is a single string from LAW Task or it is a list')
# optional arguments
parser.add_argument('-o', '--output', nargs=1, type=str, default='./', help='Set here the outputpath')
parser.add_argument('--CPUtime', dest='CPUtime', action='store_true', help='Plot only the elapsed time')
parser.add_argument('--Events', dest='Events', action='store_true', help='Plot only the events per hour')
parser.add_argument('-o', '--output', nargs=1, type=str, default='./',
help='Set here the outputpath')
parser.add_argument('--CPUtime', dest='CPUtime', action='store_true',
help='Plot only the elapsed time')
parser.add_argument('--Events', dest='Events', action='store_true',
help='Plot only the events per hour')
parser.add_argument('--All', dest='All', action='store_true',
help='Set plotoptions according to plot for all channels')
parser.add_argument('--format', required=False, nargs=1, type=str, default='png',
help='Comma-separated list of plot formats to use: eps, pdf, png, svg. If nothing is chosen, png is used.')
return vars(parser.parse_args())
......@@ -111,13 +121,24 @@ def get_loginformation(files):
for file in files:
event = False
run_time_temp = []
with open(file) as origin:
for line in origin:
# extract elapsed time with time unit
if 'Elapsed time' in line:
line = line.split()
run_time.append(float(line[3]))
unit = line[4]
if 'Time elapsed' in line:
line = line.split(':')
hours = float(line[1])
minutes = float(line[2])
seconds = float(line[3])
if hours == True:
run_time_temp.append(hours + minutes/60 + seconds/360)
unit = 'hours'
else:
run_time_temp.append(minutes + seconds/60)
unit = 'minutes'
# extract channel name
if 'Tablename' in line and not channel:
line = line.split()
......@@ -129,30 +150,32 @@ def get_loginformation(files):
number_events.append(float(line[4][10:]))
event = True
# found bug in logfiles where elapsed time is negativ
# temporary fix
run_time.append(run_time_temp[-1])
run_time = np.array(run_time)
number_events = np.array(number_events)
run_time_arr = run_time[run_time > 0]
number_events_arr = number_events[run_time > 0]
information = {
'runtime': run_time_arr,
'runtime': run_time,
'runtime_unit': unit,
'channel': channel,
'events': number_events_arr
'events': number_events
}
return information
def plot_elapsed_time(informationdict, out_path):
def plot_elapsed_time(informationdict, out_path, plot_all=False, format='png'):
time = informationdict['runtime']
unit = informationdict['runtime_unit']
channel = informationdict['channel']
if plot_all:
channel = channel.split('.')
channel = channel[0]
# get relevant values
mean = np.mean(time)
std = np.std(time)
......@@ -163,7 +186,7 @@ def plot_elapsed_time(informationdict, out_path):
# set saving location
filename = out_path[0] + ('' if out_path[0][-1] == '/' else '/')
filename += channel + '.Hist_Elapsed_time.png'
filename += channel + '.Hist_Elapsed_time.' + format
# set figure
fig = plt.figure(figsize=(16, 12))
......@@ -172,14 +195,15 @@ def plot_elapsed_time(informationdict, out_path):
# plot histogram
n, batches, _ = ax.hist(time, bins=20, color='deepskyblue', edgecolor='black', label='Total CPU time: {0:0.0f} hours'.format(CPUtime))
# plot mean and median
ax.vlines(mean, 0, max(n), colors='red', linestyles='dashed', label=r'Mean: {0:0.1f}$\pm${2:0.1f} {1}'.format(mean, unit, std))
ax.vlines(median, 0, max(n), colors='green', linestyles='dashed', label=r'Median: {0:0.1f}$\pm${2:0.1f} {1}'.format(median, unit, iqd))
if not plot_all:
# plot mean and median
ax.vlines(mean, 0, max(n), colors='red', linestyles='dashed', label=r'Mean: {0:0.1f}$\pm${2:0.1f} {1}'.format(mean, unit, std))
ax.vlines(median, 0, max(n), colors='green', linestyles='dashed', label=r'Median: {0:0.1f}$\pm${2:0.1f} {1}'.format(median, unit, iqd))
# finish and save figure
ax.set_title('Elapsed time of ' + channel + ' production', fontsize=20)
ax.set_xlabel('CPU time [' + unit + ']', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20)
ax.set_ylabel('frequency', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20)
ax.set_xlabel('CPU time [' + unit + ']', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20, labelpad=15)
ax.set_ylabel('frequency', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20, labelpad=15)
ax.set_yscale('log')
ax.tick_params(axis='both', which='major', labelsize=20)
......@@ -189,7 +213,7 @@ def plot_elapsed_time(informationdict, out_path):
fig.savefig(filename)
def plot_events_per_hour(informationdict, out_path):
def plot_events_per_hour(informationdict, out_path, plot_all=False, format='png'):
time = informationdict['runtime']
unit = informationdict['runtime_unit']
......@@ -201,6 +225,10 @@ def plot_events_per_hour(informationdict, out_path):
else:
eph = events/(time/60)
if plot_all:
channel = channel.split('.')
channel = channel[0]
# get relevant values
mean = np.mean(eph)
std = np.std(eph)
......@@ -212,7 +240,7 @@ def plot_events_per_hour(informationdict, out_path):
# set saving location
filename = out_path[0] + ('' if out_path[0][-1] == '/' else '/')
filename += channel + '.Hist_Events_per_hour.png'
filename += channel + '.Hist_Events_per_hour.' + format
# set figure
fig = plt.figure(figsize=(16, 12))
......@@ -221,14 +249,20 @@ def plot_events_per_hour(informationdict, out_path):
# plot histogram
n, batches, _ = ax.hist(eph, bins=20, color='deepskyblue', edgecolor='black', label='Total CPU time: {0:0.0f} hours'.format(CPUtime))
# plot mean and median
ax.vlines(mean, 0, max(n), colors='red', linestyles='dashed', label=r'Mean: {0:0.1e}$\pm${1:0.1e} events/hour'.format(mean, std))
ax.vlines(median, 0, max(n), colors='green', linestyles='dashed', label=r'Median: {0:0.2e}$\pm${1:0.2e} events/hour'.format(median, iqd))
if not plot_all:
# scientific format
f = mticker.ScalarFormatter(useOffset=False, useMathText=True)
g = lambda x,pos : "${}$".format(f._formatSciNotation('%0.2e' % x))
sci = mticker.FuncFormatter(g)
# plot mean and median
ax.vlines(mean, 0, max(n), colors='red', linestyles='dashed', label=r'Mean: {0}$\pm${1} events/hour'.format(sci(mean), sci(std)))
ax.vlines(median, 0, max(n), colors='green', linestyles='dashed', label=r'Median: {0}$\pm${1} events/hour'.format(sci(median), sci(iqd)))
# finish and save figure
ax.set_title('Events per hour of ' + channel + ' production', fontsize=20)
ax.set_xlabel('events/hour', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20)
ax.set_ylabel('frequency', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20)
ax.set_xlabel('events/hour', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20, labelpad=15)
ax.set_ylabel('frequency', horizontalalignment='right', x=1.0, verticalalignment='top', y=1.0, fontsize=20, labelpad=15)
ax.set_yscale('log')
ax.tick_params(axis='both', which='major', labelsize=20)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment