示例#1
0

# You may set the following five variables to correct values, to turn this
# example to real benchmark.
ssd_source = '/path-to-raw-source-image-at-ssd'
ssd_target = '/path-to-raw-target-image-at-ssd'
hdd_target = '/path-to-raw-source-image-at-hdd'
nbd_ip = 'nbd-ip-addr'
nbd_port = 'nbd-port-number'

# Test-cases are "rows" in benchmark resulting table, 'id' is a caption for
# the row, other fields are handled by bench_func.
test_cases = [
    {
        'id': 'ssd -> ssd',
        'source': drv_file(ssd_source),
        'target': drv_file(ssd_target)
    },
    {
        'id': 'ssd -> hdd',
        'source': drv_file(ssd_source),
        'target': drv_file(hdd_target)
    },
    {
        'id': 'ssd -> nbd',
        'source': drv_file(ssd_source),
        'target': drv_nbd(nbd_ip, nbd_port)
    },
]

# Test-envs are "columns" in benchmark resulting table, 'id is a caption for
示例#2
0
def bench(args):
    test_cases = []

    sources = {}
    targets = {}
    for d in args.dir:
        label, path = d.split(':')  # paths with colon not supported
        sources[label] = drv_file(path + '/test-source')
        targets[label] = drv_file(path + '/test-target')

    if args.nbd:
        nbd = args.nbd.split(':')
        host = nbd[0]
        port = '10809' if len(nbd) == 1 else nbd[1]
        drv = drv_nbd(host, port)
        sources['nbd'] = drv
        targets['nbd'] = drv

    for t in args.test:
        src, dst = t.split(':')

        test_cases.append({
            'id': t,
            'source': sources[src],
            'target': targets[dst]
        })

    binaries = []  # list of (<label>, <path>, [<options>])
    for i, q in enumerate(args.env):
        name_path = q.split(':')
        if len(name_path) == 1:
            label = f'q{i}'
            path_opts = name_path[0].split(',')
        else:
            assert len(name_path) == 2  # paths with colon not supported
            label = name_path[0]
            path_opts = name_path[1].split(',')

        binaries.append((label, path_opts[0], path_opts[1:]))

    test_envs = []

    bin_paths = {}
    for i, q in enumerate(args.env):
        opts = q.split(',')
        label_path = opts[0]
        opts = opts[1:]

        if ':' in label_path:
            # path with colon inside is not supported
            label, path = label_path.split(':')
            bin_paths[label] = path
        elif label_path in bin_paths:
            label = label_path
            path = bin_paths[label]
        else:
            path = label_path
            label = f'q{i}'
            bin_paths[label] = path

        x_perf = {}
        is_mirror = False
        for opt in opts:
            if opt == 'mirror':
                is_mirror = True
            elif opt == 'copy-range=on':
                x_perf['use-copy-range'] = True
            elif opt == 'copy-range=off':
                x_perf['use-copy-range'] = False
            elif opt.startswith('max-workers='):
                x_perf['max-workers'] = int(opt.split('=')[1])

        if is_mirror:
            assert not x_perf
            test_envs.append({
                'id': f'mirror({label})',
                'cmd': 'blockdev-mirror',
                'qemu-binary': path
            })
        else:
            test_envs.append({
                'id': f'backup({label})\n' + '\n'.join(opts),
                'cmd': 'blockdev-backup',
                'cmd-options': {
                    'x-perf': x_perf
                } if x_perf else {},
                'qemu-binary': path
            })

    result = simplebench.bench(bench_func, test_envs, test_cases, count=3)
    with open('results.json', 'w') as f:
        json.dump(result, f, indent=4)
    print(results_to_text(result))
示例#3
0
def bench(args):
    test_cases = []

    # paths with colon not supported, so we just split by ':'
    dirs = dict(d.split(':') for d in args.dir)

    nbd_drv = None
    if args.nbd:
        nbd = args.nbd.split(':')
        host = nbd[0]
        port = '10809' if len(nbd) == 1 else nbd[1]
        nbd_drv = drv_nbd(host, port)

    for t in args.test:
        src, dst = t.split(':')

        if src == 'nbd' and dst == 'nbd':
            raise ValueError("Can't use 'nbd' label for both src and dst")

        if (src == 'nbd' or dst == 'nbd') and not nbd_drv:
            raise ValueError("'nbd' label used but --nbd is not given")

        if src == 'nbd':
            source = nbd_drv
        elif args.qcow2_sources:
            source = drv_qcow2(drv_file(dirs[src] + '/test-source.qcow2'))
        else:
            source = drv_file(dirs[src] + '/test-source')

        if dst == 'nbd':
            test_cases.append({'id': t, 'source': source, 'target': nbd_drv})
            continue

        if args.target_cache == 'both':
            target_caches = ['direct', 'cached']
        else:
            target_caches = [args.target_cache]

        for c in target_caches:
            o_direct = c == 'direct'
            fname = dirs[dst] + '/test-target'
            if args.compressed:
                fname += '.qcow2'
            target = drv_file(fname, o_direct=o_direct)
            if args.compressed:
                target = drv_qcow2(target)

            test_id = t
            if args.target_cache == 'both':
                test_id += f'({c})'

            test_cases.append({
                'id': test_id,
                'source': source,
                'target': target
            })

    binaries = []  # list of (<label>, <path>, [<options>])
    for i, q in enumerate(args.env):
        name_path = q.split(':')
        if len(name_path) == 1:
            label = f'q{i}'
            path_opts = name_path[0].split(',')
        else:
            assert len(name_path) == 2  # paths with colon not supported
            label = name_path[0]
            path_opts = name_path[1].split(',')

        binaries.append((label, path_opts[0], path_opts[1:]))

    test_envs = []

    bin_paths = {}
    for i, q in enumerate(args.env):
        opts = q.split(',')
        label_path = opts[0]
        opts = opts[1:]

        if ':' in label_path:
            # path with colon inside is not supported
            label, path = label_path.split(':')
            bin_paths[label] = path
        elif label_path in bin_paths:
            label = label_path
            path = bin_paths[label]
        else:
            path = label_path
            label = f'q{i}'
            bin_paths[label] = path

        x_perf = {}
        is_mirror = False
        for opt in opts:
            if opt == 'mirror':
                is_mirror = True
            elif opt == 'copy-range=on':
                x_perf['use-copy-range'] = True
            elif opt == 'copy-range=off':
                x_perf['use-copy-range'] = False
            elif opt.startswith('max-workers='):
                x_perf['max-workers'] = int(opt.split('=')[1])

        backup_options = {}
        if x_perf:
            backup_options['x-perf'] = x_perf

        if args.compressed:
            backup_options['compress'] = True

        if is_mirror:
            assert not x_perf
            test_envs.append({
                'id': f'mirror({label})',
                'cmd': 'blockdev-mirror',
                'qemu-binary': path
            })
        else:
            test_envs.append({
                'id': f'backup({label})\n' + '\n'.join(opts),
                'cmd': 'blockdev-backup',
                'cmd-options': backup_options,
                'qemu-binary': path
            })

    result = simplebench.bench(bench_func,
                               test_envs,
                               test_cases,
                               count=args.count,
                               initial_run=args.initial_run,
                               drop_caches=args.drop_caches)
    with open('results.json', 'w') as f:
        json.dump(result, f, indent=4)
    print(results_to_text(result))