def openmdao_cmd(): """ Wrap a number of Problem viewing/debugging command line functions. """ parser = argparse.ArgumentParser() subs = parser.add_subparsers(help='sub-command help') for p, (parser_setup_func, cmd) in iteritems(_post_setup_map): subp = subs.add_parser(p) parser_setup_func(subp) subp.set_defaults(func=cmd, executor=_post_setup_exec) for p, (parser_setup_func, cmd) in iteritems(_non_post_setup_map): subp = subs.add_parser(p) parser_setup_func(subp) subp.set_defaults(executor=cmd) # handle case where someone just runs `openmdao <script>` args = [a for a in sys.argv[1:] if not a.startswith('-')] if not set(args).intersection( subs.choices) and len(args) == 1 and os.path.isfile(args[0]): _post_setup_exec(_Options(file=[args[0]], func=None)) else: options = parser.parse_args() if hasattr(options, 'executor'): options.executor(options) else: print("\nNothing to do.")
def memtrace(**kwargs): """ Turn on memory tracing within a certain context. Parameters ---------- kwargs : dict Named options to pass to setup. """ options = _Options(**kwargs) if options.outfile is None: options.outfile = 'mem_trace.raw' if options.min_mem is None: options.min_mem = 1.0 if options.stream is None: options.stream = sys.stdout _setup(options) start() yield stop() _file_line2qualname(options.outfile) if options.tree: postprocess_memtrace_tree(fname=options.outfile, min_mem=options.min_mem, show_colors=options.show_colors, stream=options.stream) else: postprocess_memtrace_flat(fname=options.outfile, min_mem=options.min_mem, show_colors=options.show_colors, stream=options.stream)
def setup(methods=None, finalize=True): """ Instruments certain important openmdao methods for profiling. Parameters ---------- methods : list, optional A list of tuples of profiled methods to override the default set. The first entry is the method name or glob pattern and the second is a tuple of class objects used for isinstance checking. The default set of methods is: .. code-block:: python [ "*": (System, Jacobian, Matrix, Solver, Driver, Problem), ] finalize : bool If True, register a function to finalize the profile before exit. """ if not func_group: _setup_func_group() _setup(_Options(methods=methods), finalize=finalize)
def openmdao_cmd(): """ Wrap a number of Problem viewing/debugging command line functions. """ parser = argparse.ArgumentParser( description='OpenMDAO Command Line Tools', epilog='Use -h after any sub-command for sub-command help.') subs = parser.add_subparsers(title='Tools', metavar='') for p, (parser_setup_func, cmd, help_str) in sorted( chain(_post_setup_map.items(), _non_post_setup_map.items())): subp = subs.add_parser(p, help=help_str) parser_setup_func(subp) if p in _post_setup_map: subp.set_defaults(func=cmd, executor=_post_setup_exec) else: subp.set_defaults(executor=cmd) # handle case where someone just runs `openmdao <script>` args = [a for a in sys.argv[1:] if not a.startswith('-')] if not set(args).intersection( subs.choices) and len(args) == 1 and os.path.isfile(args[0]): _post_setup_exec(_Options(file=[args[0]], func=None)) else: options = parser.parse_args() if hasattr(options, 'executor'): options.executor(options) else: print("\nNothing to do.")
def openmdao_cmd(): """ Wrap a number of Problem viewing/debugging command line functions. """ parser = argparse.ArgumentParser() subs = parser.add_subparsers(help='sub-command help') for p, (parser_setup_func, cmd) in iteritems(_post_setup_map): subp = subs.add_parser(p) parser_setup_func(subp) subp.set_defaults(func=cmd, executor=_post_setup_exec) for p, (parser_setup_func, cmd) in iteritems(_iprof_map): subp = subs.add_parser(p) parser_setup_func(subp) subp.set_defaults(executor=cmd) # handle case where someone just runs `openmdao <script>` args = [a for a in sys.argv[1:] if not a.startswith('-')] if not set(args).intersection(subs.choices) and len(args) == 1 and os.path.isfile(args[0]): _post_setup_exec(_Options(file=[args[0]], func=None)) else: options = parser.parse_args() if hasattr(options, 'executor'): options.executor(options) else: print("\nNothing to do.")
def setup(methods=None, verbose=None, memory=None, leaks=False, rank=-1, show_ptrs=False, outfile='stdout'): """ Setup call tracing. Parameters ---------- methods : list of (glob, (classes...)) or None Methods to be traced, based on glob patterns and isinstance checks. verbose : bool If True, show function locals and return values. memory : bool If True, show functions that increase memory usage. leaks : bool If True, show objects that are created within a function and not garbage collected. rank : int MPI rank where output is desired. The default, -1 means output from all ranks. show_ptrs : bool If True, show addresses of printed objects. outfile : file-like or str Output file. """ _setup( _Options(methods=methods, verbose=verbose, memory=memory, leaks=leaks, rank=rank, show_ptrs=show_ptrs, outfile=outfile))
def memtrace(**kwargs): """ Turn on memory tracing within a certain context. Parameters ---------- kwargs : dict Named options to pass to setup. """ options = _Options(**kwargs) if options.outfile is None: options.outfile = 'mem_trace.raw' if options.min_mem is None: options.min_mem = 1.0 if options.stream is None: options.stream = sys.stdout _setup(options) start() try: yield finally: stop() _file_line2qualname(options.outfile) if options.tree: postprocess_memtrace_tree(fname=options.outfile, min_mem=options.min_mem, show_colors=options.show_colors, stream=options.stream) else: postprocess_memtrace_flat(fname=options.outfile, min_mem=options.min_mem, show_colors=options.show_colors, stream=options.stream)
def openmdao_cmd(): """ Wrap a number of Problem viewing/debugging command line functions. """ # pre-parse sys.argv to split between before and after '--' if '--' in sys.argv: idx = sys.argv.index('--') sys_args = sys.argv[:idx] user_args = sys.argv[idx + 1:] sys.argv[:] = sys_args else: user_args = [] parser = argparse.ArgumentParser( description='OpenMDAO Command Line Tools', epilog='Use -h after any sub-command for sub-command help.' ' If using a tool on a script that takes its own command line' ' arguments, place those arguments after a "--". For example:' ' openmdao n2 -o foo.html myscript.py -- -x --myarg=bar') # setting 'dest' here will populate the Namespace with the active subparser name subs = parser.add_subparsers(title='Tools', metavar='', dest="subparser_name") for p, (parser_setup_func, executor, func, help_str) in sorted(_command_map.items()): subp = subs.add_parser(p, help=help_str) parser_setup_func(subp) subp.set_defaults(executor=executor, func=func) # handle case where someone just runs `openmdao <script> [dashed-args]` args = [a for a in sys.argv[1:] if not a.startswith('-')] if not set(args).intersection( subs.choices) and len(args) == 1 and os.path.isfile(args[0]): _simple_exec(_Options(file=[args[0]], func=None), user_args) else: hooks.use_hooks = True # we do a parse_known_args here instead of parse_args so that we can associate errors with # the correct subparser. Otherwise we would just get a top level error message without any # sub-command usage info. options, unknown = parser.parse_known_args() if unknown: msg = 'unrecognized arguments: ' + ', '.join(unknown) try: sub = subs.choices[options.subparser_name] except KeyError: parser.error(msg) else: print(sub.format_usage(), file=sys.stderr) print(msg, file=sys.stderr) parser.exit(2) if hasattr(options, 'executor'): options.executor(options, user_args) else: print("\nNothing to do.")
def setup(**kwargs): """ Setup memory profiling. Parameters ---------- kwargs : dict Keyword options. """ _setup(_Options(**kwargs))
def setup(methods=None): """ Setup memory profiling. Parameters ---------- methods : list of (glob, (classes...)) or None Methods to be profiled, based on glob patterns and isinstance checks. """ if not func_group: _setup_func_group() _setup(_Options(methods=methods))
def setup(methods=None, verbose=None): """ Setup call tracing. Parameters ---------- methods : list of (glob, (classes...)) or None Methods to be traced, based on glob patterns and isinstance checks. verbose : bool If True, show function locals and return values. """ _setup(_Options(methods=methods, verbose=verbose))
def __init__(self, methods=None, verbose=False, memory=False, leaks=False, filters=None, show_ptrs=False): self.options = _Options(methods=methods, verbose=verbose, memory=memory, leaks=leaks, filters=filters, show_ptrs=show_ptrs) self._call_setup = True
def __init__(self, methods=None, verbose=False): self.options = _Options(methods=methods, verbose=verbose) self._call_setup = True
def __init__(self, methods=None, verbose=False, memory=False, leaks=False): self.options = _Options(methods=methods, verbose=verbose, memory=memory, leaks=leaks) self._call_setup = True