aboutsummaryrefslogtreecommitdiffstats
path: root/plot_exps.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-04-21 13:28:38 -0400
committerJonathan Herman <hermanjl@cs.unc.edu>2013-04-21 13:28:38 -0400
commitfbd1df6f63eb551b99f71330d2370c570ff323f5 (patch)
treeca0db4599365bf8f4de7cd247c6363ef0ffba288 /plot_exps.py
parentdaa0e3a92e03a89baf7ea3750df374df79123245 (diff)
Scripts read directories created by other scripts if no arguments.
With no arguments, all scripts first try to load the current directory. If the current directory has no data, the scripts search for the output of the previous scripts in the toolchain, e.g. parse_exps.py loads run-data/*, created by run_exps.py. This commit also switched messages to stderr where they belong, and adds in missing lock and unlock overheads.
Diffstat (limited to 'plot_exps.py')
-rwxr-xr-xplot_exps.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/plot_exps.py b/plot_exps.py
index 76e7396..15c54d0 100755
--- a/plot_exps.py
+++ b/plot_exps.py
@@ -6,7 +6,9 @@ import os
6import shutil as sh 6import shutil as sh
7import sys 7import sys
8import traceback 8import traceback
9
9from collections import namedtuple 10from collections import namedtuple
11from config.config import DEFAULTS
10from multiprocessing import Pool, cpu_count 12from multiprocessing import Pool, cpu_count
11from optparse import OptionParser 13from optparse import OptionParser
12from parse.col_map import ColMap,ColMapBuilder 14from parse.col_map import ColMap,ColMapBuilder
@@ -17,7 +19,8 @@ def parse_args():
17 parser = OptionParser("usage: %prog [options] [csv_dir]...") 19 parser = OptionParser("usage: %prog [options] [csv_dir]...")
18 20
19 parser.add_option('-o', '--out-dir', dest='out_dir', 21 parser.add_option('-o', '--out-dir', dest='out_dir',
20 help='directory for plot output', default='plot-data') 22 help='directory for plot output',
23 default=DEFAULTS['out-plot'])
21 parser.add_option('-f', '--force', action='store_true', default=False, 24 parser.add_option('-f', '--force', action='store_true', default=False,
22 dest='force', help='overwrite existing data') 25 dest='force', help='overwrite existing data')
23 parser.add_option('-p', '--processors', default=max(cpu_count() - 1, 1), 26 parser.add_option('-p', '--processors', default=max(cpu_count() - 1, 1),
@@ -139,21 +142,31 @@ def plot_dir(data_dir, out_dir, max_procs, force):
139 142
140 sys.stderr.write('\n') 143 sys.stderr.write('\n')
141 144
145def get_dirs(args):
146 if args:
147 return args
148 elif os.path.exists(DEFAULTS['out-parse']):
149 return [DEFAULTS['out-parse']]
150 else:
151 return os.getcwd()
152
142def main(): 153def main():
143 opts, args = parse_args() 154 opts, args = parse_args()
144 args = args or [os.getcwd()] 155 dirs = get_dirs(args)
145 156
146 if opts.force and os.path.exists(opts.out_dir): 157 if opts.force and os.path.exists(opts.out_dir):
147 sh.rmtree(opts.out_dir) 158 sh.rmtree(opts.out_dir)
148 if not os.path.exists(opts.out_dir): 159 if not os.path.exists(opts.out_dir):
149 os.mkdir(opts.out_dir) 160 os.mkdir(opts.out_dir)
150 161
151 for dir in args: 162 for dir in dirs:
152 if len(args) > 1: 163 if len(dirs) > 1:
153 out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1]) 164 out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1])
154 else: 165 else:
155 out_dir = opts.out_dir 166 out_dir = opts.out_dir
156 plot_dir(dir, out_dir, opts.processors, opts.force) 167 plot_dir(dir, out_dir, opts.processors, opts.force)
157 168
169 sys.stderr.write("Plots saved in %s.\n" % opts.out_dir)
170
158if __name__ == '__main__': 171if __name__ == '__main__':
159 main() 172 main()