diff mbox series

[v9,12/13] tb-stats: adding TBStatistics info into perf dump

Message ID 20191007152839.30804-13-alex.bennee@linaro.org (mailing list archive)
State New, archived
Headers show
Series TCG code quality tracking and perf integration | expand

Commit Message

Alex Bennée Oct. 7, 2019, 3:28 p.m. UTC
From: "Vanderson M. do Rosario" <vandersonmr2@gmail.com>

Adding TBStatistics information to linux perf TB's symbol names.

Signed-off-by: Vanderson M. do Rosario <vandersonmr2@gmail.com>
Message-Id: <20190830121903.17585-3-vandersonmr2@gmail.com>
[AJB: fix authorship, auto-strings]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
AJB:
  - use g_string and auto free
---
 accel/tcg/perf/jitdump.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

Richard Henderson Oct. 8, 2019, 7:46 p.m. UTC | #1
On 10/7/19 11:28 AM, Alex Bennée wrote:
> diff --git a/accel/tcg/perf/jitdump.c b/accel/tcg/perf/jitdump.c
> index e1d6f2214e..e7b86173e0 100644
> --- a/accel/tcg/perf/jitdump.c
> +++ b/accel/tcg/perf/jitdump.c
> @@ -146,7 +146,20 @@ void start_jitdump_file(void)
>  
>  void append_load_in_jitdump_file(TranslationBlock *tb)
>  {
> -    gchar *func_name = g_strdup_printf("TB virt:0x"TARGET_FMT_lx, tb->pc);
> +    g_autoptr(GString) func_name = g_string_new("TB virt:");
> +
> +    g_string_append_printf(func_name, "0x"TARGET_FMT_lx, tb->pc);

I think it was clearer as a single printf.  Use g_string_printf().

But now I see where the missing GString went -- bad patch splitting.  ;-)

> +    if (tb->tb_stats) {
> +        TBStatistics *tbs = tb->tb_stats;
> +        unsigned g = stat_per_translation(tbs, code.num_guest_inst);
> +        unsigned ops = stat_per_translation(tbs, code.num_tcg_ops);
> +        unsigned ops_opt = stat_per_translation(tbs, code.num_tcg_ops_opt);
> +        unsigned spills = stat_per_translation(tbs, code.spills);
> +
> +        g_string_append_printf(func_name, " (g:%u op:%u opt:%u spills:%d)",
> +                               g, ops, ops_opt, spills);
> +    }

Oh, hum.  Does it really make sense to have accumulated averages here?  Why
does it not make more sense to have the statistics about this particular TB?
After all, different TB -- even for the same guest code -- will appear at
different places within the code_gen_buffer, and so have different entries in
this log.


r~
diff mbox series

Patch

diff --git a/accel/tcg/perf/jitdump.c b/accel/tcg/perf/jitdump.c
index e1d6f2214e..e7b86173e0 100644
--- a/accel/tcg/perf/jitdump.c
+++ b/accel/tcg/perf/jitdump.c
@@ -146,7 +146,20 @@  void start_jitdump_file(void)
 
 void append_load_in_jitdump_file(TranslationBlock *tb)
 {
-    gchar *func_name = g_strdup_printf("TB virt:0x"TARGET_FMT_lx, tb->pc);
+    g_autoptr(GString) func_name = g_string_new("TB virt:");
+
+    g_string_append_printf(func_name, "0x"TARGET_FMT_lx, tb->pc);
+
+    if (tb->tb_stats) {
+        TBStatistics *tbs = tb->tb_stats;
+        unsigned g = stat_per_translation(tbs, code.num_guest_inst);
+        unsigned ops = stat_per_translation(tbs, code.num_tcg_ops);
+        unsigned ops_opt = stat_per_translation(tbs, code.num_tcg_ops_opt);
+        unsigned spills = stat_per_translation(tbs, code.spills);
+
+        g_string_append_printf(func_name, " (g:%u op:%u opt:%u spills:%d)",
+                               g, ops, ops_opt, spills);
+    }
 
     /* Serialise the writing of the dump file */
     qemu_mutex_lock(&dumpfile_lock);
@@ -167,7 +180,6 @@  void append_load_in_jitdump_file(TranslationBlock *tb)
     fwrite(func_name->str, func_name->len + 1, 1, dumpfile);
     fwrite(tb->tc.ptr, tb->tc.size, 1, dumpfile);
 
-    g_free(func_name);
     fflush(dumpfile);
 
     qemu_mutex_unlock(&dumpfile_lock);