diff options
Diffstat (limited to 'plot_exps.py')
| -rwxr-xr-x | plot_exps.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/plot_exps.py b/plot_exps.py index 3b5636b..76e7396 100755 --- a/plot_exps.py +++ b/plot_exps.py | |||
| @@ -7,11 +7,11 @@ import shutil as sh | |||
| 7 | import sys | 7 | import sys |
| 8 | import traceback | 8 | import traceback |
| 9 | from collections import namedtuple | 9 | from collections import namedtuple |
| 10 | from multiprocessing import Pool, cpu_count | ||
| 10 | from optparse import OptionParser | 11 | from optparse import OptionParser |
| 11 | from parse.col_map import ColMap,ColMapBuilder | 12 | from parse.col_map import ColMap,ColMapBuilder |
| 12 | from parse.dir_map import DirMap | 13 | from parse.dir_map import DirMap |
| 13 | from plot.style import StyleMap | 14 | from plot.style import StyleMap |
| 14 | from multiprocessing import Pool, cpu_count | ||
| 15 | 15 | ||
| 16 | def parse_args(): | 16 | def parse_args(): |
| 17 | parser = OptionParser("usage: %prog [options] [csv_dir]...") | 17 | parser = OptionParser("usage: %prog [options] [csv_dir]...") |
| @@ -20,6 +20,9 @@ def parse_args(): | |||
| 20 | help='directory for plot output', default='plot-data') | 20 | help='directory for plot output', default='plot-data') |
| 21 | parser.add_option('-f', '--force', action='store_true', default=False, | 21 | parser.add_option('-f', '--force', action='store_true', default=False, |
| 22 | dest='force', help='overwrite existing data') | 22 | dest='force', help='overwrite existing data') |
| 23 | parser.add_option('-p', '--processors', default=max(cpu_count() - 1, 1), | ||
| 24 | type='int', dest='processors', | ||
| 25 | help='number of threads for processing') | ||
| 23 | 26 | ||
| 24 | return parser.parse_args() | 27 | return parser.parse_args() |
| 25 | 28 | ||
| @@ -97,7 +100,7 @@ def plot_wrapper(details): | |||
| 97 | except: | 100 | except: |
| 98 | traceback.print_exc() | 101 | traceback.print_exc() |
| 99 | 102 | ||
| 100 | def plot_dir(data_dir, out_dir, force): | 103 | def plot_dir(data_dir, out_dir, max_procs, force): |
| 101 | sys.stderr.write("Reading data...\n") | 104 | sys.stderr.write("Reading data...\n") |
| 102 | dir_map = DirMap.read(data_dir) | 105 | dir_map = DirMap.read(data_dir) |
| 103 | 106 | ||
| @@ -119,7 +122,7 @@ def plot_dir(data_dir, out_dir, force): | |||
| 119 | if not plot_details: | 122 | if not plot_details: |
| 120 | return | 123 | return |
| 121 | 124 | ||
| 122 | procs = min(len(plot_details), max(cpu_count()/2, 1)) | 125 | procs = min(len(plot_details), max_procs) |
| 123 | pool = Pool(processes=procs) | 126 | pool = Pool(processes=procs) |
| 124 | enum = pool.imap_unordered(plot_wrapper, plot_details) | 127 | enum = pool.imap_unordered(plot_wrapper, plot_details) |
| 125 | 128 | ||
| @@ -150,7 +153,7 @@ def main(): | |||
| 150 | out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1]) | 153 | out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1]) |
| 151 | else: | 154 | else: |
| 152 | out_dir = opts.out_dir | 155 | out_dir = opts.out_dir |
| 153 | plot_dir(dir, out_dir, opts.force) | 156 | plot_dir(dir, out_dir, opts.processors, opts.force) |
| 154 | 157 | ||
| 155 | if __name__ == '__main__': | 158 | if __name__ == '__main__': |
| 156 | main() | 159 | main() |
