From 5cc1d55d769e278f51eeb057b08d04afd6bb0c44 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 7 Mar 2021 00:22:40 +0100 Subject: Add a simple benchmark program for the xattr key/value recorder Signed-off-by: David Oberhollenzer --- .gitignore | 1 + tests/libsqfs/Makemodule.am | 5 ++ tests/libsqfs/xattr_benchmark.c | 124 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 tests/libsqfs/xattr_benchmark.c diff --git a/.gitignore b/.gitignore index 3501319..05afa84 100644 --- a/.gitignore +++ b/.gitignore @@ -46,3 +46,4 @@ tests/*.sh /mk42sqfs /list_files /sqfsbrowse +/xattr_benchmark diff --git a/tests/libsqfs/Makemodule.am b/tests/libsqfs/Makemodule.am index 0ad19d9..5ebb94b 100644 --- a/tests/libsqfs/Makemodule.am +++ b/tests/libsqfs/Makemodule.am @@ -7,8 +7,13 @@ test_table_LDADD = libsquashfs.la test_xattr_writer_SOURCES = tests/libsqfs/xattr_writer.c tests/test.h test_xattr_writer_LDADD = libsquashfs.la +xattr_benchmark_SOURCES = tests/libsqfs/xattr_benchmark.c +xattr_benchmark_LDADD = libcommon.a libsquashfs.la libcompat.a + LIBSQFS_TESTS = \ test_abi test_table test_xattr_writer +noinst_PROGRAMS += xattr_benchmark + check_PROGRAMS += $(LIBSQFS_TESTS) TESTS += $(LIBSQFS_TESTS) diff --git a/tests/libsqfs/xattr_benchmark.c b/tests/libsqfs/xattr_benchmark.c new file mode 100644 index 0000000..918a636 --- /dev/null +++ b/tests/libsqfs/xattr_benchmark.c @@ -0,0 +1,124 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* + * xattr_benchmark.c + * + * Copyright (C) 2021 David Oberhollenzer + */ +#include "config.h" +#include "compat.h" +#include "common.h" + +#include "sqfs/xattr_writer.h" +#include "sqfs/xattr.h" + +#include +#include +#include +#include + +static struct option long_opts[] = { + { "block-count", required_argument, NULL, 'b' }, + { "groups-size", required_argument, NULL, 'g' }, + { "version", no_argument, NULL, 'V' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 }, +}; + +static const char *short_opts = "g:b:hV"; + +static const char *help_string = +"Usage: xattr_benchmark [OPTIONS...]\n" +"\n" +"Possible options:\n" +"\n" +" --block-count, -b How many unique xattr blocks to generate.\n" +" --group-size, -g Number of key-value pairs to generate for each\n" +" xattr block.\n" +"\n"; + +int main(int argc, char **argv) +{ + long blkidx, grpidx, block_count = 0, group_size = 0; + sqfs_xattr_writer_t *xwr; + sqfs_u32 id; + int ret; + + for (;;) { + int i = getopt_long(argc, argv, short_opts, long_opts, NULL); + if (i == -1) + break; + + switch (i) { + case 'b': + block_count = strtol(optarg, NULL, 0); + break; + case 'g': + group_size = strtol(optarg, NULL, 0); + break; + case 'h': + fputs(help_string, stdout); + return EXIT_SUCCESS; + case 'V': + print_version("xattr_benchmark"); + return EXIT_SUCCESS; + default: + goto fail_arg; + } + } + + if (block_count <= 0) { + fputs("A block count > 0 must be specified.\n", stderr); + goto fail_arg; + } + + if (group_size <= 0) { + fputs("A group size > 0 must be specified.\n", stderr); + goto fail_arg; + } + + /* setup writer */ + xwr = sqfs_xattr_writer_create(0); + + /* generate blocks */ + for (blkidx = 0; blkidx < block_count; ++blkidx) { + ret = sqfs_xattr_writer_begin(xwr, 0); + if (ret < 0) { + sqfs_perror(NULL, "begin xattr block", ret); + goto fail; + } + + for (grpidx = 0; grpidx < group_size; ++grpidx) { + char key[64], value[64]; + + snprintf(key, sizeof(key), "user.group%ld.key%ld", + blkidx, grpidx); + + snprintf(value, sizeof(value), "group%ld/value%ld", + blkidx, grpidx); + + ret = sqfs_xattr_writer_add(xwr, key, value, + strlen(value)); + + if (ret < 0) { + sqfs_perror(NULL, "add to xattr block", ret); + goto fail; + } + } + + ret = sqfs_xattr_writer_end(xwr, &id); + if (ret < 0) { + sqfs_perror(NULL, "end xattr block", ret); + goto fail; + } + } + + /* cleanup */ + sqfs_destroy(xwr); + return EXIT_SUCCESS; +fail: + sqfs_destroy(xwr); + return EXIT_FAILURE; +fail_arg: + fputs("Try `xattr_benchmark --help' for more information.\n", stderr); + return EXIT_FAILURE; +} -- cgit v1.2.3