* [Question] About '(*idx)++' of perf_evsel__new_idx
@ 2017-01-30 2:53 Taeung Song
2017-01-30 19:03 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Taeung Song @ 2017-01-30 2:53 UTC (permalink / raw)
To: perf group; +Cc: Arnaldo Carvalho de Melo, Namhyung Kim
Hi, :)
Can I ask you one thing ?
I'm reading source code util/parse-event.c
Along the way, I wonder why increase idx before checking
whether 'evsel' is NULL or not ? (at 310,311 line number)
300 static struct perf_evsel *
301 __add_event(struct list_head *list, int *idx,
302 struct perf_event_attr *attr,
303 char *name, struct cpu_map *cpus,
304 struct list_head *config_terms)
305 {
306 struct perf_evsel *evsel;
307
308 event_attr_init(attr);
309
310 evsel = perf_evsel__new_idx(attr, (*idx)++);
311 if (!evsel)
312 return NULL;
313
314 evsel->cpus = cpu_map__get(cpus);
315 evsel->own_cpus = cpu_map__get(cpus);
316
IMHO, if 'evsel' isn't NULL, we can increase idx like below.
evsel = perf_evsel__new_idx(attr, *idx);
if (!evsel)
return NULL;
else
(*idx)++;
Is it wrong ? or is there other reason about increasing idx
before check 'evsel'?
Thanks,
Taeung
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Question] About '(*idx)++' of perf_evsel__new_idx
2017-01-30 2:53 [Question] About '(*idx)++' of perf_evsel__new_idx Taeung Song
@ 2017-01-30 19:03 ` Arnaldo Carvalho de Melo
2017-01-31 2:13 ` Taeung Song
0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2017-01-30 19:03 UTC (permalink / raw)
To: Taeung Song; +Cc: perf group, Arnaldo Carvalho de Melo, Namhyung Kim
Em Mon, Jan 30, 2017 at 11:53:18AM +0900, Taeung Song escreveu:
> Hi, :)
>
> Can I ask you one thing ?
>
> I'm reading source code util/parse-event.c
> Along the way, I wonder why increase idx before checking
> whether 'evsel' is NULL or not ? (at 310,311 line number)
>
>
> 300 static struct perf_evsel *
> 301 __add_event(struct list_head *list, int *idx,
> 302 struct perf_event_attr *attr,
> 303 char *name, struct cpu_map *cpus,
> 304 struct list_head *config_terms)
> 305 {
> 306 struct perf_evsel *evsel;
> 307
> 308 event_attr_init(attr);
> 309
> 310 evsel = perf_evsel__new_idx(attr, (*idx)++);
> 311 if (!evsel)
> 312 return NULL;
> 313
> 314 evsel->cpus = cpu_map__get(cpus);
> 315 evsel->own_cpus = cpu_map__get(cpus);
> 316
>
> IMHO, if 'evsel' isn't NULL, we can increase idx like below.
>
> evsel = perf_evsel__new_idx(attr, *idx);
> if (!evsel)
> return NULL;
> else
> (*idx)++;
>
> Is it wrong ? or is there other reason about increasing idx
> before check 'evsel'?
I think you're right and we should increment idx only if we manage to
create the evsel instance, no need for the else clause tho.
- Arnaldo
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Question] About '(*idx)++' of perf_evsel__new_idx
2017-01-30 19:03 ` Arnaldo Carvalho de Melo
@ 2017-01-31 2:13 ` Taeung Song
0 siblings, 0 replies; 3+ messages in thread
From: Taeung Song @ 2017-01-31 2:13 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: perf group, Arnaldo Carvalho de Melo, Namhyung Kim
Evening! :)
On 01/31/2017 04:03 AM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jan 30, 2017 at 11:53:18AM +0900, Taeung Song escreveu:
>> Hi, :)
>>
>> Can I ask you one thing ?
>>
>> I'm reading source code util/parse-event.c
>> Along the way, I wonder why increase idx before checking
>> whether 'evsel' is NULL or not ? (at 310,311 line number)
>>
>>
>> 300 static struct perf_evsel *
>> 301 __add_event(struct list_head *list, int *idx,
>> 302 struct perf_event_attr *attr,
>> 303 char *name, struct cpu_map *cpus,
>> 304 struct list_head *config_terms)
>> 305 {
>> 306 struct perf_evsel *evsel;
>> 307
>> 308 event_attr_init(attr);
>> 309
>> 310 evsel = perf_evsel__new_idx(attr, (*idx)++);
>> 311 if (!evsel)
>> 312 return NULL;
>> 313
>> 314 evsel->cpus = cpu_map__get(cpus);
>> 315 evsel->own_cpus = cpu_map__get(cpus);
>> 316
>>
>> IMHO, if 'evsel' isn't NULL, we can increase idx like below.
>>
>> evsel = perf_evsel__new_idx(attr, *idx);
>> if (!evsel)
>> return NULL;
>> else
>> (*idx)++;
>>
>> Is it wrong ? or is there other reason about increasing idx
>> before check 'evsel'?
>
> I think you're right and we should increment idx only if we manage to
> create the evsel instance, no need for the else clause tho.
>
I understood!
Thank you!
Taeung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-31 2:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-30 2:53 [Question] About '(*idx)++' of perf_evsel__new_idx Taeung Song
2017-01-30 19:03 ` Arnaldo Carvalho de Melo
2017-01-31 2:13 ` Taeung Song
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.