perf evsel: Remove idx parm from constructor
Most uses of the evsel constructor are followed by a call to perf_evlist__add with an idex of evlist->nr_entries, so make rename the current constructor to perf_evsel__new_idx and remove the need for passing the constructor for the common case. We still need the new_idx variant because the way groups are handled, with evsel->nr_members holding the number of entries in an evlist, partitioning the evlist into sublists inside a single linked list. This asks for a clarifying refactoring, but for now simplify the non parser cases, so that tool writers don't have to bother with evsel idx setting. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-zy9tskx6jqm2rmw7468zze2a@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
@@ -117,6 +117,8 @@ void perf_evlist__delete(struct perf_evlist *evlist)
|
||||
void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry)
|
||||
{
|
||||
list_add_tail(&entry->node, &evlist->entries);
|
||||
entry->idx = evlist->nr_entries;
|
||||
|
||||
if (!evlist->nr_entries++)
|
||||
perf_evlist__set_id_pos(evlist);
|
||||
}
|
||||
@@ -165,7 +167,7 @@ int perf_evlist__add_default(struct perf_evlist *evlist)
|
||||
|
||||
event_attr_init(&attr);
|
||||
|
||||
evsel = perf_evsel__new(&attr, 0);
|
||||
evsel = perf_evsel__new(&attr);
|
||||
if (evsel == NULL)
|
||||
goto error;
|
||||
|
||||
@@ -190,7 +192,7 @@ static int perf_evlist__add_attrs(struct perf_evlist *evlist,
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < nr_attrs; i++) {
|
||||
evsel = perf_evsel__new(attrs + i, evlist->nr_entries + i);
|
||||
evsel = perf_evsel__new_idx(attrs + i, evlist->nr_entries + i);
|
||||
if (evsel == NULL)
|
||||
goto out_delete_partial_list;
|
||||
list_add_tail(&evsel->node, &head);
|
||||
@@ -249,9 +251,8 @@ perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
|
||||
int perf_evlist__add_newtp(struct perf_evlist *evlist,
|
||||
const char *sys, const char *name, void *handler)
|
||||
{
|
||||
struct perf_evsel *evsel;
|
||||
struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
|
||||
|
||||
evsel = perf_evsel__newtp(sys, name, evlist->nr_entries);
|
||||
if (evsel == NULL)
|
||||
return -1;
|
||||
|
||||
|
@@ -168,7 +168,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
|
||||
perf_evsel__calc_id_pos(evsel);
|
||||
}
|
||||
|
||||
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
|
||||
struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
|
||||
{
|
||||
struct perf_evsel *evsel = zalloc(sizeof(*evsel));
|
||||
|
||||
@@ -219,7 +219,7 @@ out:
|
||||
return format;
|
||||
}
|
||||
|
||||
struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx)
|
||||
struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx)
|
||||
{
|
||||
struct perf_evsel *evsel = zalloc(sizeof(*evsel));
|
||||
|
||||
|
@@ -96,8 +96,19 @@ struct thread_map;
|
||||
struct perf_evlist;
|
||||
struct perf_record_opts;
|
||||
|
||||
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx);
|
||||
struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name, int idx);
|
||||
struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
|
||||
|
||||
static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
|
||||
{
|
||||
return perf_evsel__new_idx(attr, 0);
|
||||
}
|
||||
|
||||
struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
|
||||
|
||||
static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
|
||||
{
|
||||
return perf_evsel__newtp_idx(sys, name, 0);
|
||||
}
|
||||
|
||||
struct event_format *event_format__new(const char *sys, const char *name);
|
||||
|
||||
|
@@ -2797,7 +2797,7 @@ int perf_session__read_header(struct perf_session *session)
|
||||
perf_event__attr_swap(&f_attr.attr);
|
||||
|
||||
tmp = lseek(fd, 0, SEEK_CUR);
|
||||
evsel = perf_evsel__new(&f_attr.attr, i);
|
||||
evsel = perf_evsel__new(&f_attr.attr);
|
||||
|
||||
if (evsel == NULL)
|
||||
goto out_delete_evlist;
|
||||
@@ -2916,7 +2916,7 @@ int perf_event__process_attr(struct perf_tool *tool __maybe_unused,
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
evsel = perf_evsel__new(&event->attr.attr, evlist->nr_entries);
|
||||
evsel = perf_evsel__new(&event->attr.attr);
|
||||
if (evsel == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
@@ -277,7 +277,7 @@ static int __add_event(struct list_head *list, int *idx,
|
||||
|
||||
event_attr_init(attr);
|
||||
|
||||
evsel = perf_evsel__new(attr, (*idx)++);
|
||||
evsel = perf_evsel__new_idx(attr, (*idx)++);
|
||||
if (!evsel)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -378,7 +378,7 @@ static int add_tracepoint(struct list_head *list, int *idx,
|
||||
{
|
||||
struct perf_evsel *evsel;
|
||||
|
||||
evsel = perf_evsel__newtp(sys_name, evt_name, (*idx)++);
|
||||
evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
|
||||
if (!evsel)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -1097,7 +1097,7 @@ static bool is_event_supported(u8 type, unsigned config)
|
||||
.threads = { 0 },
|
||||
};
|
||||
|
||||
evsel = perf_evsel__new(&attr, 0);
|
||||
evsel = perf_evsel__new(&attr);
|
||||
if (evsel) {
|
||||
ret = perf_evsel__open(evsel, NULL, &tmap.map) >= 0;
|
||||
perf_evsel__delete(evsel);
|
||||
|
Reference in New Issue
Block a user