diff mbox series

[v2,21/40] test/plugin: make insn plugin less noisy by default

Message ID 20240705084047.857176-22-alex.bennee@linaro.org
State New
Headers show
Series July maintainer updates (32bit, testing, plugins, gdbstub) | expand

Commit Message

Alex Bennée July 5, 2024, 8:40 a.m. UTC
While the match functionality is useful lets make the verbosity
optional while we are actually running.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 tests/plugin/insn.c | 36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

Comments

Manos Pitsidianakis July 5, 2024, 10:02 a.m. UTC | #1
On Fri, 5 Jul 2024 at 11:49, Alex Bennée <alex.bennee@linaro.org> wrote:
>
> While the match functionality is useful lets make the verbosity
> optional while we are actually running.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  tests/plugin/insn.c | 36 +++++++++++++++++++++---------------
>  1 file changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
> index 5e0aa03223..524f9ddde8 100644
> --- a/tests/plugin/insn.c
> +++ b/tests/plugin/insn.c
> @@ -20,6 +20,7 @@ static qemu_plugin_u64 insn_count;
>
>  static bool do_inline;
>  static bool do_size;
> +static bool do_trace;
>  static GArray *sizes;
>
>  typedef struct {
> @@ -73,30 +74,30 @@ static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *udata)
>      MatchCount *match = qemu_plugin_scoreboard_find(insn_match->counts,
>                                                      cpu_index);
>
> -    g_autoptr(GString) ts = g_string_new("");
> -
>      insn->hits++;
> -    g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits",
> -                           insn->vaddr, insn->disas, insn->hits);
>
>      uint64_t icount = qemu_plugin_u64_get(insn_count, cpu_index);
>      uint64_t delta = icount - match->last_hit;
>
>      match->hits++;
>      match->total_delta += delta;
> -
> -    g_string_append_printf(ts,
> -                           " , cpu %u,"
> -                           " %"PRId64" match hits,"
> -                           " Δ+%"PRId64 " since last match,"
> -                           " %"PRId64 " avg insns/match\n",
> -                           cpu_index,
> -                           match->hits, delta,
> -                           match->total_delta / match->hits);
> -
>      match->last_hit = icount;
>
> -    qemu_plugin_outs(ts->str);
> +    if (do_trace) {
> +        g_autoptr(GString) ts = g_string_new("");
> +        g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits",
> +                               insn->vaddr, insn->disas, insn->hits);
> +        g_string_append_printf(ts,
> +                               " , cpu %u,"
> +                               " %"PRId64" match hits,"
> +                               " Δ+%"PRId64 " since last match,"
> +                               " %"PRId64 " avg insns/match\n",
> +                               cpu_index,
> +                               match->hits, delta,
> +                               match->total_delta / match->hits);
> +
> +        qemu_plugin_outs(ts->str);
> +    }
>  }
>
>  static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
> @@ -216,6 +217,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
>              }
>          } else if (g_strcmp0(tokens[0], "match") == 0) {
>              parse_match(tokens[1]);
> +        } else if (g_strcmp0(tokens[0], "trace") == 0) {
> +            if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_trace)) {
> +                fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
> +                return -1;
> +            }
>          } else {
>              fprintf(stderr, "option parsing failed: %s\n", opt);
>              return -1;
> --
> 2.39.2
>
>

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
diff mbox series

Patch

diff --git a/tests/plugin/insn.c b/tests/plugin/insn.c
index 5e0aa03223..524f9ddde8 100644
--- a/tests/plugin/insn.c
+++ b/tests/plugin/insn.c
@@ -20,6 +20,7 @@  static qemu_plugin_u64 insn_count;
 
 static bool do_inline;
 static bool do_size;
+static bool do_trace;
 static GArray *sizes;
 
 typedef struct {
@@ -73,30 +74,30 @@  static void vcpu_insn_matched_exec_before(unsigned int cpu_index, void *udata)
     MatchCount *match = qemu_plugin_scoreboard_find(insn_match->counts,
                                                     cpu_index);
 
-    g_autoptr(GString) ts = g_string_new("");
-
     insn->hits++;
-    g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits",
-                           insn->vaddr, insn->disas, insn->hits);
 
     uint64_t icount = qemu_plugin_u64_get(insn_count, cpu_index);
     uint64_t delta = icount - match->last_hit;
 
     match->hits++;
     match->total_delta += delta;
-
-    g_string_append_printf(ts,
-                           " , cpu %u,"
-                           " %"PRId64" match hits,"
-                           " Δ+%"PRId64 " since last match,"
-                           " %"PRId64 " avg insns/match\n",
-                           cpu_index,
-                           match->hits, delta,
-                           match->total_delta / match->hits);
-
     match->last_hit = icount;
 
-    qemu_plugin_outs(ts->str);
+    if (do_trace) {
+        g_autoptr(GString) ts = g_string_new("");
+        g_string_append_printf(ts, "0x%" PRIx64 ", '%s', %"PRId64 " hits",
+                               insn->vaddr, insn->disas, insn->hits);
+        g_string_append_printf(ts,
+                               " , cpu %u,"
+                               " %"PRId64" match hits,"
+                               " Δ+%"PRId64 " since last match,"
+                               " %"PRId64 " avg insns/match\n",
+                               cpu_index,
+                               match->hits, delta,
+                               match->total_delta / match->hits);
+
+        qemu_plugin_outs(ts->str);
+    }
 }
 
 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
@@ -216,6 +217,11 @@  QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
             }
         } else if (g_strcmp0(tokens[0], "match") == 0) {
             parse_match(tokens[1]);
+        } else if (g_strcmp0(tokens[0], "trace") == 0) {
+            if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_trace)) {
+                fprintf(stderr, "boolean argument parsing failed: %s\n", opt);
+                return -1;
+            }
         } else {
             fprintf(stderr, "option parsing failed: %s\n", opt);
             return -1;