def to_flamegraph(stacks, counts):
    """ Convert the stack dumps and sample counts into the flamegraph format.

    Return a list of lines.
    """
    lines = []
    for id in counts:
        stack = ';'.join(reversed(stacks[id]))
        count = counts[id]
        lines.append('{0} {1}'.format(stack, count))
    return lines
