Ejemplo n.º 1
0
def nflxprofile_generate_flame_graph(file_path,
                                     range_start,
                                     range_end,
                                     package_name=False,
                                     flavor='standard'):
    try:
        f = get_file(file_path)
        profile = nflxprofile_pb2.Profile()
        profile.ParseFromString(f.read())
    except TypeError:
        abort(500, 'Failed to parse profile.')
    finally:
        f.close()

    stack_processor = FLAVORS.get(flavor, StackProcessor)

    start_time = profile.start_time
    if range_start is not None:
        range_start = (math.floor(start_time) + range_start)
    if range_end is not None:
        range_end = (math.floor(start_time) + range_end)

    return get_flame_graph(profile, {},
                           range_start=range_start,
                           range_end=range_end,
                           package_name=package_name,
                           stack_processor=stack_processor)
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser(
        prog="nflxprofile",
        description=('Parse '
                     'common profile/tracing formats into nflxprofile'))
    parser.add_argument('--output')
    parser.add_argument('--input-format',
                        choices=['v8', 'perf', 'nflxprofile'])
    parser.add_argument('--output-format', choices=['nflxprofile', 'tree'])
    parser.add_argument('--force', action="store_true")
    parser.add_argument('--extra-options', type=json.loads)
    parser.add_argument('input', nargs="+")

    args = parser.parse_args()

    input_format = get_input_format(args.input_format, args.input)
    output_format = get_output_format(args.output_format, args.output)

    validate_input_output(input_format, output_format, args.input)

    if output_format == 'nflxprofile':
        out = args.output
        if not out:
            out = 'profile.nflxprofile'

        filenames = args.input
        extra_options = args.extra_options or {}

        profile = None
        if input_format == 'v8':
            profiles = []
            for filename in filenames:
                with open(filename, 'r') as f:
                    profiles.append(json.loads(f.read()))
            profile = v8_parse(profiles, **extra_options)

        with open(out, 'wb') as f:
            f.write(profile.SerializeToString())

    elif output_format == 'tree':
        out = args.output
        if not out:
            out = 'profile.json'

        filename = args.input[0]
        extra_options = args.extra_options or {}

        extra_options['stack_processor'] = STACK_PROCESSOR[extra_options.get(
            'stack_processor', 'default')]

        tree = {}
        if input_format == 'nflxprofile':
            profile = Profile()
            with open(filename, 'rb') as f:
                profile.ParseFromString(f.read())
            tree = get_flame_graph(profile, {}, **extra_options)

        with open(out, 'w') as f:
            f.write(json.dumps(tree))
Ejemplo n.º 3
0
    def test_nodejs1(self):
        profile = nflxprofile_pb2.Profile()
        with open("test/fixtures/nodejs1.nflxprofile", "rb") as f:
            profile.ParseFromString(f.read())

        expected = None
        with open("test/fixtures/nodejs1.json", "r") as f:
            expected = json.loads(f.read())

        fg = get_flame_graph(profile, None,
                             stack_processor=NodeJsStackProcessor)
        self.assertDictEqual(fg, expected)
Ejemplo n.º 4
0
def nflxprofile_generate_differential_flame_graph(file_path, range_start,
                                                  range_end):
    try:
        f = get_file(file_path)
        profile = nflxprofile_pb2.Profile()
        profile.ParseFromString(f.read())
    except TypeError:
        abort(500, 'Failed to parse profile.')
    finally:
        f.close()

    start_time = profile.start_time
    if range_start is not None:
        range_start = (math.floor(start_time) + range_start)
    if range_end is not None:
        range_end = (math.floor(start_time) + range_end)

    return get_flame_graph(profile, {},
                           range_start=range_start,
                           range_end=range_end)