From: Ingo Molnar <mingo@elte.hu>
To: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Clark Williams <williams@redhat.com>,
John Kacur <jkacur@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] perf_counter: Allow specifying a pid to record
Date: Fri, 15 May 2009 09:33:27 +0200 [thread overview]
Message-ID: <20090515073327.GA13879@elte.hu> (raw)
In-Reply-To: <20090515015046.GA13664@ghostprotocols.net>
* Arnaldo Carvalho de Melo <acme@redhat.com> wrote:
> Em Thu, May 14, 2009 at 10:45:27PM -0300, Arnaldo Carvalho de Melo escreveu:
> > commit ee8ffeaf1ba6aee56cf822cba291fbacb5dd450b
> > Author: Arnaldo Carvalho de Melo <acme@redhat.com>
> > Date: Thu May 14 22:41:18 2009 -0300
> >
> > perf_count: Allow connecting to an existing thread
> >
> > Impact: new command line option
> >
> > Allow specifying a pid instead of always fork+exec'ing a command.
> >
> > Because the PERF_EVENT_COMM and PERF_EVENT_MMAP events happened before
> > we connected, we must synthesize them so that 'perf record' can get what
> > it needs.
>
> Grr, it should read "so that 'perf report' can get", new patch below.
>
> commit 37216038fe2807ee0725e221675914cd41233541
> Author: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date: Thu May 14 22:41:18 2009 -0300
>
> perf_count: Allow connecting to an existing thread
>
> Impact: new command line option
>
> Allow specifying a pid instead of always fork+exec'ing a command.
>
> Because the PERF_EVENT_COMM and PERF_EVENT_MMAP events happened before
> we connected, we must synthesize them so that 'perf report' can get what
> it needs.
>
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Very nice, applied it - thanks Arnaldo!
> +static void pid_synthesize_mmap_events(pid_t pid, pid_t pgid)
> +{
> + char filename[PATH_MAX];
> + FILE *fp;
> +
> + snprintf(filename, sizeof(filename), "/proc/%d/maps", pid);
> +
> + fp = fopen(filename, "r");
> + if (fp == NULL) {
> + fprintf(stderr, "couldn't open %s\n", filename);
> + exit(EXIT_FAILURE);
> + }
> + while (1) {
> + char bf[BUFSIZ];
> + unsigned char vm_read, vm_write, vm_exec, vm_mayshare;
> + struct mmap_event mmap_ev = {
> + .header.type = PERF_EVENT_MMAP,
> + };
> + unsigned long ino;
> + int major, minor;
> + size_t size;
> + if (fgets(bf, sizeof(bf), fp) == NULL)
> + break;
> +
> + /* 00400000-0040c000 r-xp 00000000 fd:01 41038 /bin/cat */
> + sscanf(bf, "%llx-%llx %c%c%c%c %llx %x:%x %lu",
> + &mmap_ev.start, &mmap_ev.len,
> + &vm_read, &vm_write, &vm_exec, &vm_mayshare,
> + &mmap_ev.pgoff, &major, &minor, &ino);
> + if (vm_exec == 'x') {
> + char *execname = strrchr(bf, ' ');
> +
> + if (execname == NULL || execname[1] != '/')
> + continue;
> +
> + execname += 1;
> + size = strlen(execname);
> + execname[size - 1] = '\0'; /* Remove \n */
> + memcpy(mmap_ev.filename, execname, size);
> + size = ALIGN(size, sizeof(uint64_t));
> + mmap_ev.len -= mmap_ev.start;
> + mmap_ev.header.size = (sizeof(mmap_ev) -
> + (sizeof(mmap_ev.filename) - size));
> + mmap_ev.pid = pgid;
> + mmap_ev.tid = pid;
> +
> + if (write(output, &mmap_ev, mmap_ev.header.size) < 0) {
> + perror("failed to write");
> + exit(-1);
> + }
> + }
> + }
> +
> + fclose(fp);
> +}
Neat - this was one of the holes in the concept :)
Ingo
next prev parent reply other threads:[~2009-05-15 7:34 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-15 1:45 [PATCH] perf_counter: Allow specifying a pid to record Arnaldo Carvalho de Melo
2009-05-15 1:50 ` [PATCH v2] " Arnaldo Carvalho de Melo
2009-05-15 7:33 ` Ingo Molnar [this message]
2009-05-15 7:36 ` [tip:perfcounters/core] perf record: " tip-bot for Arnaldo Carvalho de Melo
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=20090515073327.GA13879@elte.hu \
--to=mingo@elte.hu \
--cc=acme@redhat.com \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=williams@redhat.com \
/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.