def _format_size(size):
    """Copied from tracemalloc.py"""
    for unit in ('B', 'KiB', 'MiB', 'GiB', 'TiB'):
        if abs(size) < 100 and unit != 'B':
            return '%.1f %s' % (size, unit)
        if abs(size) < 10 * 1024 or unit == 'TiB':
            return '%.0f %s' % (size, unit)
        size /= 1024
