コード例 #1
0
ファイル: __main__.py プロジェクト: johnconnelly75/vprof
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(description=_MODULE_DESC)
    parser.add_argument('profilers', metavar='opts',
                        help='Profilers configuration')
    parser.add_argument('source', metavar='src', nargs=1,
                        help='Python program to profile.')
    parser.add_argument('--port', dest='port', default=8000, type=int,
                        help='Internal webserver port.')
    args = parser.parse_args()

    if len(args.profilers) > len(set(args.profilers)):
        print('Profiler configuration is ambiguous. Remove duplicates.')
        sys.exit(1)

    for option in args.profilers:
        if option not in _PROFILE_MAP:
            print('Unrecognized option: %s' % option)
            sys.exit(2)

    sys.argv[:] = args.source
    program_name, program_stats = args.source[0], OrderedDict()
    for option in args.profilers:
        curr_profiler = _PROFILE_MAP[option](program_name)
        print('Running %s...' % curr_profiler.__class__.__name__)
        program_stats[option] = curr_profiler.run()
    sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(_HOST, args.port, program_stats)
コード例 #2
0
ファイル: __main__.py プロジェクト: jorisvandenbossche/vprof
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(description=_MODULE_DESC)
    parser.add_argument('profilers', metavar='opts',
                        help='Profilers configuration')
    parser.add_argument('source', metavar='src', nargs=1,
                        help='Python program to profile')
    parser.add_argument('--port', dest='port', default=8000, type=int,
                        help='Internal webserver port')
    parser.add_argument('--debug', dest='debug_mode',
                        action='store_true', default=False,
                        help="Don't suppress error messages")
    args = parser.parse_args()

    if len(args.profilers) > len(set(args.profilers)):
        print('Profiler configuration is ambiguous. Remove duplicates.')
        sys.exit(1)

    for option in args.profilers:
        if option not in _PROFILE_MAP:
            print('Unrecognized option: %s' % option)
            sys.exit(2)

    sys.argv[:] = args.source
    program_name, program_stats = args.source[0], OrderedDict()
    for option in args.profilers:
        curr_profiler = _PROFILE_MAP[option](program_name)
        print('Running %s...' % curr_profiler.__class__.__name__)
        program_stats[option] = curr_profiler.run()
    if not args.debug_mode:
        sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(_HOST, args.port, program_stats)
コード例 #3
0
ファイル: __main__.py プロジェクト: durden/vprof
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(
        prog=_PROGRAN_NAME, description=_MODULE_DESC,
        formatter_class=argparse.RawTextHelpFormatter)
    exclusive_group = parser.add_mutually_exclusive_group(required=True)
    exclusive_group.add_argument('-r', '--remote', dest='remote',
                                 action='store_true', default=False,
                                 help='launch in remote mode')
    exclusive_group.add_argument('-s', '--source', metavar='src', nargs=1,
                                 help='Python module or package to profile')
    parser.add_argument('-c', '--config', metavar='options',
                        help=_MODES_DESC)
    parser.add_argument('-H', '--host', dest='host', default=_HOST, type=str,
                        help='set internal webserver host')
    parser.add_argument('-p', '--port', dest='port', default=_PORT, type=int,
                        help='set internal webserver port')
    parser.add_argument('-n', '--no-browser', dest='dont_start_browser',
                        action='store_true', default=False,
                        help="don't start browser automatically")
    parser.add_argument('--debug', dest='debug_mode',
                        action='store_true', default=False,
                        help="don't suppress error messages")
    parser.add_argument('--version', action='version',
                        version='vprof %s' % __version__)
    (args, leftover_args) = parser.parse_known_args()

    # Override sys.argv so the command being profiled can grab its' own args if
    # necessary
    sys.argv[:] = leftover_args

    if args.config and args.remote:
        print(_ERROR_MSG['config error']['msg'])
        sys.exit(_ERROR_MSG['config error']['code'])

    if not args.config and not args.remote:
        print(_ERROR_MSG['no config']['msg'])
        sys.exit(_ERROR_MSG['no config']['code'])

    program_stats = {}
    if not args.remote:
        try:
            program_stats = profiler.run_profilers(  # pylint: disable=redefined-variable-type
                args.source[0], args.config, verbose=True)
        except profiler.AmbiguousConfigurationError:
            print(_ERROR_MSG['ambiguous configuration']['msg'])
            sys.exit(_ERROR_MSG['ambiguous configuration']['code'])
        except profiler.BadOptionError as exc:
            print(exc)
            sys.exit(_ERROR_MSG['bad option']['code'])

    if not args.debug_mode:
        sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(
        args.host, args.port, program_stats, args.dont_start_browser)
コード例 #4
0
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(prog=_PROGRAN_NAME,
                                     description=_MODULE_DESC)
    parser.add_argument('profilers',
                        metavar='options',
                        help='profiler configuration')
    parser.add_argument('source',
                        metavar='src',
                        nargs=1,
                        help='Python module to profile')
    parser.add_argument('--port',
                        dest='port',
                        default=8000,
                        type=int,
                        help='set internal webserver port')
    parser.add_argument('--debug',
                        dest='debug_mode',
                        action='store_true',
                        default=False,
                        help="don't suppress error messages")
    parser.add_argument('-n',
                        '--no-browser',
                        dest='dont_start_browser',
                        action='store_true',
                        default=False,
                        help="don't start browser after profiling")
    args = parser.parse_args()

    if len(args.profilers) > len(set(args.profilers)):
        print('Profiler configuration is ambiguous. Remove duplicates.')
        sys.exit(1)

    available_profilers = {opt for opt, _ in _PROFILERS}
    for option in args.profilers:
        if option not in available_profilers:
            print('Unrecognized option: %s' % option)
            sys.exit(2)

    sys.argv[:] = args.source
    program_name, program_stats = args.source[0], OrderedDict()
    present_profilers = ((s, p) for s, p in _PROFILERS if s in args.profilers)
    for option, profiler in present_profilers:
        curr_profiler = profiler(program_name)
        print('Running %s...' % curr_profiler.__class__.__name__)
        program_stats[option] = curr_profiler.run()
    if not args.debug_mode:
        sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(_HOST, args.port, program_stats,
                       args.dont_start_browser)
コード例 #5
0
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(
        prog=_PROGRAN_NAME, description=_MODULE_DESC,
        formatter_class=argparse.RawTextHelpFormatter)
    exclusive_group = parser.add_mutually_exclusive_group(required=True)
    exclusive_group.add_argument('-r', '--remote', dest='remote',
                                 action='store_true', default=False,
                                 help='launch in remote mode')
    exclusive_group.add_argument('-s', '--source', metavar='src', nargs=1,
                                 help='Python module or package to profile')
    parser.add_argument('-c', '--config', metavar='options',
                        help=_MODES_DESC)
    parser.add_argument('-p', '--port', dest='port', default=8000, type=int,
                        help='set internal webserver port')
    parser.add_argument('-n', '--no-browser', dest='dont_start_browser',
                        action='store_true', default=False,
                        help="don't start browser automatically")
    parser.add_argument('--debug', dest='debug_mode',
                        action='store_true', default=False,
                        help="don't suppress error messages")
    args = parser.parse_args()

    if args.config and args.remote:
        print(_ERROR_MSG['config error']['msg'])
        sys.exit(_ERROR_MSG['config error']['code'])

    if not args.config and not args.remote:
        print(_ERROR_MSG['no config']['msg'])
        sys.exit(_ERROR_MSG['no config']['code'])

    program_stats = {}
    if not args.remote:
        try:
            program_stats = profiler.run_profilers(  # pylint: disable=redefined-variable-type
                args.source[0], args.config, verbose=True)
        except profiler.AmbiguousConfigurationError:
            print(_ERROR_MSG['ambiguous configuration']['msg'])
            sys.exit(_ERROR_MSG['ambiguous configuration']['code'])
        except profiler.BadOptionError as exc:
            print(exc)
            sys.exit(_ERROR_MSG['bad option']['code'])
        except base_profile.ProfilerRuntimeException as exc:
            print(exc)
            sys.exit(_ERROR_MSG['runtime error']['code'])

    if not args.debug_mode:
        sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(
        _HOST, args.port, program_stats, args.dont_start_browser)
コード例 #6
0
ファイル: __main__.py プロジェクト: adrianhust/vprof
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(
        prog=_PROGRAN_NAME, description=_MODULE_DESC)
    parser.add_argument('profilers', metavar='options',
                        help='profiler configuration')
    parser.add_argument('source', metavar='src', nargs=1,
                        help='Python module to profile')
    parser.add_argument('--port', dest='port', default=8000, type=int,
                        help='set internal webserver port')
    parser.add_argument('--debug', dest='debug_mode',
                        action='store_true', default=False,
                        help="don't suppress error messages")
    parser.add_argument('-n', '--no-browser', dest='dont_start_browser',
                        action='store_true', default=False,
                        help="don't start browser after profiling")
    args = parser.parse_args()

    if len(args.profilers) > len(set(args.profilers)):
        print('Profiler configuration is ambiguous. Remove duplicates.')
        sys.exit(1)

    available_profilers = {opt for opt, _ in _PROFILERS}
    for option in args.profilers:
        if option not in available_profilers:
            print('Unrecognized option: %s' % option)
            sys.exit(2)

    sys.argv[:] = args.source
    program_name, program_stats = args.source[0], OrderedDict()
    present_profilers = ((s, p) for s, p in _PROFILERS if s in args.profilers)
    for option, profiler in present_profilers:
        curr_profiler = profiler(program_name)
        print('Running %s...' % curr_profiler.__class__.__name__)
        program_stats[option] = curr_profiler.run()
    if not args.debug_mode:
        sys.stderr = open(os.devnull, "w")
    print('Starting HTTP server...')
    stats_server.start(
        _HOST, args.port, program_stats, args.dont_start_browser)
コード例 #7
0
ファイル: __main__.py プロジェクト: tkelman/vprof
def main():
    """Main function of the module."""
    parser = argparse.ArgumentParser(
        prog=_PROGRAN_NAME,
        description=_MODULE_DESC,
        formatter_class=argparse.RawTextHelpFormatter)
    launch_modes = parser.add_mutually_exclusive_group(required=True)
    launch_modes.add_argument('-r',
                              '--remote',
                              dest='remote',
                              action='store_true',
                              default=False,
                              help='launch in remote mode')
    launch_modes.add_argument('-i',
                              '--input-file',
                              dest='input_file',
                              type=str,
                              default='',
                              help='render UI from file')
    launch_modes.add_argument('-c',
                              '--config',
                              nargs=2,
                              dest='config',
                              help=_CONFIG_DESC,
                              metavar=('CONFIG', 'SRC'))
    parser.add_argument('-H',
                        '--host',
                        dest='host',
                        default=_HOST,
                        type=str,
                        help='set internal webserver host')
    parser.add_argument('-p',
                        '--port',
                        dest='port',
                        default=_PORT,
                        type=int,
                        help='set internal webserver port')
    parser.add_argument('-n',
                        '--no-browser',
                        dest='dont_start_browser',
                        action='store_true',
                        default=False,
                        help="don't start browser automatically")
    parser.add_argument('-o',
                        '--output-file',
                        dest='output_file',
                        type=str,
                        default='',
                        help='save profile to file')
    parser.add_argument('--debug',
                        dest='debug_mode',
                        action='store_true',
                        default=False,
                        help="don't suppress error messages")
    parser.add_argument('--version',
                        action='version',
                        version='vprof %s' % __version__)
    args = parser.parse_args()

    # Render UI from file.
    if args.input_file:
        with open(args.input_file) as ifile:
            saved_stats = json.loads(ifile.read())
            if saved_stats['version'] != __version__:
                print('Incorrect profiler version - %s. %s is required.' %
                      (saved_stats['version'], __version__))
                sys.exit(_ERR_CODES['input_file_error'])
            stats_server.start(args.host, args.port, saved_stats,
                               args.dont_start_browser, args.debug_mode)
    # Launch in remote mode.
    elif args.remote:
        stats_server.start(args.host, args.port, {}, args.dont_start_browser,
                           args.debug_mode)
    # Profiler mode.
    else:
        config, source = args.config
        try:
            program_stats = runner.run_profilers(source, config, verbose=True)
        except runner.AmbiguousConfigurationError:
            print('Profiler configuration %s is ambiguous. '
                  'Please, remove duplicates.' % config)
            sys.exit(_ERR_CODES['ambiguous_configuration'])
        except runner.BadOptionError as exc:
            print(exc)
            sys.exit(_ERR_CODES['bad_option'])

        if args.output_file:
            with open(args.output_file, 'w') as outfile:
                program_stats['version'] = __version__
                outfile.write(json.dumps(program_stats, indent=2))
        else:
            stats_server.start(args.host, args.port, program_stats,
                               args.dont_start_browser, args.debug_mode)
コード例 #8
0
ファイル: __main__.py プロジェクト: rlugojr/vprof
def main():
    """Visual profiler main function."""
    parser = argparse.ArgumentParser(
        prog=_PROGRAN_NAME, description=_MODULE_DESC,
        formatter_class=argparse.RawTextHelpFormatter)
    launch_modes = parser.add_mutually_exclusive_group(required=True)
    launch_modes.add_argument('-r', '--remote', dest='remote',
                              action='store_true', default=False,
                              help='launch in remote mode')
    launch_modes.add_argument('-i', '--input-file', dest='input_file',
                              type=str, default='',
                              help='render visualization from file')
    launch_modes.add_argument('-c', '--config', nargs=2, dest='config',
                              help=_CONFIG_DESC, metavar=('CONFIG', 'SRC'))
    parser.add_argument('-H', '--host', dest='host', default=_HOST, type=str,
                        help='set internal webserver host')
    parser.add_argument('-p', '--port', dest='port', default=_PORT, type=int,
                        help='set internal webserver port')
    parser.add_argument('-n', '--no-browser', dest='dont_start_browser',
                        action='store_true', default=False,
                        help="don't start browser automatically")
    parser.add_argument('-o', '--output-file', dest='output_file',
                        type=str, default='', help='save profile to file')
    parser.add_argument('--debug', dest='debug_mode',
                        action='store_true', default=False,
                        help="don't suppress error messages")
    parser.add_argument('--version', action='version',
                        version='vprof %s' % __version__)
    args = parser.parse_args()

    # Render visualizations from saved file.
    if args.input_file:
        with open(args.input_file) as ifile:
            saved_stats = json.loads(ifile.read())
            if saved_stats['version'] != __version__:
                print('Incorrect profile version - %s. %s is required.' % (
                    saved_stats['version'], __version__))
                sys.exit(_ERR_CODES['input_file_error'])
            stats_server.start(args.host, args.port, saved_stats,
                               args.dont_start_browser, args.debug_mode)
    # Start in remote mode.
    elif args.remote:
        stats_server.start(args.host, args.port, {},
                           args.dont_start_browser, args.debug_mode)
    # Profiler mode.
    else:
        config, source = args.config
        try:
            program_stats = runner.run_profilers(  # pylint: disable=redefined-variable-type
                source, config, verbose=True)
        except runner.AmbiguousConfigurationError:
            print('Profiler configuration %s is ambiguous. '
                  'Please, remove duplicates.' % config)
            sys.exit(_ERR_CODES['ambiguous_configuration'])
        except runner.BadOptionError as exc:
            print(exc)
            sys.exit(_ERR_CODES['bad_option'])

        if args.output_file:
            with open(args.output_file, 'w') as outfile:
                program_stats['version'] = __version__
                outfile.write(json.dumps(program_stats, indent=2))
        else:
            stats_server.start(
                args.host, args.port, program_stats,
                args.dont_start_browser, args.debug_mode)