[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map
From: |
Alex Bennée |
Subject: |
[Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files |
Date: |
Thu, 31 Jul 2014 14:06:24 +0100 |
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 <address@hidden>
---
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
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 6ef8282..ce57884 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -259,6 +259,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 1549625..3defba8 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -3348,6 +3348,16 @@ Dump json-encoded vmstate information for current
machine type to file
in @var{file}
ETEXI
+DEF("perfmap", 0, QEMU_OPTION_PERFMAP, \
+ "-perfmap generate a /tmp/perf-${pid}.map file for perf\n",
+ QEMU_ARCH_ALL)
+STEXI
address@hidden -perfmap
address@hidden -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
@end table
diff --git a/translate-all.c b/translate-all.c
index 8f7e11b..2af0774 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"
@@ -129,6 +130,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);
@@ -184,6 +203,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);
@@ -670,6 +690,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 fe451aa..f07f6e0 100644
--- a/vl.c
+++ b/vl.c
@@ -118,6 +118,7 @@ int main(int argc, char **argv)
#include "qapi/opts-visitor.h"
#include "qom/object_interfaces.h"
#include "qapi-event.h"
+#include "qemu-common.h"
#define DEFAULT_RAM_SIZE 128
@@ -3385,6 +3386,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.0.3
- [Qemu-devel] [PATCH v3 0/9] qemu-log dfilter and perf.map changes, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 6/9] qemu-log: support simple pid substitution in logfile, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 1/9] tcg: add ability to dump /tmp/perf-<pid>.map files,
Alex Bennée <=
- [Qemu-devel] [PATCH v3 9/9] target-arm: dfilter support for in_asm, op, opt_op, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 7/9] qemu-log: new option -dfilter to limit output, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 8/9] qemu-log: dfilter-ise exec, out_asm, and op_opt, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 5/9] qemu-log: Improve the "exec" TB execution logging, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 4/9] qemu-log: Avoid function call for disabled qemu_log_mask logging, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 2/9] tcg: light re-factor and pass down TranslationBlock, Alex Bennée, 2014/07/31
- [Qemu-devel] [PATCH v3 3/9] qemu-log: correct help text for -d cpu, Alex Bennée, 2014/07/31