From: "Alex Bennée" <alex.bennee@linaro.org>
To: Mahmoud Mandour <ma.mandourr@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v3] plugins/syscall: Added a table-like summary output
Date: Wed, 05 May 2021 14:13:53 +0100 [thread overview]
Message-ID: <87fsz1nwqv.fsf@linaro.org> (raw)
In-Reply-To: <20210420115433.12148-1-ma.mandourr@gmail.com>
Mahmoud Mandour <ma.mandourr@gmail.com> writes:
> Added a table-like output which contains the total number of calls
> for each used syscall along with the number of errors that occurred.
>
> Per-call tracing is still available through supplying the argument
> ``print`` to the plugin.
>
> Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
> ---
<snip>
> +
> +void print_entry(gpointer val, gpointer user_data)
> {
> g_autofree gchar *out;
> - out = g_strdup_printf("syscall #%" PRIi64 " returned -> %" PRIi64 "\n",
> - num, ret);
> + SyscallStats *entry = (SyscallStats *) val;
> + int64_t syscall_num = entry->num;
> + out = g_strdup_printf(
> + "%-13" PRIi64 "%-6" PRIi64 " %" PRIi64 "\n",
> + syscall_num, entry->calls, entry->errors);
> qemu_plugin_outs(out);
> }
This still fails to compile due to a missing static:
[2/10] Compiling C object tests/plugin/libsyscall.so.p/syscall.c.o
FAILED: tests/plugin/libsyscall.so.p/syscall.c.o
cc -Itests/plugin/libsyscall.so.p -Itests/plugin -I../../tests/plugin -I../../include/qemu -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -fdiagnostics-color=auto -pipe -Wall -Winvalid-pch -Werror -std=gnu99 -O2 -g -isystem /home/alex/lsrc/qemu.git/linux-headers -isystem linux-headers -iquote . -iquote /home/alex/lsrc/qemu.git -iquote /home/alex/lsrc/qemu.git/include -iquote /home/alex/lsrc/qemu.git/disas/libvixl -iquote /home/alex/lsrc/qemu.git/tcg/i386 -pthread -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined -Wimplicit-fallthrough=2 -Wno-missing-include-dirs -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -DLEGACY_RDMA_REG_MR -fPIC -MD -MQ tests/plugin/libsyscall.so.p/syscall.c.o -MF tests/plugin/libsyscall.so.p/syscall.c.o.d -o tests/plugin/libsyscall.so.p/syscall.c.o -c ../../tests/plugin/syscall.c
../../tests/plugin/syscall.c:80:6: error: no previous prototype for ‘print_entry’ [-Werror=missing-prototypes]
void print_entry(gpointer val, gpointer user_data)
^~~~~~~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
make: *** [Makefile:152: run-ninja] Error 1
>
> +static gint comp_func(gconstpointer ea, gconstpointer eb)
> +{
> + SyscallStats *ent_a = (SyscallStats *) ea;
> + SyscallStats *ent_b = (SyscallStats *) eb;
> +
> + return ent_a->calls > ent_b->calls ? -1 : 1;
> +}
> +
> /* ************************************************************************* */
> +static void plugin_exit(qemu_plugin_id_t id, void *p)
> +{
> + if (!statistics) {
> + return;
> + }
> +
> + g_mutex_lock(&lock);
> + GList *entries = g_hash_table_get_values(statistics);
> + entries = g_list_sort(entries, comp_func);
> + qemu_plugin_outs("syscall no. calls errors\n");
>
> -static void plugin_exit(qemu_plugin_id_t id, void *p) {}
> + g_list_foreach(entries, print_entry, NULL);
> +
> + g_list_free(entries);
> + g_hash_table_destroy(statistics);
> + g_mutex_unlock(&lock);
> +}
Hmm it looks like we see multiple plugin_exit's when running multiple
threads:
./qemu-aarch64 -d plugin -D output -plugin ./tests/plugin/libsyscall.so ./tests/tcg/aarch64-linux-user/linux-test
I don't see it with testthread or the new signals test though which is
confusing. Something linux-test is doing must be different.
>
> QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
> const qemu_info_t *info,
> int argc, char **argv)
> {
> + if (argc == 0) {
> + statistics = g_hash_table_new_full(NULL, g_direct_equal, NULL, g_free);
> + } else {
> + for (int i = 0; i < argc; i++) {
> + if (g_strcmp0(argv[i], "print") != 0) {
> + fprintf(stderr, "unsupported argument: %s\n", argv[i]);
> + return -1;
> + }
> + }
> + }
> +
> qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall);
> qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret);
> qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
Otherwise looking pretty good - certainly a more useful default ;-)
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
--
Alex Bennée
next prev parent reply other threads:[~2021-05-05 13:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-20 11:54 [PATCH v3] plugins/syscall: Added a table-like summary output Mahmoud Mandour
2021-05-05 13:13 ` Alex Bennée [this message]
2021-05-05 17:56 ` Mahmoud Mandour
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fsz1nwqv.fsf@linaro.org \
--to=alex.bennee@linaro.org \
--cc=ma.mandourr@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).