perf evsel: Introduce constructor for cycles event

That is the default used when no events is specified in tools, separate
it so that simpler tools that need no evlist can use it directly.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-67mwuthscwroz88x9pswcqyv@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 674d2d69
......@@ -239,31 +239,13 @@ void perf_event_attr__set_max_precise_ip(struct perf_event_attr *attr)
int perf_evlist__add_default(struct perf_evlist *evlist)
{
struct perf_event_attr attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
};
struct perf_evsel *evsel;
event_attr_init(&attr);
perf_event_attr__set_max_precise_ip(&attr);
struct perf_evsel *evsel = perf_evsel__new_cycles();
evsel = perf_evsel__new(&attr);
if (evsel == NULL)
goto error;
/* use asprintf() because free(evsel) assumes name is allocated */
if (asprintf(&evsel->name, "cycles%.*s",
attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0)
goto error_free;
return -ENOMEM;
perf_evlist__add(evlist, evsel);
return 0;
error_free:
perf_evsel__delete(evsel);
error:
return -ENOMEM;
}
int perf_evlist__add_dummy(struct perf_evlist *evlist)
......
......@@ -253,6 +253,34 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
return evsel;
}
struct perf_evsel *perf_evsel__new_cycles(void)
{
struct perf_event_attr attr = {
.type = PERF_TYPE_HARDWARE,
.config = PERF_COUNT_HW_CPU_CYCLES,
};
struct perf_evsel *evsel;
event_attr_init(&attr);
perf_event_attr__set_max_precise_ip(&attr);
evsel = perf_evsel__new(&attr);
if (evsel == NULL)
goto out;
/* use asprintf() because free(evsel) assumes name is allocated */
if (asprintf(&evsel->name, "cycles%.*s",
attr.precise_ip ? attr.precise_ip + 1 : 0, ":ppp") < 0)
goto error_free;
out:
return evsel;
error_free:
perf_evsel__delete(evsel);
evsel = NULL;
goto out;
}
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
......
......@@ -175,6 +175,8 @@ static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *
return perf_evsel__newtp_idx(sys, name, 0);
}
struct perf_evsel *perf_evsel__new_cycles(void);
struct event_format *event_format__new(const char *sys, const char *name);
void perf_evsel__init(struct perf_evsel *evsel,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment