From nobody Mon Feb 9 22:20:05 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1621532709; cv=none; d=zohomail.com; s=zohoarc; b=OITaqL/uYXXFypEOkFHshlDPOJPFFZKvwfI4eWXEeH76DyJjaYUhR/Ar8eIyfVvb0uBsR9RD0ECSEki/l4dXl/v/RX5kzOWu5wTTdAcSV+j+ZTOQT67J+ZwvXH83mvgWHg3lBR+QoiE3h38UEQAMCBl74oVXYEEvWLXIzlXF/ow= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621532709; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AMEc95i31AY77+bT+r3OtP0SO6eeuibPTNGNNWAs+D0=; b=YFscLC7S6v6VZNi+toMPxS9xosYeyn38D8YGvn5HuJxquoV6g6k++b/ZnOCA5bMpNIglb2Oi930Q54SHQHuK5Lhec1OZ9TnqukSMTd0DlXISGHcMQGOyJ9yg9BcDHkLaj9zbge6GBz2ysHofi2t5bvDCCNvj8B5ClBDU6KbkNbc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162153270966297.16087176323174; Thu, 20 May 2021 10:45:09 -0700 (PDT) Received: from localhost ([::1]:47154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmjM-0006Gz-KL for importer@patchew.org; Thu, 20 May 2021 13:45:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmha-0003Ya-Rj for qemu-devel@nongnu.org; Thu, 20 May 2021 13:43:18 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]:33548) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljmhZ-0001Ay-0C for qemu-devel@nongnu.org; Thu, 20 May 2021 13:43:18 -0400 Received: by mail-wr1-x435.google.com with SMTP id n2so18597822wrm.0 for ; Thu, 20 May 2021 10:43:16 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id e26sm3281333wmh.39.2021.05.20.10.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 May 2021 10:43:07 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C19461FF96; Thu, 20 May 2021 18:43:04 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AMEc95i31AY77+bT+r3OtP0SO6eeuibPTNGNNWAs+D0=; b=bKXtC5cLcTmq1F9vbjI+y9SXz2J16eIUOO009GcodDmX1BeY9Zp856KHOIzpHtJJC3 NqBKRh4XEWYx9mJqELAGBt8QlOyux4w+SkCvUIp/mwwKbC2yatIuJG7EKS0k6nk8qh2h yKCNhxNFoaijlp/ahqSUr5+vVIn29liFUb9di1C5ukrfRNxrSpTNNjA1RTNpyYJS8iCf 5sAh55I6nVx86iGc8RlIfkvdFEdU53Z4S8c3TtLPvwWTXhauYTvz+HofM8+euYQFLBW+ vykQnVOQxeqE1C3DBLgqLwGGE3hPGWa+94hdAxhD8jWqgErhXmG4bvzUgaTN+5StWUlS mYCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AMEc95i31AY77+bT+r3OtP0SO6eeuibPTNGNNWAs+D0=; b=Cd4TAQUaZk6c1I8tw+Ic9c2X9d9TvCiu7hsu5bRRzFhi4yLDY98kac3dWz1VC9m/bv AD/CuAqQnknVWIyVByVfGKEVNyrbnuYBbNjRYJcc9r8H9r+IQPWq3WnapDH5jWeAHOeD 92RrZBwe84BuX1egK8BQGgefxP+IFg7pnSR/lcKKJztpnLI7IycUQ8x7XK4SVffD+Ky+ 0K5H5ii/5In0h1CWqqTn3gprRhiBLLAO77lDJ7lKDU284Q6RxB2kl21bzLMlg1E6NB+y b61J7CVrJijNcLOE6LaH7bJIO89ybTZwIvhtIflw+KXhWLlu9FqLCpngiZnEzU4xV83F ujVg== X-Gm-Message-State: AOAM530COG80noApBKpFw3liXop/0no7yVaMLJfao5FAMEG236kKZNYT lr/YJLP7n3QoWyBfbwPJV2+Q2w== X-Google-Smtp-Source: ABdhPJySeKT5m08yAD0pHil519FXWIFEpbzKeLSLU4/dgnmJI1nvcXRygPHQ2IOWxK7ZiCpseDrMHg== X-Received: by 2002:adf:f20b:: with SMTP id p11mr1389889wro.190.1621532595683; Thu, 20 May 2021 10:43:15 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 8/8] plugins/syscall: Added a table-like summary output Date: Thu, 20 May 2021 18:43:03 +0100 Message-Id: <20210520174303.12310-9-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210520174303.12310-1-alex.bennee@linaro.org> References: <20210520174303.12310-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, stefanha@redhat.com, crosa@redhat.com, pbonzini@redhat.com, Mahmoud Mandour , =?UTF-8?q?Alex=20Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Mahmoud Mandour 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 Signed-off-by: Alex Benn=C3=A9e Message-Id: <20210519032409.3041-1-ma.mandourr@gmail.com> --- tests/plugin/syscall.c | 98 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/tests/plugin/syscall.c b/tests/plugin/syscall.c index 53ee2ab6c4..6dd71092e1 100644 --- a/tests/plugin/syscall.c +++ b/tests/plugin/syscall.c @@ -16,32 +16,120 @@ =20 QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; =20 +typedef struct { + int64_t num; + int64_t calls; + int64_t errors; +} SyscallStats; + +static GMutex lock; +static GHashTable *statistics; + +static SyscallStats *get_or_create_entry(int64_t num) +{ + SyscallStats *entry =3D + (SyscallStats *) g_hash_table_lookup(statistics, GINT_TO_POINTER(n= um)); + + if (!entry) { + entry =3D g_new0(SyscallStats, 1); + entry->num =3D num; + g_hash_table_insert(statistics, GINT_TO_POINTER(num), (gpointer) e= ntry); + } + + return entry; +} + static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, uint64_t a8) { - g_autofree gchar *out =3D g_strdup_printf("syscall #%" PRIi64 "\n", nu= m); - qemu_plugin_outs(out); + if (statistics) { + SyscallStats *entry; + g_mutex_lock(&lock); + entry =3D get_or_create_entry(num); + entry->calls++; + g_mutex_unlock(&lock); + } else { + g_autofree gchar *out =3D g_strdup_printf("syscall #%" PRIi64 "\n"= , num); + qemu_plugin_outs(out); + } } =20 static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx, int64_t num, int64_t ret) +{ + if (statistics) { + SyscallStats *entry; + + g_mutex_lock(&lock); + /* Should always return an existent entry. */ + entry =3D get_or_create_entry(num); + if (ret < 0) { + entry->errors++; + } + g_mutex_unlock(&lock); + } else { + g_autofree gchar *out; + out =3D g_strdup_printf("syscall #%" PRIi64 " returned -> %" PRIi6= 4 "\n", + num, ret); + qemu_plugin_outs(out); + } +} + +static void print_entry(gpointer val, gpointer user_data) { g_autofree gchar *out; - out =3D g_strdup_printf("syscall #%" PRIi64 " returned -> %" PRIi64 "\= n", - num, ret); + SyscallStats *entry =3D (SyscallStats *) val; + int64_t syscall_num =3D entry->num; + out =3D g_strdup_printf( + "%-13" PRIi64 "%-6" PRIi64 " %" PRIi64 "\n", + syscall_num, entry->calls, entry->errors); qemu_plugin_outs(out); } =20 +static gint comp_func(gconstpointer ea, gconstpointer eb) +{ + SyscallStats *ent_a =3D (SyscallStats *) ea; + SyscallStats *ent_b =3D (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 =3D g_hash_table_get_values(statistics); + entries =3D g_list_sort(entries, comp_func); + qemu_plugin_outs("syscall no. calls errors\n"); =20 -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); +} =20 QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { + if (argc =3D=3D 0) { + statistics =3D g_hash_table_new_full(NULL, g_direct_equal, NULL, g= _free); + } else { + for (int i =3D 0; i < argc; i++) { + if (g_strcmp0(argv[i], "print") !=3D 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); --=20 2.20.1