This patch is to return error code of perf_new_session function on
failure instead of NULL.
Test Results:
Before Fix:
$ perf c2c report -input
failed to open nput: No such file or directory
$ echo $?
0
$
After Fix:
$ perf c2c report -input
failed to open nput: No such file or directory
$ echo $?
254
$
Committer notes:
Fix 'perf tests topology' case, where we use that TEST_ASSERT_VAL(...,
session), i.e. we need to pass zero in case of failure, which was the
case before when NULL was returned by perf_session__new() for failure,
but now we need to negate the result of IS_ERR(session) to respect that
TEST_ASSERT_VAL) expectation of zero meaning failure.
Reported-by: Nageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Signed-off-by: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Nageswara R Sastry <rnsastry@linux.vnet.ibm.com>
Acked-by: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Reviewed-by: Mukesh Ojha <mojha@codeaurora.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kate Stewart <kstewart@linuxfoundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shawn Landden <shawn@git.icu>
Cc: Song Liu <songliubraving@fb.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tzvetomir Stoyanov <tstoyanov@vmware.com>
Link: http://lore.kernel.org/lkml/20190822071223.17892.45782.stgit@localhost.localdomain
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
22 files changed:
#include <dlfcn.h>
#include <errno.h>
#include <linux/bitmap.h>
#include <dlfcn.h>
#include <errno.h>
#include <linux/bitmap.h>
struct perf_annotate {
struct perf_tool tool;
struct perf_annotate {
struct perf_tool tool;
data.path = input_name;
annotate.session = perf_session__new(&data, false, &annotate.tool);
data.path = input_name;
annotate.session = perf_session__new(&data, false, &annotate.tool);
- if (annotate.session == NULL)
- return -1;
+ if (IS_ERR(annotate.session))
+ return PTR_ERR(annotate.session);
annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
HEADER_BRANCH_STACK);
annotate.has_br_stack = perf_header__has_feat(&annotate.session->header,
HEADER_BRANCH_STACK);
#include "util/util.h"
#include "util/probe-file.h"
#include <linux/string.h>
#include "util/util.h"
#include "util/probe-file.h"
#include <linux/string.h>
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
{
static int build_id_cache__kcore_buildid(const char *proc_dir, char *sbuildid)
{
data.force = force;
session = perf_session__new(&data, false, NULL);
data.force = force;
session = perf_session__new(&data, false, NULL);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
}
if (symbol__init(session ? &session->header.env : NULL) < 0)
}
if (symbol__init(session ? &session->header.env : NULL) < 0)
#include "util/symbol.h"
#include "util/data.h"
#include <errno.h>
#include "util/symbol.h"
#include "util/data.h"
#include <errno.h>
static int sysfs__fprintf_build_id(FILE *fp)
{
static int sysfs__fprintf_build_id(FILE *fp)
{
goto out;
session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops);
goto out;
session = perf_session__new(&data, false, &build_id__mark_dso_hit_ops);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
/*
* We take all buildids when the file contains AUX area tracing data
/*
* We take all buildids when the file contains AUX area tracing data
#include <errno.h>
#include <inttypes.h>
#include <linux/compiler.h>
#include <errno.h>
#include <inttypes.h>
#include <linux/compiler.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
#include <linux/zalloc.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
#include <linux/zalloc.h>
}
session = perf_session__new(&data, 0, &c2c.tool);
}
session = perf_session__new(&data, 0, &c2c.tool);
- if (session == NULL) {
- pr_debug("No memory for session\n");
+ if (IS_ERR(session)) {
+ err = PTR_ERR(session);
+ pr_debug("Error creating perf session\n");
#include "util/time-utils.h"
#include "util/annotate.h"
#include "util/map.h"
#include "util/time-utils.h"
#include "util/annotate.h"
#include "util/map.h"
#include <linux/zalloc.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
#include <linux/zalloc.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
data__for_each_file(i, d) {
d->session = perf_session__new(&d->data, false, &pdiff.tool);
data__for_each_file(i, d) {
d->session = perf_session__new(&d->data, false, &pdiff.tool);
+ if (IS_ERR(d->session)) {
pr_err("Failed to open %s\n", d->data.path);
pr_err("Failed to open %s\n", d->data.path);
+ return PTR_ERR(d->session);
}
has_br_stack = perf_header__has_feat(&d->session->header,
}
has_br_stack = perf_header__has_feat(&d->session->header,
data__for_each_file(i, d) {
d->session = perf_session__new(&d->data, false, &pdiff.tool);
data__for_each_file(i, d) {
d->session = perf_session__new(&d->data, false, &pdiff.tool);
+ if (IS_ERR(d->session)) {
+ ret = PTR_ERR(d->session);
pr_err("Failed to open %s\n", d->data.path);
pr_err("Failed to open %s\n", d->data.path);
#include "util/session.h"
#include "util/data.h"
#include "util/debug.h"
#include "util/session.h"
#include "util/data.h"
#include "util/debug.h"
static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
{
static int __cmd_evlist(const char *file_name, struct perf_attr_details *details)
{
bool has_tracepoint = false;
session = perf_session__new(&data, 0, NULL);
bool has_tracepoint = false;
session = perf_session__new(&data, 0, NULL);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
evlist__for_each_entry(session->evlist, pos) {
perf_evsel__fprintf(pos, details, stdout);
evlist__for_each_entry(session->evlist, pos) {
perf_evsel__fprintf(pos, details, stdout);
#include "util/symbol.h"
#include "util/synthetic-events.h"
#include "util/thread.h"
#include "util/symbol.h"
#include "util/synthetic-events.h"
#include "util/thread.h"
#include <subcmd/parse-options.h>
#include <subcmd/parse-options.h>
data.path = inject.input_name;
inject.session = perf_session__new(&data, true, &inject.tool);
data.path = inject.input_name;
inject.session = perf_session__new(&data, true, &inject.tool);
- if (inject.session == NULL)
- return -1;
+ if (IS_ERR(inject.session))
+ return PTR_ERR(inject.session);
if (zstd_init(&(inject.session->zstd_data), 0) < 0)
pr_warning("Decompression initialization failed.\n");
if (zstd_init(&(inject.session->zstd_data), 0) < 0)
pr_warning("Decompression initialization failed.\n");
#include "util/tool.h"
#include "util/callchain.h"
#include "util/time-utils.h"
#include "util/tool.h"
#include "util/callchain.h"
#include "util/time-utils.h"
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
#include <subcmd/pager.h>
#include <subcmd/parse-options.h>
data.path = input_name;
kmem_session = session = perf_session__new(&data, false, &perf_kmem);
data.path = input_name;
kmem_session = session = perf_session__new(&data, false, &perf_kmem);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/time64.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/time64.h>
kvm->tool = eops;
kvm->session = perf_session__new(&file, false, &kvm->tool);
kvm->tool = eops;
kvm->session = perf_session__new(&file, false, &kvm->tool);
+ if (IS_ERR(kvm->session)) {
pr_err("Initializing perf session failed\n");
pr_err("Initializing perf session failed\n");
+ return PTR_ERR(kvm->session);
}
symbol__init(&kvm->session->header.env);
}
symbol__init(&kvm->session->header.env);
* perf session
*/
kvm->session = perf_session__new(&data, false, &kvm->tool);
* perf session
*/
kvm->session = perf_session__new(&data, false, &kvm->tool);
- if (kvm->session == NULL) {
- err = -1;
+ if (IS_ERR(kvm->session)) {
+ err = PTR_ERR(kvm->session);
goto out;
}
kvm->session->evlist = kvm->evlist;
goto out;
}
kvm->session->evlist = kvm->evlist;
#include <linux/hash.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
#include <linux/hash.h>
#include <linux/kernel.h>
#include <linux/zalloc.h>
static struct perf_session *session;
static struct perf_session *session;
};
session = perf_session__new(&data, false, &eops);
};
session = perf_session__new(&data, false, &eops);
pr_err("Initializing perf session failed\n");
pr_err("Initializing perf session failed\n");
+ return PTR_ERR(session);
}
symbol__init(&session->header.env);
}
symbol__init(&session->header.env);
#include "util/dso.h"
#include "util/map.h"
#include "util/symbol.h"
#include "util/dso.h"
#include "util/map.h"
#include "util/symbol.h"
#define MEM_OPERATION_LOAD 0x1
#define MEM_OPERATION_STORE 0x2
#define MEM_OPERATION_LOAD 0x1
#define MEM_OPERATION_STORE 0x2
struct perf_session *session = perf_session__new(&data, false,
&mem->tool);
struct perf_session *session = perf_session__new(&data, false,
&mem->tool);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
if (mem->cpu_list) {
ret = perf_session__cpu_bitmap(session, mem->cpu_list,
if (mem->cpu_list) {
ret = perf_session__cpu_bitmap(session, mem->cpu_list,
#include <signal.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <linux/string.h>
#include <linux/time64.h>
#include <linux/zalloc.h>
#include <linux/string.h>
#include <linux/time64.h>
#include <linux/zalloc.h>
}
session = perf_session__new(data, false, tool);
}
session = perf_session__new(data, false, tool);
pr_err("Perf session creation failed.\n");
pr_err("Perf session creation failed.\n");
+ return PTR_ERR(session);
}
fd = perf_data__fd(data);
}
fd = perf_data__fd(data);
repeat:
session = perf_session__new(&data, false, &report.tool);
repeat:
session = perf_session__new(&data, false, &report.tool);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
ret = evswitch__init(&report.evswitch, session->evlist, stderr);
if (ret)
ret = evswitch__init(&report.evswitch, session->evlist, stderr);
if (ret)
#include <api/fs/fs.h>
#include <perf/cpumap.h>
#include <linux/time64.h>
#include <api/fs/fs.h>
#include <perf/cpumap.h>
#include <linux/time64.h>
int rc = -1;
session = perf_session__new(&data, false, &sched->tool);
int rc = -1;
session = perf_session__new(&data, false, &sched->tool);
- if (session == NULL) {
- pr_debug("No Memory for session\n");
- return -1;
+ if (IS_ERR(session)) {
+ pr_debug("Error creating perf session");
+ return PTR_ERR(session);
}
symbol__init(&session->header.env);
}
symbol__init(&session->header.env);
symbol_conf.use_callchain = sched->show_callchain;
session = perf_session__new(&data, false, &sched->tool);
symbol_conf.use_callchain = sched->show_callchain;
session = perf_session__new(&data, false, &sched->tool);
- if (session == NULL)
- return -ENOMEM;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
evlist = session->evlist;
evlist = session->evlist;
#include <unistd.h>
#include <subcmd/pager.h>
#include <perf/evlist.h>
#include <unistd.h>
#include <subcmd/pager.h>
#include <perf/evlist.h>
#include "util/record.h"
#include "util/util.h"
#include "perf.h"
#include "util/record.h"
#include "util/util.h"
#include "perf.h"
int i = 0;
session = perf_session__new(&data, false, NULL);
int i = 0;
session = perf_session__new(&data, false, NULL);
- if (!session)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
snprintf(scripts_path, MAXPATHLEN, "%s/scripts", get_argv_exec_path());
}
session = perf_session__new(&data, false, &script.tool);
}
session = perf_session__new(&data, false, &script.tool);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
if (header || header_only) {
script.tool.show_feat_hdr = SHOW_FEAT_HEADER;
if (header || header_only) {
script.tool.show_feat_hdr = SHOW_FEAT_HEADER;
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <linux/ctype.h>
#include <perf/evlist.h>
#include <linux/ctype.h>
#include <perf/evlist.h>
}
session = perf_session__new(data, false, NULL);
}
session = perf_session__new(data, false, NULL);
- if (session == NULL) {
- pr_err("Perf session creation failed.\n");
- return -1;
+ if (IS_ERR(session)) {
+ pr_err("Perf session creation failed\n");
+ return PTR_ERR(session);
}
init_features(session);
}
init_features(session);
perf_stat.data.mode = PERF_DATA_MODE_READ;
session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
perf_stat.data.mode = PERF_DATA_MODE_READ;
session = perf_session__new(&perf_stat.data, false, &perf_stat.tool);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
perf_stat.session = session;
stat_config.output = stderr;
perf_stat.session = session;
stat_config.output = stderr;
#include "util/tool.h"
#include "util/data.h"
#include "util/debug.h"
#include "util/tool.h"
#include "util/data.h"
#include "util/debug.h"
#ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE
FILE *open_memstream(char **ptr, size_t *sizeloc);
#ifdef LACKS_OPEN_MEMSTREAM_PROTOTYPE
FILE *open_memstream(char **ptr, size_t *sizeloc);
&tchart->tool);
int ret = -EINVAL;
&tchart->tool);
int ret = -EINVAL;
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
symbol__init(&session->header.env);
symbol__init(&session->header.env);
#include <linux/stringify.h>
#include <linux/time64.h>
#include <linux/types.h>
#include <linux/stringify.h>
#include <linux/time64.h>
#include <linux/types.h>
}
top.session = perf_session__new(NULL, false, NULL);
}
top.session = perf_session__new(NULL, false, NULL);
- if (top.session == NULL) {
- status = -1;
+ if (IS_ERR(top.session)) {
+ status = PTR_ERR(top.session);
goto out_delete_evlist;
}
goto out_delete_evlist;
}
trace->multiple_threads = true;
session = perf_session__new(&data, false, &trace->tool);
trace->multiple_threads = true;
session = perf_session__new(&data, false, &trace->tool);
- if (session == NULL)
- return -1;
+ if (IS_ERR(session))
+ return PTR_ERR(session);
if (trace->opts.target.pid)
symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
if (trace->opts.target.pid)
symbol_conf.pid_list_str = strdup(trace->opts.target.pid);
#include "session.h"
#include "evlist.h"
#include "debug.h"
#include "session.h"
#include "evlist.h"
#include "debug.h"
#define TEMPL "/tmp/perf-test-XXXXXX"
#define DATA_SIZE 10
#define TEMPL "/tmp/perf-test-XXXXXX"
#define DATA_SIZE 10
};
session = perf_session__new(&data, false, NULL);
};
session = perf_session__new(&data, false, NULL);
- TEST_ASSERT_VAL("can't get session", session);
+ TEST_ASSERT_VAL("can't get session", !IS_ERR(session));
session->evlist = perf_evlist__new_default();
TEST_ASSERT_VAL("can't get evlist", session->evlist);
session->evlist = perf_evlist__new_default();
TEST_ASSERT_VAL("can't get evlist", session->evlist);
int i;
session = perf_session__new(&data, false, NULL);
int i;
session = perf_session__new(&data, false, NULL);
- TEST_ASSERT_VAL("can't get session", session);
+ TEST_ASSERT_VAL("can't get session", !IS_ERR(session));
/* On platforms with large numbers of CPUs process_cpu_topology()
* might issue an error while reading the perf.data file section
/* On platforms with large numbers of CPUs process_cpu_topology()
* might issue an error while reading the perf.data file section
#include "machine.h"
#include "config.h"
#include <linux/ctype.h>
#include "machine.h"
#include "config.h"
#include <linux/ctype.h>
#define pr_N(n, fmt, ...) \
eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
#define pr_N(n, fmt, ...) \
eprintf(n, debug_data_convert, fmt, ##__VA_ARGS__)
err = -1;
/* perf.data session */
session = perf_session__new(&data, 0, &c.tool);
err = -1;
/* perf.data session */
session = perf_session__new(&data, 0, &c.tool);
+ if (IS_ERR(session)) {
+ err = PTR_ERR(session);
if (c.queue_size) {
ordered_events__set_alloc_size(&session->ordered_events,
if (c.queue_size) {
ordered_events__set_alloc_size(&session->ordered_events,
#include "../perf.h"
#include "arch/common.h"
#include <internal/lib.h>
#include "../perf.h"
#include "arch/common.h"
#include <internal/lib.h>
#ifdef HAVE_ZSTD_SUPPORT
static int perf_session__process_compressed_event(struct perf_session *session,
#ifdef HAVE_ZSTD_SUPPORT
static int perf_session__process_compressed_event(struct perf_session *session,
struct perf_session *perf_session__new(struct perf_data *data,
bool repipe, struct perf_tool *tool)
{
struct perf_session *perf_session__new(struct perf_data *data,
bool repipe, struct perf_tool *tool)
{
struct perf_session *session = zalloc(sizeof(*session));
if (!session)
struct perf_session *session = zalloc(sizeof(*session));
if (!session)
perf_env__init(&session->header.env);
if (data) {
perf_env__init(&session->header.env);
if (data) {
- if (perf_data__open(data))
+ ret = perf_data__open(data);
+ if (ret < 0)
goto out_delete;
session->data = data;
if (perf_data__is_read(data)) {
goto out_delete;
session->data = data;
if (perf_data__is_read(data)) {
- if (perf_session__open(session) < 0)
+ ret = perf_session__open(session);
+ if (ret < 0)
perf_evlist__init_trace_event_sample_raw(session->evlist);
/* Open the directory data. */
perf_evlist__init_trace_event_sample_raw(session->evlist);
/* Open the directory data. */
- if (data->is_dir && perf_data__open_dir(data))
+ if (data->is_dir) {
+ ret = perf_data__open_dir(data);
+ if (ret)
}
} else {
session->machines.host.env = &perf_env;
}
} else {
session->machines.host.env = &perf_env;
out_delete:
perf_session__delete(session);
out:
out_delete:
perf_session__delete(session);
out:
}
static void perf_session__delete_threads(struct perf_session *session)
}
static void perf_session__delete_threads(struct perf_session *session)