From: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Thomas-Mich Richter <tmricht@linux.vnet.ibm.com>,
Michael Petlan <mpetlan@redhat.com>, Jiri Olsa <jolsa@redhat.com>,
linux-perf-users@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 2/3 v2] perf trace: Introduce errno_to_name()
Date: Thu, 7 Dec 2017 16:00:10 +0100 [thread overview]
Message-ID: <1512658810-7874-1-git-send-email-brueckner@linux.vnet.ibm.com> (raw)
In-Reply-To: <20171207144846.GB6458@kernel.org>
Introduce an errno_to_name() function to return the name of a
give errno number as string.
With this change, the dependency to libaudit can be removed for
architectures that support syscall tables. Hence, remove the
audit_errno_to_name() call in builtin-trace.c and just link
util/syscalltbl.c against libaudit. A follow-up commit could
then clean-up this dependency with respect to the syscall table.
The errno name strings are generated by util/generate-errno-names.sh
script and saved as util/errno-names.h.
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
---
tools/perf/.gitignore | 1 +
tools/perf/Makefile.config | 2 +-
tools/perf/Makefile.perf | 12 ++++++++++--
tools/perf/builtin-trace.c | 17 ++++++++++++++---
tools/perf/util/generate-errno-names.sh | 32 ++++++++++++++++++++++++++++++++
5 files changed, 58 insertions(+), 6 deletions(-)
create mode 100755 tools/perf/util/generate-errno-names.sh
diff --git a/tools/perf/.gitignore b/tools/perf/.gitignore
index 643cc4ba..4e022f9 100644
--- a/tools/perf/.gitignore
+++ b/tools/perf/.gitignore
@@ -14,6 +14,7 @@ perf*.1
perf*.xml
perf*.html
common-cmds.h
+errno-names.h
perf.data
perf.data.old
output.svg
diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index ab16aab..d8447b1 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -251,7 +251,7 @@ INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
-# $(obj-perf) for generated common-cmds.h
+# $(obj-perf) for generated common-cmds.h and errno-names.h
# $(obj-perf)/util for generated bison/flex headers
ifneq ($(OUTPUT),)
INC_FLAGS += -I$(obj-perf)/util
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 68cf136..82aed33d 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -518,6 +518,12 @@ $(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt
$(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt)
$(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@
+$(OUTPUT)util/errno-names.h: util/generate-errno-names.sh
+ $(QUIET_GEN). util/generate-errno-names.sh \
+ $(srctree)/include/uapi/asm-generic/errno-base.h \
+ $(srctree)/include/uapi/asm-generic/errno.h \
+ > $@+ && mv $@+ $@
+
$(SCRIPTS) : % : %.sh
$(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@'
@@ -565,7 +571,8 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc
$(vhost_virtio_ioctl_array) \
$(madvise_behavior_array) \
$(perf_ioctl_array) \
- $(prctl_option_array)
+ $(prctl_option_array) \
+ $(OUTPUT)util/errno-names.h
$(OUTPUT)%.o: %.c prepare FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@
@@ -847,7 +854,8 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea
$(OUTPUT)$(kcmp_type_array) \
$(OUTPUT)$(vhost_virtio_ioctl_array) \
$(OUTPUT)$(perf_ioctl_array) \
- $(OUTPUT)$(prctl_option_array)
+ $(OUTPUT)$(prctl_option_array) \
+ $(OUTPUT)util/errno-names.h
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
#
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 84debdb..04af6a1 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -42,17 +42,16 @@
#include "string2.h"
#include "syscalltbl.h"
#include "rb_resort.h"
+#include "util/errno-names.h"
#include <errno.h>
#include <inttypes.h>
-#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
#include <poll.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <linux/err.h>
#include <linux/filter.h>
-#include <linux/audit.h>
#include <linux/kernel.h>
#include <linux/random.h>
#include <linux/stringify.h>
@@ -1659,6 +1658,18 @@ static int trace__fprintf_callchain(struct trace *trace, struct perf_sample *sam
return sample__fprintf_callchain(sample, 38, print_opts, &callchain_cursor, trace->output);
}
+static const char *errno_to_name(int err)
+{
+ switch (err) {
+#define ERRNO_NAME_MAP(_err, _num) case _num: return #_err;
+ ALL_ERRNO_NAME_MAPPINGS
+#undef ERRNO_NAME_MAP
+ default:
+ return "(unknown)";
+ break;
+ };
+}
+
static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
union perf_event *event __maybe_unused,
struct perf_sample *sample)
@@ -1729,7 +1740,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
errno_print: {
char bf[STRERR_BUFSIZE];
const char *emsg = str_error_r(-ret, bf, sizeof(bf)),
- *e = audit_errno_to_name(-ret);
+ *e = errno_to_name(-ret);
fprintf(trace->output, ") = -1 %s %s", e, emsg);
}
diff --git a/tools/perf/util/generate-errno-names.sh b/tools/perf/util/generate-errno-names.sh
new file mode 100755
index 0000000..6c114a8
--- /dev/null
+++ b/tools/perf/util/generate-errno-names.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+#
+# Generate errno names header file
+#
+# Copyright IBM Corp. 2017
+# Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
+
+infiles="$@"
+tmpfile=$(mktemp -t generate-errno-names.XXXXXXXXX)
+
+trap 'rm -f $tmpfile' 0
+
+grep -hE '^#define[[:blank:]]+([^[:blank:]]+)[[:blank:]]+([[:digit:]]+).*' $infiles \
+ |awk '{ print $2", "$3; }' \
+ |sort -t, -k2 -nu \
+ |sed -e 's/^/\tERRNO_NAME_MAP(/' -e 's/$/)/' \
+ > $tmpfile
+
+cat <<EoHeader
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _UTIL_ERRNO_NAMES_H
+#define _UTIL_ERRNO_NAMES_H
+
+#define ALL_ERRNO_NAME_MAPPINGS \\
+EoHeader
+head -n -1 $tmpfile |sed -e 's/$/ \\/'
+tail -1 $tmpfile
+
+cat <<EoFooter
+#endif /* _UTIL_ERRNO_NAMES_H */
+EoFooter
--
1.8.3.1
next prev parent reply other threads:[~2017-12-07 15:00 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 8:27 [PATCH 0/3] perf: generate s390 syscall table and remove auditlibs dependency Hendrik Brueckner
2017-12-07 8:27 ` [PATCH 1/3] perf s390: generate system call table from asm/unistd.h Hendrik Brueckner
2017-12-07 15:30 ` Arnaldo Carvalho de Melo
2017-12-07 17:37 ` Arnaldo Carvalho de Melo
2017-12-11 9:06 ` Hendrik Brueckner
2017-12-11 14:19 ` Arnaldo Carvalho de Melo
2017-12-07 8:28 ` [PATCH 2/3] perf: introduce errno_to_name() function Hendrik Brueckner
2017-12-07 8:37 ` [PATCH 2/3] fixup! " Hendrik Brueckner
2017-12-07 14:48 ` Arnaldo Carvalho de Melo
2017-12-07 15:00 ` Hendrik Brueckner [this message]
2017-12-07 17:52 ` [PATCH 2/3 v2] perf trace: Introduce errno_to_name() Arnaldo Carvalho de Melo
2017-12-11 11:32 ` Hendrik Brueckner
2017-12-11 15:00 ` Arnaldo Carvalho de Melo
2017-12-07 8:28 ` [PATCH 3/3] perf trace: no longer require auditlibs if syscall tables are present Hendrik Brueckner
2017-12-07 17:53 ` Arnaldo Carvalho de Melo
2017-12-11 9:35 ` Hendrik Brueckner
2017-12-07 15:29 ` [PATCH 0/3] perf: generate s390 syscall table and remove auditlibs dependency 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=1512658810-7874-1-git-send-email-brueckner@linux.vnet.ibm.com \
--to=brueckner@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=jolsa@redhat.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=mpetlan@redhat.com \
--cc=tmricht@linux.vnet.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).