From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTGL0-0007Fb-Cu for qemu-devel@nongnu.org; Thu, 27 Mar 2014 15:51:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTGKu-0007Wq-QX for qemu-devel@nongnu.org; Thu, 27 Mar 2014 15:51:42 -0400 Received: from mail-qg0-x22c.google.com ([2607:f8b0:400d:c04::22c]:50680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTGKu-0007Wk-Hp for qemu-devel@nongnu.org; Thu, 27 Mar 2014 15:51:36 -0400 Received: by mail-qg0-f44.google.com with SMTP id a108so3334242qge.17 for ; Thu, 27 Mar 2014 12:51:36 -0700 (PDT) Sender: Richard Henderson Message-ID: <53348143.5060902@twiddle.net> Date: Thu, 27 Mar 2014 12:51:31 -0700 From: Richard Henderson MIME-Version: 1.0 References: <1395938253-9225-1-git-send-email-alex.bennee@linaro.org> In-Reply-To: <1395938253-9225-1-git-send-email-alex.bennee@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [RFC PATCH] tcg: add ability to dump /tmp/perf-.map files List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: alex.bennee@linaro.org, qemu-devel@nongnu.org Cc: Yeongkyoon Lee , Alexander Graf , Kirill Batuzov , Blue Swirl , Stefan Weil , Anthony Liguori , Amit Shah , Matthew Fernandez On 03/27/2014 09:37 AM, alex.bennee@linaro.org wrote: > From: Alex Bennée > > 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. Plausible, I suppose. > TCGOpDef tcg_op_defs[] = { > #define DEF(s, oargs, iargs, cargs, flags) { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags }, > @@ -2575,6 +2579,8 @@ static inline int tcg_gen_code_common(TCGContext *s, uint64_t target_pc, > the_end: > /* Generate TB finalization at the end of block */ > tcg_out_tb_finalize(s); > + > + tcg_write_perfmap(gen_code_buf, s->code_ptr - gen_code_buf, target_pc); > return -1; > } > > @@ -2666,6 +2672,21 @@ void tcg_dump_info(FILE *f, fprintf_function cpu_fprintf) > } > #endif > > +static FILE *tcg_perfmap = NULL; > +void qemu_tcg_enable_perfmap(void) { > + gchar * map_file = g_strdup_printf("/tmp/perf-%d.map", getpid()); > + tcg_perfmap = g_fopen(map_file, "w"); > + g_free(map_file); > +} > + > +static void tcg_write_perfmap(uint8_t *start, uint64_t size, uint64_t target_pc) > +{ > + if (tcg_perfmap) { > + g_fprintf(tcg_perfmap, "%lx %lx subject-0x%lx\n", > + (uint64_t) start, size, target_pc); > + } > +} Why oh why do you feel the need to use g_fprintf? That's just gratuitous glib obfuscation, that. For this small of a single-use function, I think it would be clearer to just do the printf directly in tcg_gen_code_common. Certainly no need to use uint64_t all over the place; ptrdiff_t and target_ulong are exactly the right thing. r~