[PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument

Alex Bradbury posted 5 patches 3 months, 2 weeks ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>
[PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument
Posted by Alex Bradbury 3 months, 2 weeks ago
Also add documentation for this argument. This allows the default of 20
to be overridden, and is helpful for using the hotblocks plugin for
analysis scripts that require collecting data on a larger number of
blocks (e.g. setting limit=0 to dump information on all blocks).

Signed-off-by: Alex Bradbury <asb@igalia.com>
---
 contrib/plugins/hotblocks.c | 10 +++++++++-
 docs/about/emulation.rst    |  2 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 40d8dae1cd..8ecf033997 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -84,7 +84,8 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
     if (sorted_counts) {
         g_string_append_printf(report, "pc, tcount, icount, ecount\n");
 
-        for (i = 0, it = sorted_counts; i < limit && it; i++, it = it->next) {
+        for (i = 0, it = sorted_counts; (limit == 0 || i < limit) && it;
+             i++, it = it->next) {
             ExecCount *rec = (ExecCount *) it->data;
             g_string_append_printf(
                 report, "0x%016"PRIx64", %d, %ld, %"PRIu64"\n",
@@ -170,6 +171,13 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,
                 fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
                 return -1;
             }
+        } else if (g_strcmp0(tokens[0], "limit") == 0) {
+            char *endptr = NULL;
+            limit = g_ascii_strtoull(tokens[1], &endptr, 10);
+            if (endptr == tokens[1] || *endptr != '\0') {
+                fprintf(stderr, "unsigned integer parsing failed: %s\n", opt);
+                return -1;
+            }
         } else {
             fprintf(stderr, "option parsing failed: %s\n", opt);
             return -1;
diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst
index 9c963f4705..185edb8ad7 100644
--- a/docs/about/emulation.rst
+++ b/docs/about/emulation.rst
@@ -473,6 +473,8 @@ Behaviour can be tweaked with the following arguments:
     - Description
   * - inline=true|false
     - Use faster inline addition of a single counter.
+  * - limit=N
+    - The number of blocks to be printed. (Default: N = 20, use 0 for no limit).
 
 Hot Pages
 .........
-- 
2.50.1
Re: [PATCH 5/5] contrib/plugins/hotblocks: Allow limit to be set as a command line argument
Posted by Pierrick Bouvier 3 months, 2 weeks ago
On 7/29/25 11:41 PM, Alex Bradbury wrote:
> Also add documentation for this argument. This allows the default of 20
> to be overridden, and is helpful for using the hotblocks plugin for
> analysis scripts that require collecting data on a larger number of
> blocks (e.g. setting limit=0 to dump information on all blocks).
> 
> Signed-off-by: Alex Bradbury <asb@igalia.com>
> ---
>   contrib/plugins/hotblocks.c | 10 +++++++++-
>   docs/about/emulation.rst    |  2 ++
>   2 files changed, 11 insertions(+), 1 deletion(-)

That's a good idea, thanks!
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>