From patchwork Fri Sep 3 09:03:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 506493 Delivered-To: patch@linaro.org Received: by 2002:a02:8629:0:0:0:0:0 with SMTP id e38csp835654jai; Fri, 3 Sep 2021 02:27:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKXFSQwHndSzLm7OknONVlT5/3FbCYXJj5cfAm7V82M4Ol0q8U5E8LD01VXmkmKXOEKuek X-Received: by 2002:a25:bc10:: with SMTP id i16mr3560074ybh.73.1630661261774; Fri, 03 Sep 2021 02:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630661261; cv=none; d=google.com; s=arc-20160816; b=sqB6z10w2B5LHgG8lsF+ZdM3jwixi1m9uvP+DnfZvGMMuWKbhaJvX21WKt+XDt1ZLa TI/x/33erbUBXU1mQV5b3XAe5lLG3MzZyIN7Cy1yajoQQ3ixWH7HJLaJsSclNvhKHL1O 6pWaAm/dVcmb5FzFfZTHlL7CylFrzmnqhnNmlUT5h7J6Fc50yEUtwPR4/+M6Nan5eOXw hYeya7E9f1NGCtJrHJiNnREXJxHiTGuO6F0MKMdbvGHsJlrI1BuKBYU83qy1H67FZDvB GpwiUXP935AtYZ58IWanL8v0sxtlSqYynPmsPSkFFBe0+h4UO7brTGOKktmDCO0IcH0i A+2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=5M7LN/rhrQ/tByfAjAq1zS6Dlqe4MPUhzqfn+rf9SCw=; b=PGrcdstVlNqeg2b7sPfx5sseEmExFF2tyDmGRCC5ZcW5ajxarGgSPPwBIphl6WwaDT 6EK5sgQhtQlu925TKaR21u2syUWqbcltpHpUqnBaET7rMM85ugIUR2yKZnX4OZ2/d90r 1KjsZM/K6RIHfqAdyhMJsavAyi2Ap/UPBH4q518/XUAntv6sjfaODhWWEneHN9fa5FSa MvQHmk/UwF7w+ROs3MO7J7HRdi9FhogieGUXx+WrC34CEfCqjmhDPVsxwzFKxzcmRjDq BDpxQFdbv3ij20Ze2gEeuWnO1OIEClQLzTP6bNGOCtF3jgbVwBDIKh2CPjJ9wJFQnXwD cHoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xNXZwStz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v4si5052061ybp.116.2021.09.03.02.27.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Sep 2021 02:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xNXZwStz; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47796 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mM5U4-0003Od-8q for patch@linaro.org; Fri, 03 Sep 2021 05:27:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mM5F4-0003hZ-N6 for qemu-devel@nongnu.org; Fri, 03 Sep 2021 05:12:10 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:43588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mM5F2-0003vJ-RM for qemu-devel@nongnu.org; Fri, 03 Sep 2021 05:12:10 -0400 Received: by mail-wm1-x32b.google.com with SMTP id o39-20020a05600c512700b002e74638b567so3111995wms.2 for ; Fri, 03 Sep 2021 02:12:08 -0700 (PDT) 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=5M7LN/rhrQ/tByfAjAq1zS6Dlqe4MPUhzqfn+rf9SCw=; b=xNXZwStzUDdNbJ7ueWslUc8Su7Fs8m77d5SdoKYa2QB/7XbIYDdVcRKkY2EW184xfp TpG0vqN68kUKlX51cn/3u4NWfEFUv0RI6Xh8DJwVnS0ffRMCYBf2RCFj/OfHhhpa52Ov SjLqQbKefGM+vpdgl627r9IQqHayWUX66okQBOAUojq4EmYdnYob0WvPDajoGXXiIKZP wCe4QENKmXCug66kgm5NEgdK6bfFZD4ATnrpRf6kZSfVT3v/dPbfNVbTJ0W8x03fnjMA sCM+qDPbb5D25zq2UUJ4V6W3wDawi+jBcMJlrzapRfmDBXFuh2a/Fm5SFjLq0y9egI8G zd4g== 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=5M7LN/rhrQ/tByfAjAq1zS6Dlqe4MPUhzqfn+rf9SCw=; b=cuFwwG/udG/8eFv7LtJqcDqQSLqSOcp7xD2vAaUxadw34MnxWcuQn8Oe7A3suYeomG MxTzDz0t4nsPiWDB32xf0fI03Oyqt1rX+AMS7UEYHGB6OAZ4eXqfUEY77d/sr6o5+Zq5 gKReetYIACVZ+FyyhsrffsYl/otCTY+tJpKGoS24gysLlu38vOeIIjgJpCPy1kAyurvX lyQl3403f3VFI5cGM1Khly0WPqyrvCW4EEn+TBchVOglIRU1rNXqffmrfXw7NLhK9kGd EJ0HDYZVjr/0C/Y0AU0i9pJzF4K15uQT1In+LwC48Tl87uzKJFiOvix1kPukGZ9uIsI7 +Ehg== X-Gm-Message-State: AOAM532VIVIJSBs3jpp0rZ2jQBn3NopT391YxNg3i6dxNKPJUiD372mT AEoxJOf2nl86JthCcX7GmKHQWKuWFhmEeg== X-Received: by 2002:a1c:a9ce:: with SMTP id s197mr7120120wme.173.1630660327381; Fri, 03 Sep 2021 02:12:07 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id d7sm4140205wrs.39.2021.09.03.02.12.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Sep 2021 02:12:03 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id F18C61FFAC; Fri, 3 Sep 2021 10:03:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 14/22] plugins/hwprofile: adapt to the new plugin arguments scheme Date: Fri, 3 Sep 2021 10:03:31 +0100 Message-Id: <20210903090339.1074887-15-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210903090339.1074887-1-alex.bennee@linaro.org> References: <20210903090339.1074887-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x32b.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: Alexandre Iooss , Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Mahmoud Mandour Parsing boolean arguments correctly (e.g. pattern=on or source=false). Introduced a new "track" argument that takes a [read|write] value. This substitutes passing read or write to "arg=" that is deprecated. Also, matches are now taken one by one through the "match" argument. Signed-off-by: Mahmoud Mandour Reviewed-by: Alex Bennée Tested-by: Alex Bennée Signed-off-by: Alex Bennée Message-Id: <20210730135817.17816-7-ma.mandourr@gmail.com> -- 2.30.2 diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst index 5cddf31c70..e1f9eff587 100644 --- a/docs/devel/tcg-plugins.rst +++ b/docs/devel/tcg-plugins.rst @@ -306,22 +306,22 @@ which will eventually report:: The hwprofile tool can only be used with system emulation and allows the user to see what hardware is accessed how often. It has a number of options: - * arg=read or arg=write + * track=read or track=write By default the plugin tracks both reads and writes. You can use one of these options to limit the tracking to just one class of accesses. - * arg=source + * source Will include a detailed break down of what the guest PC that made the - access was. Not compatible with arg=pattern. Example output:: + access was. Not compatible with the pattern option. Example output:: cirrus-low-memory @ 0xfffffd00000a0000 pc:fffffc0000005cdc, 1, 256 pc:fffffc0000005ce8, 1, 256 pc:fffffc0000005cec, 1, 256 - * arg=pattern + * pattern Instead break down the accesses based on the offset into the HW region. This can be useful for seeing the most used registers of a diff --git a/contrib/plugins/hwprofile.c b/contrib/plugins/hwprofile.c index faf216ac00..691d4edb0c 100644 --- a/contrib/plugins/hwprofile.c +++ b/contrib/plugins/hwprofile.c @@ -259,27 +259,42 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { int i; + g_autoptr(GString) matches_raw = g_string_new(""); for (i = 0; i < argc; i++) { char *opt = argv[i]; - if (g_strcmp0(opt, "read") == 0) { - rw = QEMU_PLUGIN_MEM_R; - } else if (g_strcmp0(opt, "write") == 0) { - rw = QEMU_PLUGIN_MEM_W; - } else if (g_strcmp0(opt, "pattern") == 0) { - pattern = true; - } else if (g_strcmp0(opt, "source") == 0) { - source = true; - } else if (g_str_has_prefix(opt, "match")) { - gchar **parts = g_strsplit(opt, "=", 2); + g_autofree char **tokens = g_strsplit(opt, "=", 2); + + if (g_strcmp0(tokens[0], "track") == 0) { + if (g_strcmp0(tokens[1], "read") == 0) { + rw = QEMU_PLUGIN_MEM_R; + } else if (g_strcmp0(tokens[1], "write") == 0) { + rw = QEMU_PLUGIN_MEM_W; + } else { + fprintf(stderr, "invalid value for track: %s\n", tokens[1]); + return -1; + } + } else if (g_strcmp0(tokens[0], "pattern") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &pattern)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } + } else if (g_strcmp0(tokens[0], "source") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &source)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } + } else if (g_strcmp0(tokens[0], "match") == 0) { check_match = true; - matches = g_strsplit(parts[1], ",", -1); - g_strfreev(parts); + g_string_append_printf(matches_raw, "%s,", tokens[1]); } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; } } + if (check_match) { + matches = g_strsplit(matches_raw->str, ",", -1); + } if (source && pattern) { fprintf(stderr, "can only currently track either source or pattern.\n");