linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
To: christopher lee <christopher.lee.eu@gmail.com>
Cc: Linux Trace Devel <linux-trace-devel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: how to register an event handler for the instance
Date: Thu, 12 May 2022 06:05:24 +0300	[thread overview]
Message-ID: <CAPpZLN4cETG40X1TWGa8b9o=rDhufXBKKGj0MDmCP4CVip9LpA@mail.gmail.com> (raw)
In-Reply-To: <fbb8049e2a9fcce07110d5d97f08458d27c977b4.camel@gmail.com>

On Wed, May 11, 2022 at 9:33 PM christopher lee
<christopher.lee.eu@gmail.com> wrote:
>
> On Sat, 2022-05-07 at 08:02 +0300, Tzvetomir Stoyanov wrote:
> > On Fri, May 6, 2022 at 7:18 PM christopher lee
> > <christopher.lee.eu@gmail.com> wrote:
> > >
> > > Hi all,
> > >
> > > I use libtraceevent in my trace tool to parse the event log. Now I
> > > allocated an instance, but no idea how to use
> > > tep_register_event_handler() to register a handler for the
> > > instance. Is
> > > it possilbe to register handler for the event in the instance?
> > >
> >
> > Hi Chrit,
> > All trace events are the same across all trace instances, thus the
> > handler registered with tep_register_event_handler() handles events
> > from all instances with a given id. That's why there are no
> > "instance"
> > oriented APIs in that library. I would suggest looking at the tracefs
> > library, which is instance aware. It can be used to allocate trace
> > instances and read events from a given instance.
> >
> > https://trace-cmd.org/Documentation/libtracefs/
> >
>
>
> Hi Tzvetomir Stoyanov,
>
> Thanks,  instance event handlers work now, but I'm confused with these
> codes, do I have to read trace_pipe_raw? I found that if I didn't read
> this file, the handler would not be able to get trace information.
> Becuase if I read this file, and also call tep_print_event() will
> consume lots of CPU resoruce. how can I parse the trace event info
> without reading this file?

Hi Christ,
All recorded events are in trace_pipe_raw file, so yes - if you want
to parse the trace event info, the first step is to read the events.
It consumes lots of CPU resources because there are a lot of events to
read and parse. I would suggest using the tracefs_iterate_raw_events()
API to read the events, as it is optimized to read the trace_pipe_raw
file in an efficient way, or at least to look at its implementation if
you do not want to use the tracefs library.

static int read_callback(struct tep_event *event, struct tep_record
*record, int cpu, void *context)
{
     ...
     tep_print_event();
     ...
}

tracefs_iterate_raw_events(tep, instance, NULL, 0, read_callback, ...);

>
>
>         for (i = 0; ; i++) {
>                 char *raw_buf;
>                 char *cpu;
>
>                 ret = asprintf(&cpu, "%s/cpu%d", per_cpu, i);
>                 if (ret < 0)
>                         pdie("Could not allocate memory for cpu buffer
> %d name", i);
>
>                 ret = stat(cpu, &st);
>                 if (ret < 0 || !S_ISDIR(st.st_mode)) {
>                         free(cpu);
>                         goto start;
>                 }
>
>                 ret = asprintf(&raw_buf, "%s/trace_pipe_raw", cpu);
>                 if (ret < 0)
>                         pdie("Could not allocate memory for cpu %d raw
> buffer name", i);
>
>                 read_raw_buffer(i, raw_buf);
>                 free(raw_buf);
>                 free(cpu);
>         }
>
> Best regards,
> Christ
>
> >



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

  reply	other threads:[~2022-05-12  3:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 16:18 how to register an event handler for the instance christopher lee
2022-05-07  5:02 ` Tzvetomir Stoyanov
2022-05-11 18:33   ` christopher lee
2022-05-12  3:05     ` Tzvetomir Stoyanov [this message]
2022-05-16 18:14     ` Steven Rostedt
2022-05-16 21:24       ` christopher lee

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='CAPpZLN4cETG40X1TWGa8b9o=rDhufXBKKGj0MDmCP4CVip9LpA@mail.gmail.com' \
    --to=tz.stoyanov@gmail.com \
    --cc=christopher.lee.eu@gmail.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).