Beispiel #1
0
def _itrace_setup_parser(parser):
    """
    Set up the command line options for the 'openmdao trace' command line tool.
    """
    if not func_group:
        _setup_func_group()

    parser.add_argument('file', nargs=1, help='Python file to be traced.')
    parser.add_argument('-g', '--group', action='store', dest='methods',
                        default='openmdao',
                        help='Determines which group of methods will be traced. Default is "openmdao".'
                              ' Options are: %s' % sorted(func_group.keys()))
    parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
                        help="Show function locals and return values.")
    parser.add_argument('--ptrs', action='store_true', dest='show_ptrs',
                        help="Show addresses of printed objects.")
    parser.add_argument('-m', '--memory', action='store_true', dest='memory',
                        help="Show memory usage.")
    parser.add_argument('-l', '--leaks', action='store_true', dest='leaks',
                        help="Show objects that are not garbage collected after each function call.")
    parser.add_argument('-r', '--rank', action='store', dest='rank', type=int,
                        default=-1, help='MPI rank where output is desired.  Default is all ranks.')
    parser.add_argument('-o', '--outfile', action='store', dest='outfile',
                        default='stdout', help='Output file.  Defaults to stdout.')
    parser.add_argument('-f', '--filter', action='append', dest='filters',
                        default=[],
                        help='An expression.  If it evaluates to True for any matching trace '
                             'function, that function will be displayed in the trace. One '
                             'expression can be added for each class.')
Beispiel #2
0
def _mem_prof_setup_parser(parser):
    if not func_group:
        _setup_func_group()

    parser.add_argument('-g', '--group', action='store', dest='methods',
                        default='openmdao_all',
                        help='Determines which group of methods will be tracked. Options are %s' %
                             sorted(func_group.keys()))
    parser.add_argument('file', metavar='file', nargs=1,
                        help='Python file to profile.')
def _itrace_setup_parser(parser):
    if not func_group:
        _setup_func_group()

    parser.add_argument('file', nargs=1, help='Python file to be traced.')
    parser.add_argument('-g', '--group', action='store', dest='methods',
                        default='openmdao',
                        help='Determines which group of methods will be traced. Default is "openmdao".'
                              ' Options are: %s' % sorted(func_group.keys()))
    parser.add_argument('-v', '--verbose', action='store_true', dest='verbose',
                        help="Show function locals and return values.")
Beispiel #4
0
def _itrace_setup_parser(parser):
    """
    Set up the command line options for the 'openmdao trace' command line tool.
    """
    if not func_group:
        _setup_func_group()

    parser.add_argument('file', nargs=1, help='Python file to be traced.')
    parser.add_argument(
        '-g',
        '--group',
        action='store',
        dest='methods',
        default='openmdao',
        help=
        'Determines which group of methods will be traced. Default is "openmdao".'
        ' Options are: %s' % sorted(func_group.keys()))
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        dest='verbose',
                        help="Show function locals and return values.")
    parser.add_argument('-m',
                        '--memory',
                        action='store_true',
                        dest='memory',
                        help="Show memory usage.")
    parser.add_argument(
        '-l',
        '--leaks',
        action='store_true',
        dest='leaks',
        help=
        "Show objects that are not garbage collected after each function call."
    )
    parser.add_argument(
        '-r',
        '--rank',
        action='store',
        dest='rank',
        type=int,
        default=-1,
        help='MPI rank where output is desired.  Default is all ranks.')
    parser.add_argument('-o',
                        '--outfile',
                        action='store',
                        dest='outfile',
                        default='stdout',
                        help='Output file.  Defaults to stdout.')
Beispiel #5
0
def _mem_prof_setup_parser(parser):
    if not func_group:
        _setup_func_group()

    parser.add_argument(
        '-g',
        '--group',
        action='store',
        dest='methods',
        default='openmdao_all',
        help='Determines which group of methods will be tracked. Options are %s'
        % sorted(func_group.keys()))
    parser.add_argument('file',
                        metavar='file',
                        nargs=1,
                        help='Python file to profile.')
Beispiel #6
0
def _trace_py_file():
    """
    Process command line args and perform tracing on a specified python file.
    """
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-g',
        '--group',
        action='store',
        dest='group',
        default='openmdao',
        help=
        'Determines which group of methods will be tracked. Default is "openmdao".'
        ' Options are: %s' % sorted(func_group.keys()))
    parser.add_argument('-v',
                        '--verbose',
                        action='store_true',
                        dest='verbose',
                        help="Show function locals and return values.")
    parser.add_argument('file',
                        metavar='file',
                        nargs=1,
                        help='Python file to profile.')

    options = parser.parse_args()

    progname = options.file[0]
    sys.path.insert(0, os.path.dirname(progname))

    setup(methods=func_group[options.group], verbose=options.verbose)
    with open(progname, 'rb') as fp:
        code = compile(fp.read(), progname, 'exec')

    globals_dict = {
        '__file__': progname,
        '__name__': '__main__',
        '__package__': None,
        '__cached__': None,
    }

    start()

    exec(code, globals_dict)
Beispiel #7
0
def _iprof_setup_parser(parser):
    if not func_group:
        _setup_func_group()

    parser.add_argument('-p',
                        '--port',
                        action='store',
                        dest='port',
                        default=8009,
                        type=int,
                        help='port used for web server')
    parser.add_argument('--no_browser',
                        action='store_true',
                        dest='noshow',
                        help="Don't pop up a browser to view the data.")
    parser.add_argument('-t',
                        '--title',
                        action='store',
                        dest='title',
                        default='Profile of Method Calls by Instance',
                        help='Title to be displayed above profiling view.')
    parser.add_argument(
        '-g',
        '--group',
        action='store',
        dest='methods',
        default='openmdao',
        help='Determines which group of methods will be tracked. Current '
        'options are: %s and "openmdao" is the default' %
        sorted(func_group.keys()))
    parser.add_argument(
        '-m',
        '--maxcalls',
        action='store',
        dest='maxcalls',
        default=15000,
        type=int,
        help='Maximum number of calls displayed at one time.  Default=15000.')
    parser.add_argument('file',
                        metavar='file',
                        nargs='+',
                        help='Raw profile data files or a python file.')
Beispiel #8
0
def _iprof_setup_parser(parser):
    if not func_group:
        _setup_func_group()

    parser.add_argument('-p', '--port', action='store', dest='port',
                        default=8009, type=int,
                        help='port used for web server')
    parser.add_argument('--no_browser', action='store_true', dest='noshow',
                        help="Don't pop up a browser to view the data.")
    parser.add_argument('-t', '--title', action='store', dest='title',
                        default='Profile of Method Calls by Instance',
                        help='Title to be displayed above profiling view.')
    parser.add_argument('-g', '--group', action='store', dest='methods',
                        default='openmdao',
                        help='Determines which group of methods will be tracked. Current '
                             'options are: %s and "openmdao" is the default' %
                              sorted(func_group.keys()))
    parser.add_argument('-m', '--maxcalls', action='store', dest='maxcalls',
                        default=15000, type=int,
                        help='Maximum number of calls displayed at one time.  Default=15000.')
    parser.add_argument('file', metavar='file', nargs='+',
                        help='Raw profile data files or a python file.')
Beispiel #9
0
def _prof_view():
    """
    Called from a command line to instance based profile data in a web page.
    """

    parser = argparse.ArgumentParser()
    parser.add_argument('-p',
                        '--port',
                        action='store',
                        dest='port',
                        default=8009,
                        type=int,
                        help='port used for web server')
    parser.add_argument('--noshow',
                        action='store_true',
                        dest='noshow',
                        help="Don't pop up a browser to view the data.")
    parser.add_argument('-t',
                        '--title',
                        action='store',
                        dest='title',
                        default='Profile of Method Calls by Instance',
                        help='Title to be displayed above profiling view.')
    parser.add_argument(
        '-g',
        '--group',
        action='store',
        dest='group',
        default='openmdao',
        help='Determines which group of methods will be tracked. Current '
        'options are: %s and "openmdao" is the default' %
        sorted(func_group.keys()))
    parser.add_argument(
        '-m',
        '--maxcalls',
        action='store',
        dest='maxcalls',
        default=15000,
        type=int,
        help='Maximum number of calls displayed at one time.  Default=15000.')
    parser.add_argument('files',
                        metavar='file',
                        nargs='+',
                        help='Raw profile data files or a python file.')

    options = parser.parse_args()

    if options.files[0].endswith('.py'):
        if len(options.files) > 1:
            print("iprofview can only process a single python file.",
                  file=sys.stderr)
            sys.exit(-1)
        _profile_py_file(options.files[0], methods=func_group[options.group])
        options.files = ['iprof.0']

    app = _Application(options)
    app.listen(options.port)

    print("starting server on port %d" % options.port)

    serve_thread = _startThread(tornado.ioloop.IOLoop.current().start)
    launch_thread = _startThread(lambda: _launch_browser(options.port))

    while serve_thread.isAlive():
        serve_thread.join(timeout=1)