All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, crosthwaitepeter@gmail.com,
	pbonzini@redhat.com, "Alex Bennée" <alex.bennee@linaro.org>,
	aurelien@aurel32.net, rth@twiddle.net
Subject: [Qemu-devel] [PATCH v4 01/11] tcg: add ability to dump /tmp/perf-<pid>.map files
Date: Mon,  3 Aug 2015 10:14:41 +0100	[thread overview]
Message-ID: <1438593291-27109-2-git-send-email-alex.bennee@linaro.org> (raw)
In-Reply-To: <1438593291-27109-1-git-send-email-alex.bennee@linaro.org>

This allows the perf tool to map samples to each individual translation
block. This could be expanded for user space but currently it gives
enough information to find any hotblocks by other means.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---

v2:
  - hoist up into translate-all.c
  - don't use pointless glib wrappers
  - use proper format types for portability
  - mark prologue/epilog area
  - rebase

v3:
  - fix bracket for perf-map
  - find an include for the tb_enable_perfmap() declaration
  - checkpatch clean-ups
---
 include/qemu-common.h |  2 ++
 qemu-options.hx       |  9 +++++++++
 translate-all.c       | 26 ++++++++++++++++++++++++++
 vl.c                  |  4 ++++
 4 files changed, 41 insertions(+)

diff --git a/include/qemu-common.h b/include/qemu-common.h
index fb3da6c..60b87d0 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -382,6 +382,8 @@ typedef struct PCIHostDeviceAddress {
 void tcg_exec_init(unsigned long tb_size);
 bool tcg_enabled(void);
 
+void tb_enable_perfmap(void);
+
 void cpu_exec_init_all(void);
 
 /* CPU save/load.  */
diff --git a/qemu-options.hx b/qemu-options.hx
index 77f5853..ae53346 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3572,6 +3572,15 @@ to the RNG daemon.
 
 ETEXI
 
+DEF("perfmap", 0, QEMU_OPTION_PERFMAP, \
+    "-perfmap        generate a /tmp/perf-${pid}.map file for perf\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -perfmap
+@findex -perfmap
+This will cause QEMU to generate a map file for Linux perf tools that will allow
+basic profiling information to be broken down into basic blocks.
+ETEXI
 
 HXCOMM This is the last statement. Insert new options before this line!
 STEXI
diff --git a/translate-all.c b/translate-all.c
index 60a3d8b..c05e2a5 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
+#include <glib.h>
 
 #include "config.h"
 
@@ -133,6 +134,24 @@ static void tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
                          tb_page_addr_t phys_page2);
 static TranslationBlock *tb_find_pc(uintptr_t tc_ptr);
 
+static FILE *tb_perfmap;
+
+void tb_enable_perfmap(void)
+{
+    gchar *map_file = g_strdup_printf("/tmp/perf-%d.map", getpid());
+    tb_perfmap = fopen(map_file, "w");
+    g_free(map_file);
+}
+
+static void tb_write_perfmap(tcg_insn_unit *start, int size, target_ulong pc)
+{
+    if (tb_perfmap) {
+        fprintf(tb_perfmap,
+                "%"PRIxPTR" %x subject-"TARGET_FMT_lx"\n",
+                (uintptr_t) start, size, pc);
+    }
+}
+
 void cpu_gen_init(void)
 {
     tcg_context_init(&tcg_ctx); 
@@ -190,6 +209,7 @@ int cpu_gen_code(CPUArchState *env, TranslationBlock *tb, int *gen_code_size_ptr
     s->code_out_len += gen_code_size;
 #endif
 
+    tb_write_perfmap(gen_code_buf, gen_code_size, tb->pc);
 #ifdef DEBUG_DISAS
     if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
         qemu_log("OUT: [size=%d]\n", gen_code_size);
@@ -669,6 +689,12 @@ static inline void code_gen_alloc(size_t tb_size)
             tcg_ctx.code_gen_buffer_size - 1024;
     tcg_ctx.code_gen_buffer_size -= 1024;
 
+    if (tb_perfmap) {
+        fprintf(tb_perfmap,
+                "%"PRIxPTR" %x tcg-prologue-buffer\n",
+                (uintptr_t) tcg_ctx.code_gen_prologue, 1024);
+    }
+
     tcg_ctx.code_gen_buffer_max_size = tcg_ctx.code_gen_buffer_size -
         (TCG_MAX_OP_SIZE * OPC_BUF_SIZE);
     tcg_ctx.code_gen_max_blocks = tcg_ctx.code_gen_buffer_size /
diff --git a/vl.c b/vl.c
index 0adbbd6..1d2de4f 100644
--- a/vl.c
+++ b/vl.c
@@ -122,6 +122,7 @@ int main(int argc, char **argv)
 #include "qapi-event.h"
 #include "exec/semihost.h"
 #include "crypto/init.h"
+#include "qemu-common.h"
 
 #define MAX_VIRTIO_CONSOLES 1
 #define MAX_SCLP_CONSOLES 1
@@ -3348,6 +3349,9 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_D:
                 log_file = optarg;
                 break;
+            case QEMU_OPTION_PERFMAP:
+                tb_enable_perfmap();
+                break;
             case QEMU_OPTION_s:
                 add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
                 break;
-- 
2.5.0

  reply	other threads:[~2015-08-03  9:15 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-03  9:14 [Qemu-devel] [PATCH v4 00/11] qemu-log, perfmap and other logging tweaks Alex Bennée
2015-08-03  9:14 ` Alex Bennée [this message]
2015-08-03 13:40   ` [Qemu-devel] [PATCH v4 01/11] tcg: add ability to dump /tmp/perf-<pid>.map files Paolo Bonzini
2015-08-04  7:39     ` Alex Bennée
2015-08-04 10:02       ` Paolo Bonzini
2015-08-04 11:59       ` Aurelien Jarno
2015-08-04 12:55         ` Alex Bennée
2015-08-04 19:01           ` Aurelien Jarno
2015-08-04 12:15   ` Aurelien Jarno
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 02/11] tcg: light re-factor and pass down TranslationBlock Alex Bennée
2015-08-04 12:36   ` Aurelien Jarno
2016-02-03 18:38     ` Alex Bennée
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 03/11] qemu-log: correct help text for -d cpu Alex Bennée
2015-08-04 12:16   ` Aurelien Jarno
2015-08-04 15:11     ` Alex Bennée
2015-08-04 15:15       ` Peter Maydell
2015-08-04 15:21         ` Richard Henderson
2015-08-04 17:22           ` Alex Bennée
2015-08-04 18:09             ` Richard Henderson
2015-08-04 19:08               ` Alex Bennée
2015-08-04 19:16                 ` Richard Henderson
2015-09-15 19:28                   ` Peter Maydell
2015-09-15 19:41                     ` Richard Henderson
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 04/11] qemu-log: Avoid function call for disabled qemu_log_mask logging Alex Bennée
2015-08-04 12:17   ` Aurelien Jarno
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 05/11] qemu-log: Improve the "exec" TB execution logging Alex Bennée
2015-08-04 12:17   ` Aurelien Jarno
2015-08-10 19:40   ` Christopher Covington
2016-02-03 18:45     ` Alex Bennée
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 06/11] qemu-log: support simple pid substitution in logfile Alex Bennée
2015-08-04 12:17   ` Aurelien Jarno
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 07/11] qemu-log: new option -dfilter to limit output Alex Bennée
2015-08-04 12:21   ` Aurelien Jarno
2015-08-10 16:59   ` Christopher Covington
2015-08-10 18:30     ` Alex Bennée
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 08/11] qemu-log: dfilter-ise exec, out_asm, and op_opt Alex Bennée
2015-08-04 12:22   ` Aurelien Jarno
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 09/11] target-arm: dfilter support for in_asm, op, opt_op Alex Bennée
2015-08-04 12:23   ` Aurelien Jarno
2015-08-04 14:44   ` Richard Henderson
2015-08-04 17:26     ` Alex Bennée
2015-08-04 18:11       ` Richard Henderson
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 10/11] vl.c: log system invocation when enabled Alex Bennée
2015-08-04 12:30   ` Aurelien Jarno
2015-08-04 12:40   ` Peter Maydell
2015-08-04 12:46     ` Aurelien Jarno
2015-08-04 13:14       ` Peter Maydell
2015-08-04 15:12         ` Alex Bennée
2015-08-03  9:14 ` [Qemu-devel] [PATCH v4 11/11] cputlb: modernise the debug support Alex Bennée
2015-08-04 12:33   ` Aurelien Jarno
2016-02-03 18:54     ` Alex Bennée
2016-02-03 19:05       ` Peter Maydell
2016-02-04  7:03         ` Alex Bennée
2015-09-11  7:54 ` [Qemu-devel] [PATCH v4 00/11] qemu-log, perfmap and other logging tweaks Michael Tokarev
2015-09-11 14:07   ` Alex Bennée

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438593291-27109-2-git-send-email-alex.bennee@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=aurelien@aurel32.net \
    --cc=crosthwaitepeter@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.