Esempio n. 1
0
def analyze():
    arg_parser = argparse.ArgumentParser(description='Analyze log files.')
    arg_parser.add_argument(
        '-o',
        '--output',
        help=
        'Save the results of the analysis to a file that can be read later.')
    arg_parser.add_argument(
        '-r',
        '--report',
        choices=['text', 'json', 'html'],
        help=
        'Generate a report in the requested format and stream it to stdout.')
    arg_parser.add_argument(
        '--threshold-percent',
        type=float,
        default=None,
        help=
        "Don't include entries that accounted for less than this amount of time relative to the total execution"
        " time in the report.")
    group = arg_parser.add_argument_group('Input File')
    group_ex = group.add_mutually_exclusive_group()
    group_ex.add_argument(
        '-l',
        '--log',
        default='edx_analytics.log',
        help=
        'A log file to analyze. Defaults to "edx_analytics.log" in the current directory.'
    )
    group_ex.add_argument('-i',
                          '--input',
                          help='Reads a previously saved result file.')
    group_ex.add_argument(
        '-t',
        '--trace',
        help=
        'Path to an execution trace of the launch-task process captured by pyinstrument and saved as JSON.'
    )

    args = arg_parser.parse_args()

    if args.input:
        root = Measurement.from_json(args.input)
    elif args.trace:
        root = Measurement.from_pyinstrument_trace(args.trace)
    else:
        root = analyze_log_file(args.log)

    if args.output:
        json_report(root,
                    args.output,
                    pretty=False,
                    threshold_percent=args.threshold_percent)

    if args.report == 'json':
        json_report(root, threshold_percent=args.threshold_percent)
    elif args.report == 'text':
        text_report(root, threshold_percent=args.threshold_percent)
    elif args.report == 'html':
        html_report(root, threshold_percent=args.threshold_percent)
Esempio n. 2
0
def analyze():
    arg_parser = argparse.ArgumentParser(description='Analyze log files.')
    arg_parser.add_argument(
        '-o', '--output',
        help='Save the results of the analysis to a file that can be read later.'
    )
    arg_parser.add_argument(
        '-r', '--report',
        choices=['text', 'json', 'html'],
        help='Generate a report in the requested format and stream it to stdout.'
    )
    arg_parser.add_argument(
        '--threshold-percent',
        type=float,
        default=None,
        help="Don't include entries that accounted for less than this amount of time relative to the total execution"
             " time in the report."
    )
    group = arg_parser.add_argument_group('Input File')
    group_ex = group.add_mutually_exclusive_group()
    group_ex.add_argument(
        '-l', '--log',
        default='edx_analytics.log',
        help='A log file to analyze. Defaults to "edx_analytics.log" in the current directory.'
    )
    group_ex.add_argument(
        '-i', '--input',
        help='Reads a previously saved result file.'
    )
    group_ex.add_argument(
        '-t', '--trace',
        help='Path to an execution trace of the launch-task process captured by pyinstrument and saved as JSON.'
    )

    args = arg_parser.parse_args()

    if args.input:
        root = Measurement.from_json(args.input)
    elif args.trace:
        root = Measurement.from_pyinstrument_trace(args.trace)
    else:
        root = analyze_log_file(args.log)

    if args.output:
        json_report(root, args.output, pretty=False, threshold_percent=args.threshold_percent)

    if args.report == 'json':
        json_report(root, threshold_percent=args.threshold_percent)
    elif args.report == 'text':
        text_report(root, threshold_percent=args.threshold_percent)
    elif args.report == 'html':
        html_report(root, threshold_percent=args.threshold_percent)