Mercurial > cgi-bin > hgwebdir.cgi > VMS > 2__runs_and_data
view scripts/overhead_data_generation.py @ 24:6d03033aca59
added config file for HWSim ping-pong test program
| author | Sean <seanhalle@yahoo.com> |
|---|---|
| date | Thu, 17 May 2012 20:41:06 +0200 |
| parents | |
| children |
line source
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
4 import sys
5 from re import match, search
6 from pprint import pformat
7 from datetime import datetime
8 from subprocess import call,Popen,PIPE
10 """
11 This script generates a graph that represents the overhead
13 involved in synchronisation operations
14 This script generates results for 5 runs per threads and iteration in
15 TOTAL_THREADS_TABLE and ITER_PER_TASK_TABLE
16 """
18 usage="""
19 This runs the exec time vs task size in three levels of loop nest. The outer most iterates through
20 a selection of numbers-of-thread. For each of those, the next lever iterates over a number of work-loops-per-task
21 values. The innermost repeats several times and chooses the best.
22 Finally, it generates an output file for each value of number-of-threads that give the number of all runs.
23 It is expected that the output directory's path is meaningful, such as machine-name, date, and so on
24 Usage:
25 %s [executable binary] [path to output dir]
26 """ % sys.argv[0]
28 NUM_CORES = 4 #Number of Cores the code was compiled for
29 ITERS_PER_TASK_TABLE = [2, 5, 10, 20, 40, 80, 160, 320, 640] #Number of iterations of inner loop
30 TASKS_PER_THREAD = 30000 #Number of interations of outer loop
31 TOTAL_THREADS_TABLE = [8, 32, 128, 512]
33 def getNumber(line):
34 match_obj = search("(\d+\.?\d*)", line)
35 if match_obj != None:
36 return match_obj.groups()[0]
37 else:
38 raise ValueError
40 if len(sys.argv) != 3:
41 print usage
42 sys.exit(0)
44 cmd=sys.argv[1]
45 try:
46 f = open(cmd)
47 except IOError:
48 print "Please provide a valid executable."
49 f.close()
50 sys.exit(1)
51 finally:
52 f.close()
54 output_dir_path = sys.argv[2]
56 #===================================================================
57 # Done with parsing cmd line inputs, start doing the runs
58 #
60 for totalThreads in TOTAL_THREADS_TABLE:
61 print "\nDoing run with %d threads" % totalThreads
62 output = "%s/%d_thds__o%d__perfCtrs.meas" % (output_dir_path, totalThreads, TASKS_PER_THREAD)
63 print "output file: %s" % output
64 threadsPerCore = totalThreads/NUM_CORES
65 array_of_results = {}
66 for workload_iterations_in_task in ITERS_PER_TASK_TABLE:
67 print "Run for %s workload iterations in a task" % workload_iterations_in_task
68 results = []
69 for run in range(5):
70 print "Run %d" % run,
71 program_output = Popen("%s -t %d -i %d -o %d" % (cmd,
72 totalThreads,
73 workload_iterations_in_task,
74 TASKS_PER_THREAD),
75 stdout=PIPE, stderr=None, shell=True).stdout.read()
76 #parse arguments for
77 for line in program_output.split("\n"):
78 if match("^Sum across threads of work cycles:", line) != None:
79 total_workcycles = int(getNumber(line))
80 if match("^Total Execution Cycles:", line) != None:
81 total_exe_cycles = int(getNumber(line))
82 if match("^ExeCycles/WorkCycles Ratio", line) != None:
83 exeCycles_workCycles_ratio = float(getNumber(line))
84 results.append({"total_workcycles" : total_workcycles,
85 "total_exe_cycles" : total_exe_cycles,
86 "exeCycles_workCycles_ratio" : exeCycles_workCycles_ratio})
87 print "ratio %f" % exeCycles_workCycles_ratio
88 array_of_results[workload_iterations_in_task] = results
90 #open file to output data
91 try:
92 data_output = open(output,"w")
93 except IOError:
94 print "Cannot open output file %s" % output
95 sys.exit(1)
97 #output relevant data to file
98 data_output.write(";\n".join(["# This is a output of the overhead_data_generation.py script, run the overhead_result_calc.py script to get the calculated results",
99 "data_filename = " + pformat(output),
100 "NUM_CORES = " + pformat(NUM_CORES),
101 "ITERS_PER_TASK_TABLE = " + pformat(ITERS_PER_TASK_TABLE),
102 "TASKS_PER_THREAD = " + pformat(TASKS_PER_THREAD),
103 "date_of_run = " + pformat(datetime.now()),
104 "threads_per_core = " + pformat(threadsPerCore),
105 "totalThreads = " + pformat(totalThreads),
106 "# array_of_results: hash key is the number of iterations per task(inner iterations)",
107 "array_of_results = " + pformat(array_of_results)]))
110 data_output.close()
