From: christopher lee <christopher.lee.eu@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: how to register an event handler for the instance
Date: Mon, 16 May 2022 23:24:48 +0200 [thread overview]
Message-ID: <6d8a8664837f2cdcc861e458274b27135685716a.camel@gmail.com> (raw)
In-Reply-To: <20220516141427.775cd70a@gandalf.local.home>
Hi Steven,
>On Mon, 2022-05-16 at 14:14 -0400, Steven Rostedt wrote:
>
>
> Are you only looking to reading some events or all of them?
I created several instances and only enabled one trace event in each
instance. I need to read all trace data from each trace_pipe in each
instance and parse the trace information in each instance's associated
thread. I found that if I read tace_pipe, then parse string, it will
not consume so much CPU resource.
>
> > 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?
>
> The tep_print_event() is easier to use, but you can do things
> manually as
> well. I'll need to write a tutorial to explain this more, but I can
> help
> you here.
>
Thanks so much for your support!!
> >
> >
> > 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);
>
> This your own code?
>
no, it is your code, from your example.
> There is a way to read it yourself and to pick and choose the evens
> you
> want.
>
> If you read the raw data, you'll need to read it in page size (found
> in the
> header tep file) tep_get_page_size(). And read one page at a time.
> Then you
> can use the kbuffer code (although I haven't finished the man pages
> for
> them)
>
> Look at the traceevent/kbuffer.h file supplied by libtraceevent.
>
> You can do something like the following:
>
> unsigned long long ts; // time stamp of event
> struct tep_record record; // should probably be allocated
>
> /* For little endian 64 bit machines */
> kbuf = kbuffer_alloc(KBUFFER_LSIZE_8, KBUFFER_ENDIAN_LITTLE);
>
> read(fd, buf, page_size);
>
> kbuffer_load_subbuffer(kbuf, buf);
>
> data = kbuffer_read_event(kbuf, &ts);
>
> if (!data)
> return; // end of sub buffer.
>
> /* Move the kbuf cursor to the next event */
> kbuffer_next_event(kbuf, NULL);
>
> /* Now data has the record */
>
> record.ts = ts;
> record.size = kbuffer_event_size(kbuf);
> record.cpu = cpu; // CPU of the trace_pipe_raw file
> record.data = data;
> record.missed_events = kbuffer_missed_events(kbuf);
>
Got it now, I should measure its CPU usage and get back to you here.
Kind regards,
Christ.
> >
prev parent reply other threads:[~2022-05-16 21:24 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
2022-05-16 18:14 ` Steven Rostedt
2022-05-16 21:24 ` christopher lee [this message]
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=6d8a8664837f2cdcc861e458274b27135685716a.camel@gmail.com \
--to=christopher.lee.eu@gmail.com \
--cc=linux-trace-devel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=tz.stoyanov@gmail.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 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).