예제 #1
0
def get_profile_type(file_path):
    (f, mime) = get_file(file_path)
    if mime == 'application/octet-stream':
        r = nflxprofile_pb2.Profile()
        r.ParseFromString(f.read())
        f.close()
        return ('nflxprofile', r)
    elif is_perf_file(f):
        f.close()
        return ('perf_script', None)
    else:
        try:
            f.seek(0)
            r = json.load(f)
            f.close()
            if isinstance(r, list):
                if 'ph' in r[0]:
                    return ('trace_event', r)
            elif 'nodes' in r:
                if isinstance(r['nodes'], list):
                    return ('cpuprofile', r)
            raise InvalidFileError('Unknown JSON file.')
        except JSONDecodeError:
            f.close()
            raise InvalidFileError('Unknown file type.')
예제 #2
0
def parse_nodes(nodes):
    profile = nflxprofile_pb2.Profile()
    profile.nodes[0].function_name = 'fakenode'
    profile.nodes[0].hit_count = 0
    for node in nodes:
        node_id = node['id']
        function_name = node['callFrame']['functionName']
        children = node.get('children', None)
        hit_count = node.get('hitCount', 0)
        profile.nodes[node_id].function_name = function_name
        profile.nodes[node_id].hit_count = hit_count
        profile.nodes[node_id].libtype = ''
        if children:
            for child_id in children:
                profile.nodes[node_id].children.append(child_id)
    return profile.nodes
예제 #3
0
def nflxprofile_generate_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:
        adjusted_range_start = (math.floor(start_time) + range_start)
    if range_end is not None:
        adjusted_range_end = (math.floor(start_time) + range_end)

    return generate_flame_graph(profile.nodes, 0, profile.samples, profile.time_deltas, start_time, adjusted_range_start, adjusted_range_end, None)
예제 #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 generate_flame_graph([profile], [0], [None], range_start, range_end)
예제 #5
0
파일: heatmap.py 프로젝트: zuodh/flamescope
def nflxprofile_readoffsets(file_path):
    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()

    offsets = []
    current_time = profile.start_time

    for delta in profile.time_deltas:
        current_time += delta
        offsets.append(current_time)

    res = collections.namedtuple('offsets', ['start', 'end', 'offsets'])(profile.start_time, profile.end_time, offsets)
    return res