annotate scripts/overhead_result_calc.py @ 11:25dc41101f5d

exec_time_vs_task_size: data, results and graphs for xoanon
author Merten Sach <msach@mailbox.tu-berlin.de>
date Fri, 20 Jan 2012 14:16:45 +0100
parents
children
rev   line source
msach@4 1 #! /usr/bin/env python
msach@4 2 # -*- coding: utf-8 -*-
msach@4 3
msach@4 4 import sys
msach@4 5 from re import search
msach@4 6 import datetime
msach@4 7 from os.path import basename
msach@4 8
msach@4 9 """
msach@4 10 This script generates a graph that represents the overhead
msach@4 11 involved in synchronisation operations
msach@4 12 """
msach@4 13
msach@4 14 usage="""
msach@4 15 This generates an output file for each value of number-of-threads that give the number of all runs.
msach@4 16 As an input it expects a result file which is generated by the overhead_result_calc.py script.
msach@4 17 The file extension of the result file has to be ".meas".
msach@4 18 It is expected that the output directory's path is meaningful, such as machine-name, date, and so on
msach@4 19 Usage:
msach@4 20 %s [result files] [path to output dir]
msach@4 21 """ % sys.argv[0]
msach@4 22
msach@4 23 if len(sys.argv) < 3:
msach@4 24 print usage
msach@4 25 sys.exit(0)
msach@4 26
msach@4 27 result_filenames = sys.argv[1:-1]
msach@4 28 output_dir_path = sys.argv[-1]
msach@4 29
msach@4 30 for result_filename in result_filenames:
msach@4 31 #open input file
msach@4 32 try:
msach@4 33 result_file = open(result_filename,"r")
msach@4 34 except:
msach@4 35 print "Cannot open result file %s" % result_filename
msach@4 36 sys.exit(1)
msach@4 37
msach@4 38 #parse(evaluate) result file
msach@4 39 try:
msach@4 40 exec(result_file.read())
msach@4 41 except:
msach@4 42 print "Cannot parse result file: %s" % result_filename
msach@4 43 result_file.close()
msach@4 44 sys.exit(1)
msach@4 45 result_file.close()
msach@4 46
msach@4 47 #check for file extension
msach@4 48 result_filename = basename(result_filename)
msach@4 49 if search("\.meas$",result_filename) == None:
msach@4 50 print "Wrong file extension! Has to be '.meas'"
msach@4 51 sys.exit(1)
msach@4 52
msach@4 53 output = output_dir_path + "/" + result_filename.replace(".meas",".result")
msach@4 54 #open gnuplot output
msach@4 55 try:
msach@4 56 gnuplot_output = open(output,"w")
msach@4 57 except IOError:
msach@4 58 print "Cannot open output file %s" % output
msach@4 59 result_file.close()
msach@4 60 sys.exit(1)
msach@4 61
msach@4 62 table_header = "# %20s\t%20s\t%20s\t%20s\t%20s\t%20s\t%20s\t%20s\n" % (
msach@4 63 "<iters per task>",
msach@4 64 "<total exe cycles>",
msach@4 65 "<total work cyc>",
msach@4 66 "<one task cyc>",
msach@4 67 "<total overhead cyc>",
msach@4 68 "<num syncs>",
msach@4 69 "<overhead per Sync cyc>",
msach@4 70 "<Exe/Work ratio>")
msach@4 71
msach@4 72 #write header to file
msach@4 73 gnuplot_output.writelines(["# Output file name: %s\n" % data_filename,
msach@4 74 "# Date of Run: %s\n" % date_of_run,
msach@4 75 "# Number of Cores: %d\n" % NUM_CORES,
msach@4 76 "# Number of Threads: %f per Core, %d total\n" % (threads_per_core, totalThreads),
msach@4 77 table_header,
msach@4 78 "# " + (len(table_header)-3)*"-" + "\n"])
msach@4 79
msach@4 80 #Now print the results out
msach@4 81 for workload_iterations_in_task in ITERS_PER_TASK_TABLE:
msach@4 82 results = array_of_results[workload_iterations_in_task]
msach@4 83
msach@4 84 #take shortest run
msach@4 85 results.sort(lambda x,y: cmp(x["total_exe_cycles"],y["total_exe_cycles"]))
msach@4 86 total_workcycles = results[0]["total_workcycles"]
msach@4 87 total_exe_cycles = results[0]["total_exe_cycles"]
msach@4 88 #exeCycles_workCycles_ratio = results[0]["exeCycles_workCycles_ratio"]
msach@4 89
msach@4 90 #Calculate numbers
msach@4 91 overhead = total_exe_cycles - total_workcycles
msach@4 92 total_syncs = totalThreads * TASKS_PER_THREAD * 2
msach@4 93 overhead_per_sync = float(overhead) / float(total_syncs)
msach@4 94 cycles_of_task = float(total_workcycles) / float(TASKS_PER_THREAD * totalThreads)
msach@4 95 overhead_per_core = float(overhead) / NUM_CORES
msach@4 96 workcycles_per_core = total_workcycles / NUM_CORES
msach@4 97
msach@4 98 # The 2 is in there because we have two sync operations in one per outer iteration
msach@4 99 exeCycles_workCycles_ratio = float(total_workcycles+float(overhead)/2)/float(total_workcycles)
msach@4 100
msach@4 101 gnuplot_output.write("%20d\t%20d\t%20d\t%20f\t%20d\t%20d\t%20f\t%20f\n" % (
msach@4 102 workload_iterations_in_task,
msach@4 103 total_exe_cycles,
msach@4 104 total_workcycles,
msach@4 105 cycles_of_task,
msach@4 106 overhead,
msach@4 107 total_syncs,
msach@4 108 overhead_per_sync,
msach@4 109 exeCycles_workCycles_ratio))
msach@4 110
msach@4 111 gnuplot_output.close();