linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	Tzvetomir Stoyanov <tstoyanov@vmware.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [BUG] libtraceevent: perf script -g python segfaults
Date: Thu, 17 Oct 2019 16:28:32 -0300	[thread overview]
Message-ID: <20191017192832.GB3600@kernel.org> (raw)
In-Reply-To: <20191017144114.48e25298@gandalf.local.home>

Em Thu, Oct 17, 2019 at 02:41:14PM -0400, Steven Rostedt escreveu:
> On Thu, 17 Oct 2019 14:38:41 -0400
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> >  struct tep_event *trace_find_next_event(struct tep_handle *pevent,
> >  					struct tep_event *event)
> >  {
> > +	static struct tep_event **all_events;
> >  	static int idx;
> >  	int events_count;
> > -	struct tep_event *all_events;
> 
> If we are going to use static variables, let's make them all static and
> optimize it a little more...

I'll test it, but can't you have this somewhere else, i.e. at
tep_handle perhaps?

- Arnaldo
 
> -- Steve
> 
> diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c
> index ad74be1f0e42..3f23462517a3 100644
> --- a/tools/perf/util/trace-event-parse.c
> +++ b/tools/perf/util/trace-event-parse.c
> @@ -193,30 +193,35 @@ int parse_event_file(struct tep_handle *pevent,
>  struct tep_event *trace_find_next_event(struct tep_handle *pevent,
>  					struct tep_event *event)
>  {
> +	static struct tep_event **all_events;
> +	static int events_count;
>  	static int idx;
> -	int events_count;
> -	struct tep_event *all_events;
>  
> -	all_events = tep_get_first_event(pevent);
> -	events_count = tep_get_events_count(pevent);
> -	if (!pevent || !all_events || events_count < 1)
> +	if (!pevent || !all_events)
>  		return NULL;
>  
>  	if (!event) {
>  		idx = 0;
> -		return all_events;
> +		events_count = tep_get_events_count(pevent);
> +		if (events_count < 1)
> +			return NULL;
> +
> +		all_events = tep_list_events(pevent, TEP_EVENT_SORT_ID);
> +		if (all_events)
> +			return all_events[0];
> +		return NULL;
>  	}
>  
> -	if (idx < events_count && event == (all_events + idx)) {
> +	if (idx < events_count && event == all_events[idx]) {
>  		idx++;
>  		if (idx == events_count)
>  			return NULL;
> -		return (all_events + idx);
> +		return all_events[idx];
>  	}
>  
>  	for (idx = 1; idx < events_count; idx++) {
> -		if (event == (all_events + (idx - 1)))
> -			return (all_events + idx);
> +		if (event == all_events[idx - 1])
> +			return all_events[idx];
>  	}
>  	return NULL;
>  }

-- 

- Arnaldo

  reply	other threads:[~2019-10-17 19:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 15:42 [BUG] libtraceevent: perf script -g python segfaults Arnaldo Carvalho de Melo
2019-10-17 17:45 ` Steven Rostedt
2019-10-17 18:38 ` Steven Rostedt
2019-10-17 18:41   ` Steven Rostedt
2019-10-17 19:28     ` Arnaldo Carvalho de Melo [this message]
2019-10-17 19:37       ` Steven Rostedt
2019-10-17 19:49         ` Arnaldo Carvalho de Melo
2019-10-17 19:51           ` Arnaldo Carvalho de Melo
2019-10-21 23:19         ` [tip: perf/core] perf scripting engines: Iterate on tep event arrays directly tip-bot2 for Steven Rostedt (VMware)
2019-11-06 18:14         ` [tip: perf/urgent] " tip-bot2 for Steven Rostedt (VMware)

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=20191017192832.GB3600@kernel.org \
    --to=arnaldo.melo@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=tstoyanov@vmware.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).