All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@plumgrid.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@redhat.com>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: perf probe and structs
Date: Fri, 12 Jun 2015 19:58:02 -0700	[thread overview]
Message-ID: <557B9C3A.50101@plumgrid.com> (raw)
In-Reply-To: <20150612192716.GE6850@kernel.org>

On 6/12/15 12:27 PM, Arnaldo Carvalho de Melo wrote:
> Alexei, is this already possible with eBPF?
> I want to decode that attr_uptr thing :-)

yes, it's already possible :)

Here is working example from our experimental c+python thingy:
#!/usr/bin/env python

from bpf import BPF
from subprocess import call

prog = """
#include <uapi/linux/ptrace.h>
#include <uapi/linux/perf_event.h>
int hello(struct pt_regs *ctx)
{
   struct perf_event_attr attr = {};
   bpf_probe_read(&attr, sizeof(attr), (void *) ctx->di);
   char fmt[] = "type %x size %d config %d\\n";
   bpf_trace_printk(fmt, sizeof(fmt), attr.type, attr.size, attr.config);
   return 0;
}
"""
b = BPF(text=prog)
fn = b.load_func("hello", BPF.KPROBE)
BPF.attach_kprobe(fn, "SYSC_perf_event_open")
try:
     call(["cat", "/sys/kernel/debug/tracing/trace_pipe"])
except KeyboardInterrupt:
     pass

running above gives me output:
# ./example.py
       perf_4.1.0-5544  [001] d.h3  3818.231428: : type 1 size 0 config 0
       perf_4.1.0-5544  [001] d.h3  3818.231494: : type 0 size 112 config 0
       perf_4.1.0-5544  [001] d.h3  3818.231530: : type 0 size 112 config 0
       perf_4.1.0-5544  [001] d.h3  3818.231554: : type 0 size 112 config 0
       perf_4.1.0-5544  [001] d.h3  3818.231564: : type 0 size 112 config 0


  parent reply	other threads:[~2015-06-13  2:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 19:27 perf probe and structs Arnaldo Carvalho de Melo
2015-06-13  1:38 ` Masami Hiramatsu
2015-06-13  2:58 ` Alexei Starovoitov [this message]
2015-06-14 12:18 ` Masami Hiramatsu

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=557B9C3A.50101@plumgrid.com \
    --to=ast@plumgrid.com \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.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 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.