msach@4: #! /usr/bin/env python msach@4: # -*- coding: utf-8 -*- msach@4: msach@4: import sys msach@4: from re import search msach@4: import datetime msach@4: from os.path import basename msach@4: msach@4: """ msach@4: This script generates a graph that represents the overhead msach@4: involved in synchronisation operations msach@4: """ msach@4: msach@4: usage=""" msach@4: This generates an output file for each value of number-of-threads that give the number of all runs. msach@4: As an input it expects a result file which is generated by the overhead_result_calc.py script. msach@4: The file extension of the result file has to be ".meas". msach@4: It is expected that the output directory's path is meaningful, such as machine-name, date, and so on msach@4: Usage: msach@4: %s [result files] [path to output dir] msach@4: """ % sys.argv[0] msach@4: msach@4: if len(sys.argv) < 3: msach@4: print usage msach@4: sys.exit(0) msach@4: msach@4: result_filenames = sys.argv[1:-1] msach@4: output_dir_path = sys.argv[-1] msach@4: msach@4: for result_filename in result_filenames: msach@4: #open input file msach@4: try: msach@4: result_file = open(result_filename,"r") msach@4: except: msach@4: print "Cannot open result file %s" % result_filename msach@4: sys.exit(1) msach@4: msach@4: #parse(evaluate) result file msach@4: try: msach@4: exec(result_file.read()) msach@4: except: msach@4: print "Cannot parse result file: %s" % result_filename msach@4: result_file.close() msach@4: sys.exit(1) msach@4: result_file.close() msach@4: msach@4: #check for file extension msach@4: result_filename = basename(result_filename) msach@4: if search("\.meas$",result_filename) == None: msach@4: print "Wrong file extension! Has to be '.meas'" msach@4: sys.exit(1) msach@4: msach@4: output = output_dir_path + "/" + result_filename.replace(".meas",".result") msach@4: #open gnuplot output msach@4: try: msach@4: gnuplot_output = open(output,"w") msach@4: except IOError: msach@4: print "Cannot open output file %s" % output msach@4: result_file.close() msach@4: sys.exit(1) msach@4: msach@4: table_header = "# %20s\t%20s\t%20s\t%20s\t%20s\t%20s\t%20s\t%20s\n" % ( msach@4: "", msach@4: "", msach@4: "", msach@4: "", msach@4: "", msach@4: "", msach@4: "", msach@4: "") msach@4: msach@4: #write header to file msach@4: gnuplot_output.writelines(["# Output file name: %s\n" % data_filename, msach@4: "# Date of Run: %s\n" % date_of_run, msach@4: "# Number of Cores: %d\n" % NUM_CORES, msach@4: "# Number of Threads: %f per Core, %d total\n" % (threads_per_core, totalThreads), msach@4: table_header, msach@4: "# " + (len(table_header)-3)*"-" + "\n"]) msach@4: msach@4: #Now print the results out msach@4: for workload_iterations_in_task in ITERS_PER_TASK_TABLE: msach@4: results = array_of_results[workload_iterations_in_task] msach@4: msach@4: #take shortest run msach@4: results.sort(lambda x,y: cmp(x["total_exe_cycles"],y["total_exe_cycles"])) msach@4: total_workcycles = results[0]["total_workcycles"] msach@4: total_exe_cycles = results[0]["total_exe_cycles"] msach@4: #exeCycles_workCycles_ratio = results[0]["exeCycles_workCycles_ratio"] msach@4: msach@4: #Calculate numbers msach@4: overhead = total_exe_cycles - total_workcycles msach@4: total_syncs = totalThreads * TASKS_PER_THREAD * 2 msach@4: overhead_per_sync = float(overhead) / float(total_syncs) msach@4: cycles_of_task = float(total_workcycles) / float(TASKS_PER_THREAD * totalThreads) msach@4: overhead_per_core = float(overhead) / NUM_CORES msach@4: workcycles_per_core = total_workcycles / NUM_CORES msach@4: msach@4: # The 2 is in there because we have two sync operations in one per outer iteration msach@4: exeCycles_workCycles_ratio = float(total_workcycles+float(overhead)/2)/float(total_workcycles) msach@4: msach@4: gnuplot_output.write("%20d\t%20d\t%20d\t%20f\t%20d\t%20d\t%20f\t%20f\n" % ( msach@4: workload_iterations_in_task, msach@4: total_exe_cycles, msach@4: total_workcycles, msach@4: cycles_of_task, msach@4: overhead, msach@4: total_syncs, msach@4: overhead_per_sync, msach@4: exeCycles_workCycles_ratio)) msach@4: msach@4: gnuplot_output.close();