From: Jiri Olsa <jolsa@redhat.com>
To: rostedt@goodmis.org, fweisbec@gmail.com, mingo@redhat.com,
a.p.zijlstra@chello.nl
Cc: linux-kernel@vger.kernel.org
Subject: [RFC,PATCH 0/3] trace,perf: enabling ftrace/function tracepoint
Date: Thu, 21 Apr 2011 12:40:55 +0200 [thread overview]
Message-ID: <1303382458-11072-1-git-send-email-jolsa@redhat.com> (raw)
hi,
this is just RFC patch with patche series showing the
direction I'm taking.. _RFC_ ;)
I was discussing with Frederic the possibility to have function trace
available for perf processing, and the possibility to have it used
as starting/stopping events, and probably more.
The 1st 2 patches adding the registration function for the
ftrace/function tracepoint to be usable by both trace and perf
via tracepoint interface.
The 3rd patch is the biggest hack and is trying to add filtering
support. I'm currently looking on the filtering code to come up
with some better idea of hooking this type of filtering in.
attached patches:
1/3 - add support for enabling ftrace/function tracepoint event
2/3 - add support for registering ftrace/function tracepoint event via perf
3/3 - add filter support for ftrace/function tracepoint event
I could read perf counts from ftrace/function tracepoint using
attached program.
Any thoughts/ideas about this direction or projecting some other
would be just great :)
thanks a lot,
jirka
---
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/perf_event.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
static int trace_event__id(const char *evname)
{
char *filename;
int err = -1, fd;
if (asprintf(&filename,
"/debug/tracing/events/ftrace/%s/id",
evname) < 0)
return -1;
fd = open(filename, O_RDONLY);
if (fd >= 0) {
char id[16];
if (read(fd, id, sizeof(id)) > 0)
err = atoi(id);
close(fd);
}
free(filename);
return err;
}
static inline int
sys_perf_event_open(struct perf_event_attr *attr,
pid_t pid, int cpu, int group_fd,
unsigned long flags)
{
attr->size = sizeof(*attr);
return syscall(__NR_perf_event_open, attr, pid, cpu,
group_fd, flags);
}
int main(int argc, char **argv)
{
struct perf_event_attr attr;
int fd;
pid_t pid;
int status;
long count;
int ret;
int id = trace_event__id("function");
int child_ready_pipe[2];
if (id < 0) {
printf("is debugfs mounted on /sys/kernel/debug?\n");
return -1;
}
if (pipe(child_ready_pipe) < 0) {
perror("pipe failed");
return -1;
}
memset(&attr, 0, sizeof(attr));
attr.type = PERF_TYPE_TRACEPOINT;
attr.config = id;
attr.enable_on_exec = 1;
pid = fork();
if (!pid) {
char buf;
char *cmd = "/bin/sleep";
char *newargv[] = { cmd, "2", NULL };
char *newenviron[] = { NULL };
/* wait for parent to setup the counter */
close(child_ready_pipe[1]);
if (read(child_ready_pipe[0], &buf, 1) == -1) {
perror("unable to read pipe");
return -1;
}
close(child_ready_pipe[0]);
execve(cmd, newargv, newenviron);
perror("execve failed");
return -1;
}
fd = sys_perf_event_open(&attr, pid, -1, -1, 0);
if (fd < 0) {
perror("sys_perf_event_open failed");
return -1;
}
if (ioctl(fd, PERF_EVENT_IOC_SET_FILTER, "ip == sys_close", 0)) {
perror("ioctl failed");
return -1;
}
/* tell the child it can go nuts */
close(child_ready_pipe[1]);
close(child_ready_pipe[0]);
waitpid(pid, &status, 0);
ret = read(fd, &count, sizeof(count));
if (ret <= 0) {
perror("read failed");
return -1;
}
printf("count = %ld\n", count);
return 0;
}
next reply other threads:[~2011-04-21 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-21 10:40 Jiri Olsa [this message]
2011-04-21 10:40 ` [RFC,PATCH 1/3] trace: add support for enabling ftrace/function tracepoint event Jiri Olsa
2011-04-21 10:40 ` [RFC,PATCH 2/3] trace,perf: add support for registering ftrace/function tracepoint event via perf Jiri Olsa
2011-04-21 10:40 ` [RFC,PATCH 3/3] trace,perf: add filter support for ftrace/function tracepoint event Jiri Olsa
2011-04-21 15:20 ` Frederic Weisbecker
2011-04-21 15:27 ` [RFC,PATCH 0/3] trace,perf: enabling ftrace/function tracepoint Frederic Weisbecker
2011-04-21 15:34 ` Steven Rostedt
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=1303382458-11072-1-git-send-email-jolsa@redhat.com \
--to=jolsa@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=rostedt@goodmis.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®