Commit 8dd2a131 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf evsel: Propagate error info from tp_format

Propagate error info from tp_format via ERR_PTR to get it all the way
down to the parse-event.c tracepoint adding routines. Following
functions now return pointer with encoded error:

  - tp_format
  - trace_event__tp_format
  - perf_evsel__newtp_idx
  - perf_evsel__newtp

This affects several other places in perf, that cannot use pointer check
anymore, but must utilize the err.h interface, when getting error
information from above functions list.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Raphael Beamonte <raphael.beamonte@gmail.com>
Link: http://lkml.kernel.org/r/1441615087-13886-5-git-send-email-jolsa@kernel.org
[ Add two missing ERR_PTR() and one IS_ERR() ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent e2f9f8ea
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <linux/futex.h> #include <linux/futex.h>
#include <linux/err.h>
/* For older distros: */ /* For older distros: */
#ifndef MAP_STACK #ifndef MAP_STACK
...@@ -245,13 +246,14 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void ...@@ -245,13 +246,14 @@ static struct perf_evsel *perf_evsel__syscall_newtp(const char *direction, void
struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction); struct perf_evsel *evsel = perf_evsel__newtp("raw_syscalls", direction);
/* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */ /* older kernel (e.g., RHEL6) use syscalls:{enter,exit} */
if (evsel == NULL) if (IS_ERR(evsel))
evsel = perf_evsel__newtp("syscalls", direction); evsel = perf_evsel__newtp("syscalls", direction);
if (evsel) { if (IS_ERR(evsel))
if (perf_evsel__init_syscall_tp(evsel, handler)) return NULL;
goto out_delete;
} if (perf_evsel__init_syscall_tp(evsel, handler))
goto out_delete;
return evsel; return evsel;
...@@ -1705,12 +1707,12 @@ static int trace__read_syscall_info(struct trace *trace, int id) ...@@ -1705,12 +1707,12 @@ static int trace__read_syscall_info(struct trace *trace, int id)
snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name); snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->name);
sc->tp_format = trace_event__tp_format("syscalls", tp_name); sc->tp_format = trace_event__tp_format("syscalls", tp_name);
if (sc->tp_format == NULL && sc->fmt && sc->fmt->alias) { if (IS_ERR(sc->tp_format) && sc->fmt && sc->fmt->alias) {
snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias); snprintf(tp_name, sizeof(tp_name), "sys_enter_%s", sc->fmt->alias);
sc->tp_format = trace_event__tp_format("syscalls", tp_name); sc->tp_format = trace_event__tp_format("syscalls", tp_name);
} }
if (sc->tp_format == NULL) if (IS_ERR(sc->tp_format))
return -1; return -1;
sc->args = sc->tp_format->format.fields; sc->args = sc->tp_format->format.fields;
...@@ -2390,7 +2392,8 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp); ...@@ -2390,7 +2392,8 @@ static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist) static bool perf_evlist__add_vfs_getname(struct perf_evlist *evlist)
{ {
struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname"); struct perf_evsel *evsel = perf_evsel__newtp("probe", "vfs_getname");
if (evsel == NULL)
if (IS_ERR(evsel))
return false; return false;
if (perf_evsel__field(evsel, "pathname") == NULL) { if (perf_evsel__field(evsel, "pathname") == NULL) {
......
#include <linux/err.h>
#include <traceevent/event-parse.h> #include <traceevent/event-parse.h>
#include "evsel.h" #include "evsel.h"
#include "tests.h" #include "tests.h"
...@@ -36,8 +37,8 @@ int test__perf_evsel__tp_sched_test(void) ...@@ -36,8 +37,8 @@ int test__perf_evsel__tp_sched_test(void)
struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch"); struct perf_evsel *evsel = perf_evsel__newtp("sched", "sched_switch");
int ret = 0; int ret = 0;
if (evsel == NULL) { if (IS_ERR(evsel)) {
pr_debug("perf_evsel__new\n"); pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
return -1; return -1;
} }
...@@ -66,6 +67,11 @@ int test__perf_evsel__tp_sched_test(void) ...@@ -66,6 +67,11 @@ int test__perf_evsel__tp_sched_test(void)
evsel = perf_evsel__newtp("sched", "sched_wakeup"); evsel = perf_evsel__newtp("sched", "sched_wakeup");
if (IS_ERR(evsel)) {
pr_debug("perf_evsel__newtp failed with %ld\n", PTR_ERR(evsel));
return -1;
}
if (perf_evsel__test_field(evsel, "comm", 16, true)) if (perf_evsel__test_field(evsel, "comm", 16, true))
ret = -1; ret = -1;
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "thread_map.h" #include "thread_map.h"
#include "cpumap.h" #include "cpumap.h"
#include "tests.h" #include "tests.h"
#include <linux/err.h>
/* /*
* This test will generate random numbers of calls to some getpid syscalls, * This test will generate random numbers of calls to some getpid syscalls,
...@@ -65,7 +66,7 @@ int test__basic_mmap(void) ...@@ -65,7 +66,7 @@ int test__basic_mmap(void)
snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]); snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
evsels[i] = perf_evsel__newtp("syscalls", name); evsels[i] = perf_evsel__newtp("syscalls", name);
if (evsels[i] == NULL) { if (IS_ERR(evsels[i])) {
pr_debug("perf_evsel__new\n"); pr_debug("perf_evsel__new\n");
goto out_delete_evlist; goto out_delete_evlist;
} }
......
#include <api/fs/fs.h> #include <api/fs/fs.h>
#include <linux/err.h>
#include "evsel.h" #include "evsel.h"
#include "tests.h" #include "tests.h"
#include "thread_map.h" #include "thread_map.h"
...@@ -31,7 +32,7 @@ int test__openat_syscall_event_on_all_cpus(void) ...@@ -31,7 +32,7 @@ int test__openat_syscall_event_on_all_cpus(void)
CPU_ZERO(&cpu_set); CPU_ZERO(&cpu_set);
evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
if (evsel == NULL) { if (IS_ERR(evsel)) {
tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
pr_err("%s\n", errbuf); pr_err("%s\n", errbuf);
goto out_thread_map_delete; goto out_thread_map_delete;
......
#include <linux/err.h>
#include "perf.h" #include "perf.h"
#include "evlist.h" #include "evlist.h"
#include "evsel.h" #include "evsel.h"
...@@ -30,7 +31,7 @@ int test__syscall_openat_tp_fields(void) ...@@ -30,7 +31,7 @@ int test__syscall_openat_tp_fields(void)
} }
evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
if (evsel == NULL) { if (IS_ERR(evsel)) {
pr_debug("%s: perf_evsel__newtp\n", __func__); pr_debug("%s: perf_evsel__newtp\n", __func__);
goto out_delete_evlist; goto out_delete_evlist;
} }
......
#include <api/fs/tracing_path.h> #include <api/fs/tracing_path.h>
#include <linux/err.h>
#include "thread_map.h" #include "thread_map.h"
#include "evsel.h" #include "evsel.h"
#include "debug.h" #include "debug.h"
...@@ -19,7 +20,7 @@ int test__openat_syscall_event(void) ...@@ -19,7 +20,7 @@ int test__openat_syscall_event(void)
} }
evsel = perf_evsel__newtp("syscalls", "sys_enter_openat"); evsel = perf_evsel__newtp("syscalls", "sys_enter_openat");
if (evsel == NULL) { if (IS_ERR(evsel)) {
tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat"); tracing_path__strerror_open_tp(errno, errbuf, sizeof(errbuf), "syscalls", "sys_enter_openat");
pr_err("%s\n", errbuf); pr_err("%s\n", errbuf);
goto out_thread_map_delete; goto out_thread_map_delete;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/log2.h> #include <linux/log2.h>
#include <linux/err.h>
static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx); static void perf_evlist__mmap_put(struct perf_evlist *evlist, int idx);
static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx); static void __perf_evlist__munmap(struct perf_evlist *evlist, int idx);
...@@ -265,7 +266,7 @@ int perf_evlist__add_newtp(struct perf_evlist *evlist, ...@@ -265,7 +266,7 @@ int perf_evlist__add_newtp(struct perf_evlist *evlist,
{ {
struct perf_evsel *evsel = perf_evsel__newtp(sys, name); struct perf_evsel *evsel = perf_evsel__newtp(sys, name);
if (evsel == NULL) if (IS_ERR(evsel))
return -1; return -1;
evsel->handler = handler; evsel->handler = handler;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <traceevent/event-parse.h> #include <traceevent/event-parse.h>
#include <linux/hw_breakpoint.h> #include <linux/hw_breakpoint.h>
#include <linux/perf_event.h> #include <linux/perf_event.h>
#include <linux/err.h>
#include <sys/resource.h> #include <sys/resource.h>
#include "asm/bug.h" #include "asm/bug.h"
#include "callchain.h" #include "callchain.h"
...@@ -225,11 +226,17 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx) ...@@ -225,11 +226,17 @@ struct perf_evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx)
return evsel; return evsel;
} }
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
struct perf_evsel *perf_evsel__newtp_idx(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(perf_evsel__object.size); struct perf_evsel *evsel = zalloc(perf_evsel__object.size);
int err = -ENOMEM;
if (evsel != NULL) { if (evsel == NULL) {
goto out_err;
} else {
struct perf_event_attr attr = { struct perf_event_attr attr = {
.type = PERF_TYPE_TRACEPOINT, .type = PERF_TYPE_TRACEPOINT,
.sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | .sample_type = (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
...@@ -240,8 +247,10 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int ...@@ -240,8 +247,10 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
goto out_free; goto out_free;
evsel->tp_format = trace_event__tp_format(sys, name); evsel->tp_format = trace_event__tp_format(sys, name);
if (evsel->tp_format == NULL) if (IS_ERR(evsel->tp_format)) {
err = PTR_ERR(evsel->tp_format);
goto out_free; goto out_free;
}
event_attr_init(&attr); event_attr_init(&attr);
attr.config = evsel->tp_format->id; attr.config = evsel->tp_format->id;
...@@ -254,7 +263,8 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int ...@@ -254,7 +263,8 @@ struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int
out_free: out_free:
zfree(&evsel->name); zfree(&evsel->name);
free(evsel); free(evsel);
return NULL; out_err:
return ERR_PTR(err);
} }
const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = { const char *perf_evsel__hw_names[PERF_COUNT_HW_MAX] = {
......
...@@ -160,6 +160,9 @@ static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr) ...@@ -160,6 +160,9 @@ static inline struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx); struct perf_evsel *perf_evsel__newtp_idx(const char *sys, const char *name, int idx);
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name) static inline struct perf_evsel *perf_evsel__newtp(const char *sys, const char *name)
{ {
return perf_evsel__newtp_idx(sys, name, 0); return perf_evsel__newtp_idx(sys, name, 0);
......
#include <linux/hw_breakpoint.h> #include <linux/hw_breakpoint.h>
#include <linux/err.h>
#include "util.h" #include "util.h"
#include "../perf.h" #include "../perf.h"
#include "evlist.h" #include "evlist.h"
...@@ -393,11 +394,10 @@ static int add_tracepoint(struct list_head *list, int *idx, ...@@ -393,11 +394,10 @@ static int add_tracepoint(struct list_head *list, int *idx,
struct perf_evsel *evsel; struct perf_evsel *evsel;
evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++); evsel = perf_evsel__newtp_idx(sys_name, evt_name, (*idx)++);
if (!evsel) if (IS_ERR(evsel))
return -ENOMEM; return PTR_ERR(evsel);
list_add_tail(&evsel->node, list); list_add_tail(&evsel->node, list);
return 0; return 0;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/err.h>
#include <traceevent/event-parse.h> #include <traceevent/event-parse.h>
#include <api/fs/tracing_path.h> #include <api/fs/tracing_path.h>
#include "trace-event.h" #include "trace-event.h"
...@@ -66,6 +67,9 @@ void trace_event__cleanup(struct trace_event *t) ...@@ -66,6 +67,9 @@ void trace_event__cleanup(struct trace_event *t)
pevent_free(t->pevent); pevent_free(t->pevent);
} }
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
static struct event_format* static struct event_format*
tp_format(const char *sys, const char *name) tp_format(const char *sys, const char *name)
{ {
...@@ -74,12 +78,14 @@ tp_format(const char *sys, const char *name) ...@@ -74,12 +78,14 @@ tp_format(const char *sys, const char *name)
char path[PATH_MAX]; char path[PATH_MAX];
size_t size; size_t size;
char *data; char *data;
int err;
scnprintf(path, PATH_MAX, "%s/%s/%s/format", scnprintf(path, PATH_MAX, "%s/%s/%s/format",
tracing_events_path, sys, name); tracing_events_path, sys, name);
if (filename__read_str(path, &data, &size)) err = filename__read_str(path, &data, &size);
return NULL; if (err)
return ERR_PTR(err);
pevent_parse_format(pevent, &event, data, size, sys); pevent_parse_format(pevent, &event, data, size, sys);
...@@ -87,11 +93,14 @@ tp_format(const char *sys, const char *name) ...@@ -87,11 +93,14 @@ tp_format(const char *sys, const char *name)
return event; return event;
} }
/*
* Returns pointer with encoded error via <linux/err.h> interface.
*/
struct event_format* struct event_format*
trace_event__tp_format(const char *sys, const char *name) trace_event__tp_format(const char *sys, const char *name)
{ {
if (!tevent_initialized && trace_event__init2()) if (!tevent_initialized && trace_event__init2())
return NULL; return ERR_PTR(-ENOMEM);
return tp_format(sys, name); return tp_format(sys, name);
} }
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