mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 20/23] perf stat: Use pr_err() for error messages
Date: Wed,  8 Mar 2017 00:08:48 +0900	[thread overview]
Message-ID: <20170307150851.22304-21-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-stat.c | 52 ++++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index f53f449d864d..ee7190da9b6e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -555,7 +555,8 @@ static int __run_perf_stat(int argc, const char **argv)
 	if (forks) {
 		if (perf_evlist__prepare_workload(evsel_list, &target, argv, is_pipe,
 						  workload_exec_failed_signal) < 0) {
-			perror("failed to prepare workload");
+			pr_err("failed to prepare workload: %s\n",
+			       str_error_r(errno, msg, sizeof(msg)));
 			return -1;
 		}
 		child_pid = evsel_list->workload.pid;
@@ -608,14 +609,14 @@ static int __run_perf_stat(int argc, const char **argv)
 	}
 
 	if (perf_evlist__apply_filters(evsel_list, &counter)) {
-		error("failed to set filter \"%s\" on event %s with %d (%s)\n",
+		pr_err("failed to set filter \"%s\" on event %s with %d (%s)\n",
 			counter->filter, perf_evsel__name(counter), errno,
 			str_error_r(errno, msg, sizeof(msg)));
 		return -1;
 	}
 
 	if (perf_evlist__apply_drv_configs(evsel_list, &counter, &err_term)) {
-		error("failed to set config \"%s\" on event %s with %d (%s)\n",
+		pr_err("failed to set config \"%s\" on event %s with %d (%s)\n",
 		      err_term->val.drv_cfg, perf_evsel__name(counter), errno,
 		      str_error_r(errno, msg, sizeof(msg)));
 		return -1;
@@ -1725,18 +1726,21 @@ static int perf_stat__get_core_cached(struct cpu_map *map, int idx)
 static int perf_stat_init_aggr_mode(void)
 {
 	int nr;
+	char errbuf[STRERR_BUFSIZE];
 
 	switch (stat_config.aggr_mode) {
 	case AGGR_SOCKET:
 		if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) {
-			perror("cannot build socket map");
+			pr_err("cannot build socket map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_socket_cached;
 		break;
 	case AGGR_CORE:
 		if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) {
-			perror("cannot build core map");
+			pr_err("cannot build core map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_core_cached;
@@ -1835,18 +1839,21 @@ static int perf_stat__get_core_file(struct cpu_map *map, int idx)
 static int perf_stat_init_aggr_mode_file(struct perf_stat *st)
 {
 	struct perf_env *env = &st->session->header.env;
+	char errbuf[STRERR_BUFSIZE];
 
 	switch (stat_config.aggr_mode) {
 	case AGGR_SOCKET:
 		if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) {
-			perror("cannot build socket map");
+			pr_err("cannot build socket map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_socket_file;
 		break;
 	case AGGR_CORE:
 		if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) {
-			perror("cannot build core map");
+			pr_err("cannot build core map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		aggr_get_id = perf_stat__get_core_file;
@@ -2042,7 +2049,7 @@ static int add_default_attributes(void)
 		else
 			err = parse_events(evsel_list, transaction_limited_attrs, NULL);
 		if (err) {
-			fprintf(stderr, "Cannot set up transaction events\n");
+			pr_err("Cannot set up transaction events\n");
 			return -1;
 		}
 		return 0;
@@ -2075,14 +2082,13 @@ static int add_default_attributes(void)
 				arch_topdown_group_warn();
 			err = parse_events(evsel_list, str, NULL);
 			if (err) {
-				fprintf(stderr,
-					"Cannot set up top down events %s: %d\n",
+				pr_err("Cannot set up top down events %s: %d\n",
 					str, err);
 				free(str);
 				return -1;
 			}
 		} else {
-			fprintf(stderr, "System does not support topdown\n");
+			pr_err("System does not support topdown\n");
 			return -1;
 		}
 		free(str);
@@ -2390,6 +2396,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	FILE *output = stderr;
 	unsigned int interval;
 	const char * const stat_subcommands[] = { "record", "report" };
+	char errbuf[STRERR_BUFSIZE];
 
 	setlocale(LC_ALL, "");
 
@@ -2426,24 +2433,24 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		output = NULL;
 
 	if (output_name && output_fd) {
-		fprintf(stderr, "cannot use both --output and --log-fd\n");
+		pr_err("cannot use both --output and --log-fd\n");
 		parse_options_usage(stat_usage, stat_options, "o", 1);
 		parse_options_usage(NULL, stat_options, "log-fd", 0);
 		goto out;
 	}
 
 	if (metric_only && stat_config.aggr_mode == AGGR_THREAD) {
-		fprintf(stderr, "--metric-only is not supported with --per-thread\n");
+		pr_err("--metric-only is not supported with --per-thread\n");
 		goto out;
 	}
 
 	if (metric_only && run_count > 1) {
-		fprintf(stderr, "--metric-only is not supported with -r\n");
+		pr_err("--metric-only is not supported with -r\n");
 		goto out;
 	}
 
 	if (output_fd < 0) {
-		fprintf(stderr, "argument to --log-fd must be a > 0\n");
+		pr_err("argument to --log-fd must be a > 0\n");
 		parse_options_usage(stat_usage, stat_options, "log-fd", 0);
 		goto out;
 	}
@@ -2454,7 +2461,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 
 		output = fopen(output_name, mode);
 		if (!output) {
-			perror("failed to create output file");
+			pr_err("failed to create output file: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -1;
 		}
 		clock_gettime(CLOCK_REALTIME, &tm);
@@ -2463,7 +2471,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 		mode = append_file ? "a" : "w";
 		output = fdopen(output_fd, mode);
 		if (!output) {
-			perror("Failed opening logfd");
+			pr_err("Failed opening logfd: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			return -errno;
 		}
 	}
@@ -2476,7 +2485,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (csv_output) {
 		/* User explicitly passed -B? */
 		if (big_num_opt == 1) {
-			fprintf(stderr, "-B option not supported with -x\n");
+			pr_err("-B option not supported with -x\n");
 			parse_options_usage(stat_usage, stat_options, "B", 1);
 			parse_options_usage(NULL, stat_options, "x", 1);
 			goto out;
@@ -2497,7 +2506,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 
 	if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) {
-		fprintf(stderr, "The --per-thread option is only available "
+		pr_err("The --per-thread option is only available "
 			"when monitoring via -p -t options.\n");
 		parse_options_usage(NULL, stat_options, "p", 1);
 		parse_options_usage(NULL, stat_options, "t", 1);
@@ -2511,7 +2520,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (((stat_config.aggr_mode != AGGR_GLOBAL &&
 	      stat_config.aggr_mode != AGGR_THREAD) || nr_cgroups) &&
 	    !target__has_cpu(&target)) {
-		fprintf(stderr, "both cgroup and no-aggregation "
+		pr_err("both cgroup and no-aggregation "
 			"modes only available in system-wide mode\n");
 
 		parse_options_usage(stat_usage, stat_options, "G", 1);
@@ -2531,7 +2540,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused)
 			parse_options_usage(stat_usage, stat_options, "p", 1);
 			parse_options_usage(NULL, stat_options, "t", 1);
 		} else if (target__has_cpu(&target)) {
-			perror("failed to parse CPUs map");
+			pr_err("failed to parse CPUs map: %s\n",
+			       str_error_r(errno, errbuf, sizeof(errbuf)));
 			parse_options_usage(stat_usage, stat_options, "C", 1);
 			parse_options_usage(NULL, stat_options, "a", 1);
 		}
-- 
2.11.0

  parent reply	other threads:[~2017-03-07 15:22 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 ` [PATCH 18/23] perf script: Use pr_err() for error messages Namhyung Kim
2017-03-07 15:08 ` [PATCH 19/23] perf script: Add -q/--quiet option Namhyung Kim
2017-03-07 15:08 ` Namhyung Kim [this message]
2017-03-07 15:08 ` [PATCH 21/23] perf stat: " 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-21-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

all inboxes | Powered by JetHome®