From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Jiri Olsa <jolsa@kernel.org>, LKML <linux-kernel@vger.kernel.org>,
kernel-team@lge.com
Subject: [PATCH 18/23] perf script: Use pr_err() for error messages
Date: Wed, 8 Mar 2017 00:08:46 +0900 [thread overview]
Message-ID: <20170307150851.22304-19-namhyung@kernel.org> (raw)
In-Reply-To: <20170307150851.22304-1-namhyung@kernel.org>
There are many open calls to fprintf() for error logging. use pr_err()
instead so that they can be treated at once (e.g. with -q option).
Also convert perror() to pr_err() + str_error_r().
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/builtin-script.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index c0783b4f7b6c..d1c95f0b8a0f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1394,14 +1394,14 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
if (script) {
len = script - str;
if (len >= PATH_MAX) {
- fprintf(stderr, "invalid language specifier");
+ pr_err("invalid language specifier");
return -1;
}
strncpy(spec, str, len);
spec[len] = '\0';
scripting_ops = script_spec__lookup(spec);
if (!scripting_ops) {
- fprintf(stderr, "invalid language specifier");
+ pr_err("invalid language specifier");
return -1;
}
script++;
@@ -1409,12 +1409,12 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
script = str;
ext = strrchr(script, '.');
if (!ext) {
- fprintf(stderr, "invalid script extension");
+ pr_err("invalid script extension");
return -1;
}
scripting_ops = script_spec__lookup(++ext);
if (!scripting_ops) {
- fprintf(stderr, "invalid script extension");
+ pr_err("invalid script extension");
return -1;
}
}
@@ -1472,8 +1472,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
} else {
tok = str;
if (strlen(str) == 0) {
- fprintf(stderr,
- "Cannot set fields to 'none' for all event types.\n");
+ pr_err("Cannot set fields to 'none' for all event types.\n");
rc = -EINVAL;
goto out;
}
@@ -1498,7 +1497,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
continue;
}
if (i == imax) {
- fprintf(stderr, "Invalid field requested.\n");
+ pr_err("Invalid field requested.\n");
rc = -EINVAL;
goto out;
}
@@ -1516,7 +1515,7 @@ static int parse_output_fields(const struct option *opt __maybe_unused,
}
} else {
if (output[type].invalid_fields & all_output_options[i].field) {
- fprintf(stderr, "\'%s\' not valid for %s events.\n",
+ pr_err("\'%s\' not valid for %s events.\n",
all_output_options[i].str, event_type(type));
rc = -EINVAL;
@@ -1722,8 +1721,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
scripts_dir = opendir(scripts_path);
if (!scripts_dir) {
- fprintf(stdout,
- "open(%s) failed.\n"
+ pr_err("open(%s) failed.\n"
"Check \"PERF_EXEC_PATH\" env to set scripts dir.\n",
scripts_path);
exit(-1);
@@ -2205,6 +2203,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"perf script [<options>] <top-script> [script-args]",
NULL
};
+ char errbuf[STRERR_BUFSIZE];
setup_scripting();
@@ -2223,8 +2222,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
if (argc > 1 && !strncmp(argv[0], "rep", strlen("rep"))) {
rep_script_path = get_script_path(argv[1], REPORT_SUFFIX);
if (!rep_script_path) {
- fprintf(stderr,
- "Please specify a valid report script"
+ pr_err("Please specify a valid report script"
"(see 'perf script -l' for listing)\n");
return -1;
}
@@ -2267,13 +2265,15 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
}
if (pipe(live_pipe) < 0) {
- perror("failed to create pipe");
+ pr_err("failed to create pipe: %s\n",
+ str_error_r(errno, errbuf, sizeof(errbuf)));
return -1;
}
pid = fork();
if (pid < 0) {
- perror("failed to fork");
+ pr_err("failed to fork: %s\n",
+ str_error_r(errno, errbuf, sizeof(errbuf)));
return -1;
}
@@ -2424,8 +2424,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
int input;
if (output_set_by_user()) {
- fprintf(stderr,
- "custom fields not supported for generated scripts");
+ pr_err("custom fields not supported for generated scripts");
err = -EINVAL;
goto out_delete;
}
@@ -2433,24 +2432,26 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
input = open(file.path, O_RDONLY); /* input_name */
if (input < 0) {
err = -errno;
- perror("failed to open file");
+ pr_err("failed to open file: %s\n",
+ str_error_r(errno, errbuf, sizeof(errbuf)));
goto out_delete;
}
err = fstat(input, &perf_stat);
if (err < 0) {
- perror("failed to stat file");
+ pr_err("failed to stat file: %s\n",
+ str_error_r(errno, errbuf, sizeof(errbuf)));
goto out_delete;
}
if (!perf_stat.st_size) {
- fprintf(stderr, "zero-sized file, nothing to do!\n");
+ pr_err("zero-sized file, nothing to do!\n");
goto out_delete;
}
scripting_ops = script_spec__lookup(generate_script_lang);
if (!scripting_ops) {
- fprintf(stderr, "invalid language specifier");
+ pr_err("invalid language specifier");
err = -ENOENT;
goto out_delete;
}
--
2.11.0
next prev parent reply other threads:[~2017-03-07 15:38 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-07 15:08 [PATCHSET 00/23] perf tools: Add -q/--quiet option Namhyung Kim
2017-03-07 15:08 ` [PATCH 01/23] perf report: Hide tip message when -q option is given Namhyung Kim
2017-03-07 15:24 ` Arnaldo Carvalho de Melo
2017-03-15 18:34 ` [tip:perf/core] " tip-bot for Namhyung Kim
2017-03-07 15:08 ` [PATCH 02/23] perf buildid-cache: Add -q/--quiet option Namhyung Kim
2017-03-07 15:28 ` Arnaldo Carvalho de Melo
2017-03-07 16:07 ` Namhyung Kim
2017-03-07 15:08 ` [PATCH 03/23] perf buildid-list: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 04/23] perf c2c: Fix help message of --stats option Namhyung Kim
2017-03-15 18:35 ` [tip:perf/core] perf c2c: Clarify " tip-bot for Namhyung Kim
2017-03-07 15:08 ` [PATCH 05/23] perf c2c: Fix display bug when using pipe Namhyung Kim
2017-03-15 18:35 ` [tip:perf/core] " tip-bot for Namhyung Kim
2017-03-07 15:08 ` [PATCH 06/23] perf c2c: Add -q/--quiet option Namhyung Kim
2017-03-07 15:08 ` [PATCH 07/23] perf data: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 08/23] perf evlist: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 09/23] perf ftrace: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 10/23] perf inject: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 11/23] perf kallsyms: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 12/23] perf kmem: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 13/23] perf kvm: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 14/23] perf list: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 15/23] perf lock: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 16/23] perf mem: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 17/23] perf sched: " Namhyung Kim
2017-03-07 15:08 ` Namhyung Kim [this message]
2017-03-07 15:08 ` [PATCH 19/23] perf script: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 20/23] perf stat: Use pr_err() for error messages Namhyung Kim
2017-03-07 15:08 ` [PATCH 21/23] perf stat: Add -q/--quiet option Namhyung Kim
2017-03-07 15:08 ` [PATCH 22/23] perf top: " Namhyung Kim
2017-03-07 15:08 ` [PATCH 23/23] perf trace: " Namhyung Kim
2017-03-07 15:20 ` [PATCHSET 00/23] perf tools: " Jiri Olsa
2017-03-07 15:35 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170307150851.22304-19-namhyung@kernel.org \
--to=namhyung@kernel.org \
--cc=acme@kernel.org \
--cc=jolsa@kernel.org \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome