Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964997Ab0BZPIo (ORCPT ); Fri, 26 Feb 2010 10:08:44 -0500 Received: from bombadil.infradead.org ([18.85.46.34]:38250 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964936Ab0BZPIn (ORCPT ); Fri, 26 Feb 2010 10:08:43 -0500 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, "David S. Miller" , =?utf-8?q?Fr=C3=A9d=C3=A9ric=20Weisbecker?= , Mike Galbraith , Peter Zijlstra , Paul Mackerras , Arnaldo Carvalho de Melo Subject: [PATCH 1/1] perf tools: Flush maps on COMM events Date: Fri, 26 Feb 2010 12:08:34 -0300 Message-Id: <1267196914-16238-1-git-send-email-acme@infradead.org> X-Mailer: git-send-email 1.6.2.5 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2583 Lines: 84 From: David S. Miller Even though we don't register the counters until the child is right about to exec(), we're still going to get at least a few events while the fork()'d child is still executing 'perf' and in particular we're going to get the MMAP events. We can't distinguish the ones in the newly executed process because the PID will be the same. One way to solve this would be to have a PERF_RECORD_EXEC event, and when this is seen 'perf' can flush it's map cache. We can't use PERF_RECORD_COMM since that's generated by other things, not just exec(). Actually, thinking about it some more, using PERF_RECORD_COMM might be a good enough approximation. Cc: Frédéric Weisbecker Cc: Mike Galbraith Cc: Peter Zijlstra Cc: Paul Mackerras Signed-off-by: David S. Miller Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/thread.c | 34 ++++++++++++++++++++++++++++++---- 1 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index c090654..21b9216 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -31,15 +31,41 @@ static struct thread *thread__new(pid_t pid) return self; } +static void map_groups__flush(struct map_groups *self) +{ + int type; + + for (type = 0; type < MAP__NR_TYPES; type++) { + struct rb_root *root = &self->maps[type]; + struct rb_node *next = rb_first(root); + + while (next) { + struct map *pos = rb_entry(next, struct map, rb_node); + next = rb_next(&pos->rb_node); + rb_erase(&pos->rb_node, root); + /* + * We may have references to this map, for + * instance in some hist_entry instances, so + * just move them to a separate list. + */ + list_add_tail(&pos->node, &self->removed_maps[pos->type]); + } + } +} + int thread__set_comm(struct thread *self, const char *comm) { + int err; + if (self->comm) free(self->comm); self->comm = strdup(comm); - if (self->comm == NULL) - return -ENOMEM; - self->comm_set = true; - return 0; + err = self->comm == NULL ? -ENOMEM : 0; + if (!err) { + self->comm_set = true; + map_groups__flush(&self->mg); + } + return err; } int thread__comm_len(struct thread *self) -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/