--- v13
+++ v20
@@ -69,7 +69,8 @@
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
-
+Acked-by: Jiri Olsa <jolsa@redhat.com>
+---
v2: Address review feedback. Rename option to --event-files
v3: Add JSON example
v4: Update manpages.
@@ -99,26 +100,39 @@
- [Jiri Olsa] Be silient if arch doesn't have JSON files
- Also silence 'jevents' when parsing JSON files unless V=1 is
specified during build. Cleanup error messages.
+
+v14:- - [Jiri Olsa] Fix compile error with DEBUG=1; drop unlink() and
+ use "w" mode with fopen(); simplify file_name_to_table_name()
+
+v15: - Fix minor conflict in tools/perf/Makefile.perf when rebasing
+ to recent perf/core.
+
+v16: - Rebase to upstream; fix conflicts in tools/perf/Makefile.perf
+
+v18: - Rebase to upstream; fix conflicts in tools/perf/Makefile.perf
+
+v20: Rebase to upstream; rename a local variable to 'ldirname' to avoid
+ collision with the dirname().
---
- tools/perf/Makefile.perf | 25 +-
- tools/perf/pmu-events/Build | 11 +
- tools/perf/pmu-events/jevents.c | 692 ++++++++++++++++++++++++++++++++++++
- tools/perf/pmu-events/jevents.h | 17 +
- tools/perf/pmu-events/json.h | 3 +
- tools/perf/pmu-events/pmu-events.h | 35 ++
- 6 files changed, 779 insertions(+), 4 deletions(-)
+ tools/perf/Makefile.perf | 26 +-
+ tools/perf/pmu-events/Build | 11 +
+ tools/perf/pmu-events/jevents.c | 686 +++++++++++++++++++++++++++++++++++++
+ tools/perf/pmu-events/jevents.h | 17 +
+ tools/perf/pmu-events/json.h | 3 +
+ tools/perf/pmu-events/pmu-events.h | 35 ++
+ 6 files changed, 775 insertions(+), 3 deletions(-)
create mode 100644 tools/perf/pmu-events/Build
create mode 100644 tools/perf/pmu-events/jevents.c
create mode 100644 tools/perf/pmu-events/jevents.h
create mode 100644 tools/perf/pmu-events/pmu-events.h
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
-index 5816a3b..6a50fc1 100644
+index bde8cba..d7caa76 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
-@@ -272,14 +272,29 @@ strip: $(PROGRAMS) $(OUTPUT)perf
-
- PERF_IN := $(OUTPUT)perf-in.o
+@@ -343,12 +343,29 @@ PERF_IN := $(OUTPUT)perf-in.o
+ export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX AWK
+ include $(srctree)/tools/build/Makefile.include
+JEVENTS := $(OUTPUT)pmu-events/jevents
+JEVENTS_IN := $(OUTPUT)pmu-events/jevents-in.o
@@ -126,14 +140,12 @@
+
+export JEVENTS
+
- export srctree OUTPUT RM CC LD AR CFLAGS V BISON FLEX
- build := -f $(srctree)/tools/build/Makefile.build dir=. obj
-
- $(PERF_IN): $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h FORCE
++build := -f $(srctree)/tools/build/Makefile.build dir=. obj
++
+ $(PERF_IN): prepare FORCE
$(Q)$(MAKE) $(build)=perf
--$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN)
-- $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(LIBS) -o $@
+-$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
+$(JEVENTS_IN): FORCE
+ $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=jevents
+
@@ -143,12 +155,14 @@
+$(PMU_EVENTS_IN): $(JEVENTS) FORCE
+ $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events obj=pmu-events
+
-+$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN)
-+ $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@
++$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBTRACEEVENT_DYNAMIC_LIST)
+ $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(LIBTRACEEVENT_DYNAMIC_LIST_LDFLAGS) \
+- $(PERF_IN) $(LIBS) -o $@
++ $(PERF_IN) $(PMU_EVENTS_IN) $(LIBS) -o $@
- $(GTK_IN): FORCE
+ $(GTK_IN): fixdep FORCE
$(Q)$(MAKE) $(build)=gtk
-@@ -308,6 +323,8 @@ perf.spec $(SCRIPTS) \
+@@ -377,6 +394,8 @@ perf.spec $(SCRIPTS) \
ifneq ($(OUTPUT),)
%.o: $(OUTPUT)%.o
@echo " # Redirected target $@ => $(OUTPUT)$@"
@@ -157,20 +171,22 @@
util/%.o: $(OUTPUT)util/%.o
@echo " # Redirected target $@ => $(OUTPUT)$@"
bench/%.o: $(OUTPUT)bench/%.o
-@@ -535,8 +552,8 @@ clean: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean config-clean
+@@ -632,10 +651,11 @@ clean:: $(LIBTRACEEVENT)-clean $(LIBAPI)-clean $(LIBBPF)-clean $(LIBSUBCMD)-clea
$(call QUIET_CLEAN, core-objs) $(RM) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf-with-kcore $(LANG_BINDINGS)
- $(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
- $(Q)$(RM) .config-detected
+ $(Q)find $(if $(OUTPUT),$(OUTPUT),.) -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+ $(Q)$(RM) $(OUTPUT).config-detected
- $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32
-- $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex*
+ $(call QUIET_CLEAN, core-progs) $(RM) $(ALL_PROGRAMS) perf perf-read-vdso32 perf-read-vdsox32 $(OUTPUT)pmu-events/jevents $(srctree)/tools/perf/pmu-events/pmu-events.c
-+ $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* $(OUTPUT)pmu-events/pmu-events.c
+ $(call QUIET_CLEAN, core-gen) $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)FEATURE-DUMP $(OUTPUT)util/*-bison* $(OUTPUT)util/*-flex* \
+ $(OUTPUT)util/intel-pt-decoder/inat-tables.c $(OUTPUT)fixdep \
+ $(OUTPUT)tests/llvm-src-{base,kbuild,prologue,relocation}.c
++ $(OUTPUT)pmu-events/pmu-events.c
$(QUIET_SUBDIR0)Documentation $(QUIET_SUBDIR1) clean
$(python-clean)
diff --git a/tools/perf/pmu-events/Build b/tools/perf/pmu-events/Build
new file mode 100644
-index 0000000..048fa34
+index 0000000..d2f3430
--- /dev/null
+++ b/tools/perf/pmu-events/Build
@@ -0,0 +1,11 @@
@@ -178,7 +194,7 @@
+pmu-events-y += pmu-events.o
+JDIR = pmu-events/arch/$(ARCH)
+JSON = $(shell [ -d $(JDIR) ] && \
-+ find $(JDIR) -name '*.json' -o -name 'mapfile*')
++ find $(JDIR) -name '*.json' -o -name 'mapfile.csv')
+#
+# Locate/process JSON files in pmu-events/arch/
+# directory and create tables in pmu-events.c.
@@ -187,10 +203,10 @@
+ $(Q)$(call echo-cmd,gen)$(JEVENTS) $(ARCH) pmu-events/arch $(OUTPUT)pmu-events/pmu-events.c $(V)
diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c
new file mode 100644
-index 0000000..ab83d85
+index 0000000..aeafa82
--- /dev/null
+++ b/tools/perf/pmu-events/jevents.c
-@@ -0,0 +1,692 @@
+@@ -0,0 +1,686 @@
+#define _XOPEN_SOURCE 500 /* needed for nftw() */
+
+/* Parse event JSON files */
@@ -244,7 +260,7 @@
+#define __maybe_unused __attribute__((unused))
+#endif
+
-+int verbose = 0;
++int verbose;
+char *prog;
+
+int eprintf(int level, int var, const char *fmt, ...)
@@ -517,40 +533,37 @@
+
+static char *file_name_to_table_name(char *fname)
+{
-+ unsigned int i, j;
++ unsigned int i;
++ int n;
+ int c;
-+ int n = 1024; /* use max variable length? */
+ char *tblname;
-+ char *p;
-+
-+ tblname = malloc(n);
-+ if (!tblname)
++
++ /*
++ * Ensure tablename starts with alphabetic character.
++ * Derive rest of table name from basename of the JSON file,
++ * replacing hyphens and stripping out .json suffix.
++ */
++ n = asprintf(&tblname, "pme_%s", basename(fname));
++ if (n < 0) {
++ pr_info("%s: asprintf() error %s for file %s\n", prog,
++ strerror(errno), fname);
+ return NULL;
-+
-+ p = basename(fname);
-+
-+ memset(tblname, 0, n);
-+
-+ /* Ensure table name starts with an alphabetic char */
-+ strcpy(tblname, "pme_");
-+
-+ n = strlen(fname) + strlen(tblname);
-+ n = min(1024, n);
-+
-+ for (i = 0, j = strlen(tblname); i < strlen(fname); i++, j++) {
-+ c = p[i];
-+ if (isalnum(c) || c == '_')
-+ tblname[j] = c;
-+ else if (c == '-')
-+ tblname[j] = '_';
++ }
++
++ for (i = 0; i < strlen(tblname); i++) {
++ c = tblname[i];
++
++ if (c == '-')
++ tblname[i] = '_';
+ else if (c == '.') {
-+ tblname[j] = '\0';
++ tblname[i] = '\0';
+ break;
-+ } else {
++ } else if (!isalnum(c) && c != '_') {
+ pr_err("%s: Invalid character '%c' in file name %s\n",
-+ prog, c, p);
++ prog, c, basename(fname));
+ free(tblname);
-+ return NULL;
++ tblname = NULL;
++ break;
+ }
+ }
+
@@ -617,7 +630,7 @@
+{
+ int n = 16384;
+ FILE *mapfp;
-+ char *save;
++ char *save = NULL;
+ char *line, *p;
+ int line_num;
+ char *tblname;
@@ -697,10 +710,8 @@
+
+ pr_info("%s: Creating empty pmu_events_map[] table\n", prog);
+
-+ /* Unlink file to clear any partial writes to it */
-+ unlink(output_file);
-+
-+ outfp = fopen(output_file, "a");
++ /* Truncate file to clear any partial writes to it */
++ outfp = fopen(output_file, "w");
+ if (!outfp) {
+ perror("fopen()");
+ _Exit(1);
@@ -813,7 +824,7 @@
+ int rc;
+ int flags;
+ int maxfds;
-+ char dirname[PATH_MAX];
++ char ldirname[PATH_MAX];
+
+ const char *arch;
+ const char *output_file;
@@ -832,8 +843,7 @@
+ if (argc > 4)
+ verbose = atoi(argv[4]);
+
-+ unlink(output_file);
-+ eventsfp = fopen(output_file, "a");
++ eventsfp = fopen(output_file, "w");
+ if (!eventsfp) {
+ pr_err("%s Unable to create required file %s (%s)\n",
+ prog, output_file, strerror(errno));
@@ -843,7 +853,7 @@
+ /* Include pmu-events.h first */
+ fprintf(eventsfp, "#include \"../../pmu-events/pmu-events.h\"\n");
+
-+ sprintf(dirname, "%s/%s", start_dirname, arch);
++ sprintf(ldirname, "%s/%s", start_dirname, arch);
+
+ /*
+ * The mapfile allows multiple CPUids to point to the same JSON file,
@@ -858,9 +868,9 @@
+
+ maxfds = get_maxfds();
+ mapfile = NULL;
-+ rc = nftw(dirname, process_one_file, maxfds, flags);
++ rc = nftw(ldirname, process_one_file, maxfds, flags);
+ if (rc && verbose) {
-+ pr_info("%s: Error walking file tree %s\n", prog, dirname);
++ pr_info("%s: Error walking file tree %s\n", prog, ldirname);
+ goto empty_map;
+ } else if (rc) {
+ goto empty_map;
@@ -962,4 +972,4 @@
+
+#endif
--
-1.7.9.5
+2.5.3