Skip to contentSkip to conversation

tools: Unify perf and trace-cmd trace event format parsing v3

PATCH In review Frederic Weisbecker 4 participants 25 messages Apr 25, 2012 – May 21, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover tools: Unify perf and trace-cmd trace event format parsing v3

Hi,

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Default target is a static library in tools/libtraceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

Thanks.

Julia Lawall (1):
perf/events: Correct size given to memset

Steven Rostedt (10):
perf: Separate out trace-cmd parse-events from perf files tools/events: Add files to create libtraceevent.a
perf: Build libtraceevent.a
events: Update tools/lib/traceevent to work with perf
perf: Have perf use the new libtraceevent.a library perf/events: Add flag to produce nsec output
parse-events: Let pevent_free() take a NULL pointer
parse-events: Allow '*' and '/' operations in TP_printk
parse-event: Fix memset pointer size bug in handle
parse-events: Rename struct record to struct pevent_record

Tom Zanussi (1):
perf/events: Add flag/symbol format_flags

Vaibhav Nagarnaik (3):
parse-events: Handle invalid opcode parsing gracefully
parse-events: Handle opcode parsing error
parse-events: Support '+' opcode in print format

 tools/lib/traceevent/Makefile                      |  303 ++
 tools/lib/traceevent/event-parse.c                 | 5065 ++++++++++++++++++++
 tools/lib/traceevent/event-parse.h                 |  804 ++++
 tools/lib/traceevent/event-utils.h                 |   80 +
 tools/lib/traceevent/parse-filter.c                | 2262 +++++++++
 tools/lib/traceevent/parse-utils.c                 |  110 +
 tools/lib/traceevent/trace-seq.c                   |  200 +
 tools/perf/Makefile                                |   20 +-
 tools/perf/builtin-kmem.c                          |    6 +-
 tools/perf/builtin-lock.c                          |   26 +-
 tools/perf/builtin-sched.c                         |   42 +-
 tools/perf/builtin-script.c                        |    2 +-
 .../util/scripting-engines/trace-event-python.c    |   16 +-
 tools/perf/util/trace-event-info.c                 |    4 +-
 tools/perf/util/trace-event-parse.c                | 3220 +------------
 tools/perf/util/trace-event-read.c                 |   44 +-
 tools/perf/util/trace-event.h                      |  269 +-
 tools/scripts/Makefile.include                     |    1 +
 18 files changed, 9161 insertions(+), 3313 deletions(-)
 create mode 100644 tools/lib/traceevent/Makefile
 create mode 100644 tools/lib/traceevent/event-parse.c
 create mode 100644 tools/lib/traceevent/event-parse.h
 create mode 100644 tools/lib/traceevent/event-utils.h
 create mode 100644 tools/lib/traceevent/parse-filter.c
 create mode 100644 tools/lib/traceevent/parse-utils.c
 create mode 100644 tools/lib/traceevent/trace-seq.c
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 1/15 perf: Separate out trace-cmd parse-events from perf files

From: Steven Rostedt <[email protected]>

Move the trace-event-parse.c code that originally came from trace-cmd into their own files. The new file will be called trace-parse-events.c, as the name of trace-cmd's file was parse-events.c too, but it conflicted with the parse-events.c file in perf that parses the command line.

This tries to update the code with mimimal changes.

Perf specific code stays in the trace-event-parse.[ch] files and the common parsing code is now in trace-parse-events.c and trace-parse-events.h.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/perf/Makefile                  |    2 +
 tools/perf/util/trace-event-parse.c  | 3135 ----------------------------------
 tools/perf/util/trace-event.h        |  275 +---
 tools/perf/util/trace-parse-events.c | 3125 +++++++++++++++++++++++++++++++++
 tools/perf/util/trace-parse-events.h |  273 +++
 5 files changed, 3405 insertions(+), 3405 deletions(-)
 create mode 100644 tools/perf/util/trace-parse-events.c
 create mode 100644 tools/perf/util/trace-parse-events.h
tools/perf/Makefile +2 -0
index e98e14c..8191023 100644
@@ -292,6 +292,7 @@ LIB_H += util/hist.h
 LIB_H += util/thread.h
 LIB_H += util/thread_map.h
 LIB_H += util/trace-event.h
+LIB_H += util/trace-parse-events.h
 LIB_H += util/probe-finder.h
 LIB_H += util/dwarf-aux.h
 LIB_H += util/probe-event.h
@@ -353,6 +354,7 @@ LIB_OBJS += $(OUTPUT)util/pmu-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
+LIB_OBJS += $(OUTPUT)util/trace-parse-events.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
tools/perf/util/trace-event-parse.c +0 -3135

2,986 lines not on this page · raw message

tools/perf/util/trace-event.h +5 -270

275 lines not on this page · raw message

tools/perf/util/trace-parse-events.c new file +3125 -0

3,125 lines not on this page · raw message

tools/perf/util/trace-parse-events.h new file +273 -0

273 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.5.4

Part of the diff is not shown here. View the raw message.

#2 lore raw

PATCH 2/15 tools/events: Add files to create libtraceevent.a

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

Copy over the files from trace-cmd to the Linux tools directory such that applications like perf and latencytrace can use the more advanced parsing code.

Because some of the file names of perf conflict with trace-cmd file names, the trace-cmd files have been renamed as follows:

parse-events.c ==> event-parse.c
parse-events.h ==> event-parse.h
utils.h ==> event-utils.h

The files have been updated to handle the changes to the header files but other than that, they are identical to what was in the trace-cmd repository. The history of these files, including authorship is available at the git repo:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git

The Makefile was also copied over, but most of it was removed to focus on the parse-events code first. The parts of the Makefile for the plugins have also been removed, but will be added back when the plugin code is copied over as well. But that may be in its own separate directory.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/Makefile       |  303 +++
 tools/lib/traceevent/event-parse.c  | 4971 +++++++++++++++++++++++++++++++++++
 tools/lib/traceevent/event-parse.h  |  806 ++++++
 tools/lib/traceevent/event-utils.h  |   64 +
 tools/lib/traceevent/parse-filter.c | 2262 ++++++++++++++++
 tools/lib/traceevent/parse-utils.c  |  110 +
 tools/lib/traceevent/trace-seq.c    |  199 ++
 7 files changed, 8715 insertions(+), 0 deletions(-)
 create mode 100644 tools/lib/traceevent/Makefile
 create mode 100644 tools/lib/traceevent/event-parse.c
 create mode 100644 tools/lib/traceevent/event-parse.h
 create mode 100644 tools/lib/traceevent/event-utils.h
 create mode 100644 tools/lib/traceevent/parse-filter.c
 create mode 100644 tools/lib/traceevent/parse-utils.c
 create mode 100644 tools/lib/traceevent/trace-seq.c
tools/lib/traceevent/Makefile new file +303 -0
new file mode 100644
index 0000000..3d69aa9
@@ -0,0 +1,303 @@
+# trace-cmd version
+EP_VERSION = 1
+EP_PATCHLEVEL = 1
+EP_EXTRAVERSION = 0
+
+# file format version
+FILE_VERSION = 6
+
+MAKEFLAGS += --no-print-directory
+
+
+# Makefiles suck: This macro sets a default value of $(2) for the
+# variable named by $(1), unless the variable has been set by
+# environment or command line. This is necessary for CC and AR
+# because make sets default values, so the simpler ?= approach
+# won't work as expected.
+define allow-override
+  $(if $(or $(findstring environment,$(origin $(1))),\
+            $(findstring command line,$(origin $(1)))),,\
+    $(eval $(1) = $(2)))
+endef
+
+# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
+$(call allow-override,CC,$(CROSS_COMPILE)gcc)
+$(call allow-override,AR,$(CROSS_COMPILE)ar)
+
+EXT = -std=gnu99
+INSTALL = install
+
+# Use DESTDIR for installing into a different root directory.
+# This is useful for building a package. The program will be
+# installed in this directory as if it was the root directory.
+# Then the build tool can move it later.
+DESTDIR ?=
+DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+
+prefix ?= /usr/local
+bindir_relative = bin
+bindir = $(prefix)/$(bindir_relative)
+man_dir = $(prefix)/share/man
+man_dir_SQ = '$(subst ','\'',$(man_dir))'
+html_install = $(prefix)/share/kernelshark/html
+html_install_SQ = '$(subst ','\'',$(html_install))'
+img_install = $(prefix)/share/kernelshark/html/images
+img_install_SQ = '$(subst ','\'',$(img_install))'
+
+export man_dir man_dir_SQ html_install html_install_SQ INSTALL
+export img_install img_install_SQ
+export DESTDIR DESTDIR_SQ
+
+# copy a bit from Linux kbuild
+
+ifeq ("$(origin V)", "command line")
+  VERBOSE = $(V)
+endif
+ifndef VERBOSE
+  VERBOSE = 0
+endif
+
+ifeq ("$(origin O)", "command line")
+  BUILD_OUTPUT := $(O)
+endif
+
+ifeq ($(BUILD_SRC),)
+ifneq ($(BUILD_OUTPUT),)
+
+define build_output
+	$(if $(VERBOSE:1=),@)$(MAKE) -C $(BUILD_OUTPUT) 	\
+	BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
+endef
+
+saved-output := $(BUILD_OUTPUT)
+BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
+$(if $(BUILD_OUTPUT),, \
+     $(error output directory "$(saved-output)" does not exist))
+
+all: sub-make
+
+gui: force
+	$(call build_output, all_cmd)
+
+$(filter-out gui,$(MAKECMDGOALS)): sub-make
+
+sub-make: force
+	$(call build_output, $(MAKECMDGOALS))
+
+
+# Leave processing to above invocation of make
+skip-makefile := 1
+
+endif # BUILD_OUTPUT
+endif # BUILD_SRC
+
+# We process the rest of the Makefile if this is the final invocation of make
+ifeq ($(skip-makefile),)
+
+srctree		:= $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
+objtree		:= $(CURDIR)
+src		:= $(srctree)
+obj		:= $(objtree)
+
+export prefix bindir src obj
+
+# Shell quotes
+bindir_SQ = $(subst ','\'',$(bindir))
+bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
+
+LIB_FILE = libtraceevent.a libtraceevent.so
+
+CONFIG_INCLUDES = 
+CONFIG_LIBS	=
+CONFIG_FLAGS	=
+
+VERSION		= $(EP_VERSION)
+PATCHLEVEL	= $(EP_PATCHLEVEL)
+EXTRAVERSION	= $(EP_EXTRAVERSION)
+
+OBJ		= $@
+N		=
+
+export Q VERBOSE
+
+EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
+
+INCLUDES = -I. -I/usr/local/include $(CONFIG_INCLUDES)
+
+# Set compile option CFLAGS if not set elsewhere
+CFLAGS ?= -g -Wall
+
+# Append required CFLAGS
+override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
+override CFLAGS += $(udis86-flags)
+
+ifeq ($(VERBOSE),1)
+  Q =
+  print_compile =
+  print_app_build =
+  print_fpic_compile =
+  print_shared_lib_compile =
+  print_plugin_obj_compile =
+  print_plugin_build =
+  print_install =
+else
+  Q = @
+  print_compile =		echo '  CC                 '$(OBJ);
+  print_app_build =		echo '  BUILD              '$(OBJ);
+  print_fpic_compile =		echo '  CC FPIC            '$(OBJ);
+  print_shared_lib_compile =	echo '  BUILD SHARED LIB   '$(OBJ);
+  print_plugin_obj_compile =	echo '  CC PLUGIN OBJ      '$(OBJ);
+  print_plugin_build =		echo '  CC PLUGI           '$(OBJ);
+  print_static_lib_build =	echo '  BUILD STATIC LIB   '$(OBJ);
+  print_install =		echo '  INSTALL     '$1'	to	$(DESTDIR_SQ)$2';
+endif
+
+do_fpic_compile =					\
+	($(print_fpic_compile)				\
+	$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
+
+do_app_build =						\
+	($(print_app_build)				\
+	$(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
+
+do_compile_shared_library =			\
+	($(print_shared_lib_compile)		\
+	$(CC) --shared $^ -o $@)
+
+do_compile_plugin_obj =				\
+	($(print_plugin_obj_compile)		\
+	$(CC) -c $(CFLAGS) -fPIC -o $@ $<)
+
+do_plugin_build =				\
+	($(print_plugin_build)			\
+	$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
+
+do_build_static_lib =				\
+	($(print_static_lib_build)		\
+	$(RM) $@;  $(AR) rcs $@ $^)
+
+
+define do_compile
+	$(print_compile)						\
+	$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
+endef
+
+$(obj)/%.o: $(src)/%.c
+	$(Q)$(call do_compile)
+
+%.o: $(src)/%.c
+	$(Q)$(call do_compile)
+
+PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o
+
+ALL_OBJS = $(PEVENT_LIB_OBJS)
+
+CMD_TARGETS = $(LIB_FILE)
+
+TARGETS = $(CMD_TARGETS)
+
+
+all: all_cmd
+
+all_cmd: $(CMD_TARGETS)
+
+libtraceevent.so: $(PEVENT_LIB_OBJS)
+	$(Q)$(do_compile_shared_library)
+
+libtraceevent.a: $(PEVENT_LIB_OBJS)
+	$(Q)$(do_build_static_lib)
+
+$(PEVENT_LIB_OBJS): %.o: $(src)/%.c
+	$(Q)$(do_fpic_compile)
+
+define make_version.h
+	(echo '/* This file is automatically generated. Do not modify. */';		\
+	echo \#define VERSION_CODE $(shell						\
+	expr $(VERSION) \* 256 + $(PATCHLEVEL));					\
+	echo '#define EXTRAVERSION ' $(EXTRAVERSION);					\
+	echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"';	\
+	echo '#define FILE_VERSION '$(FILE_VERSION);					\
+	) > $1
+endef
+
+define update_version.h
+	($(call make_version.h, [email protected]);		\
+	if [ -r $@ ] && cmp -s $@ [email protected]; then		\
+		rm -f [email protected];				\
+	else						\
+		echo '  UPDATE                 $@';	\
+		mv -f [email protected] $@;			\
+	fi);
+endef
+
+ep_version.h: force
+	$(Q)$(N)$(call update_version.h)
+
+VERSION_FILES = ep_version.h
+
+define update_dir
+	(echo $1 > [email protected];	\
+	if [ -r $@ ] && cmp -s $@ [email protected]; then		\
+		rm -f [email protected];				\
+	else						\
+		echo '  UPDATE                 $@';	\
+		mv -f [email protected] $@;			\
+	fi);
+endef
+
+## make deps
+
+all_objs := $(sort $(ALL_OBJS))
+all_deps := $(all_objs:%.o=.%.d)
+
+define check_deps
+		$(CC) -M $(CFLAGS) $< > $@;
+endef
+
+$(gui_deps): ks_version.h
+$(non_gui_deps): tc_version.h
+
+$(all_deps): .%.d: $(src)/%.c
+	$(Q)$(call check_deps)
+
+$(all_objs) : %.o : .%.d
+
+dep_includes := $(wildcard $(all_deps))
+
+ifneq ($(dep_includes),)
+ include $(dep_includes)
+endif
+
+tags:	force
+	$(RM) tags
+	find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px
+
+TAGS:	force
+	$(RM) TAGS
+	find . -name '*.[ch]' | xargs etags
+
+define do_install
+	$(print_install)				\
+	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\
+		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2';	\
+	fi;						\
+	$(INSTALL) $1 '$(DESTDIR_SQ)$2'
+endef
+
+install_lib: all_cmd install_plugins install_python
+	$(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
+
+install: install_lib
+
+clean:
+	$(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES).*.d
+	$(RM) tags TAGS
+
+endif # skip-makefile
+
+PHONY += force
+force:
+
+# Declare the contents of the .PHONY variable as phony.  We keep that
+# information in a variable so we can use it in if_changed and friends.
+.PHONY: $(PHONY)
tools/lib/traceevent/event-parse.c new file +4971 -0

2,697 lines not on this page · raw message

tools/lib/traceevent/event-parse.h new file +806 -0

806 lines not on this page · raw message

tools/lib/traceevent/event-utils.h new file +64 -0

64 lines not on this page · raw message

tools/lib/traceevent/parse-filter.c new file +2262 -0

2,262 lines not on this page · raw message

tools/lib/traceevent/parse-utils.c new file +110 -0

110 lines not on this page · raw message

tools/lib/traceevent/trace-seq.c new file +199 -0

199 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.5.4

Part of the diff is not shown here. View the raw message.

#3 lore raw

PATCH 3/15 perf: Build libtraceevent.a

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

Have building perf also build libtraceevent.a. Currently, perf does not use the code within libtraceevent.a, but it soon will.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/perf/Makefile            |   10 +++++++++-
 tools/scripts/Makefile.include |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/Makefile +9 -1
index 8191023..46150ab 100644
@@ -178,6 +178,9 @@ $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
 
 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
 
+EVENT_PARSE_DIR = ../lib/traceevent/
+LIBTRACEEVENT = $(OUTPUT)$(EVENT_PARSE_DIR)libtraceevent.a
+
 #
 # Single 'perf' binary right now:
 #
@@ -301,6 +304,7 @@ LIB_H += util/cpumap.h
 LIB_H += util/top.h
 LIB_H += $(ARCH_INCLUDE)
 LIB_H += util/cgroup.h
+LIB_H += $(EVENT_PARSE_DIR)event-parse.h
 
 LIB_OBJS += $(OUTPUT)util/abspath.o
 LIB_OBJS += $(OUTPUT)util/alias.o
@@ -695,7 +699,7 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		'-DPERF_HTML_PATH="$(htmldir_SQ)"' \
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
-$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
+$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) $(LIBTRACEEVENT)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
                $(BUILTIN_OBJS) $(LIBS) -o $@
 
@@ -801,6 +805,10 @@ $(sort $(dir $(DIRECTORY_DEPS))):
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
 
+# libparsevent.a
+$(LIBTRACEEVENT):
+	make -C $(EVENT_PARSE_DIR) $(COMMAND_O) libtraceevent.a
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
tools/scripts/Makefile.include +1 -0
index 87b55a7..bde8521 100644
@@ -1,5 +1,6 @@
 ifeq ("$(origin O)", "command line")
 	OUTPUT := $(O)/
+	COMMAND_O := O=$(O)
 endif
 
 ifneq ($(OUTPUT),)
Signature · 1 line
1.7.5.4
#4 lore raw

PATCH 4/15 events: Update tools/lib/traceevent to work with perf

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

Some of the util functions of libtraceevent.a conflict with perf, such as die(), warning() and others. Move them into event-util.h that is not included by the perf tools.

Also, as perf compiles with 'bool' the filter_arg->bool needs to be renamed to filter_arg->boolean.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c  |    1 +
 tools/lib/traceevent/event-parse.h  |   20 +++-----------------
 tools/lib/traceevent/event-utils.h  |   16 ++++++++++++++++
 tools/lib/traceevent/parse-filter.c |   32 ++++++++++++++++----------------
 tools/lib/traceevent/trace-seq.c    |    1 +
 5 files changed, 37 insertions(+), 33 deletions(-)
tools/lib/traceevent/event-parse.c +1 -0
index 47a3227..3ce75b5 100644
@@ -33,6 +33,7 @@
 #include <errno.h>
 
 #include "event-parse.h"
+#include "event-utils.h"
 
 static const char *input_buf;
 static unsigned long long input_buf_ptr;
tools/lib/traceevent/event-parse.h +3 -17
index c32d715..2e0222d 100644
@@ -167,6 +167,8 @@ enum format_flags {
 	FIELD_IS_STRING		= 8,
 	FIELD_IS_DYNAMIC	= 16,
 	FIELD_IS_LONG		= 32,
+	FIELD_IS_FLAG		= 64,
+	FIELD_IS_SYMBOLIC	= 128,
 };
 
 struct format_field {
@@ -406,22 +408,6 @@ struct pevent {
 	struct event_format *last_event;
 };
 
-/* Can be overridden */
-void die(const char *fmt, ...);
-void *malloc_or_die(unsigned int size);
-void warning(const char *fmt, ...);
-void pr_stat(const char *fmt, ...);
-void vpr_stat(const char *fmt, va_list ap);
-
-/* Always available */
-void __die(const char *fmt, ...);
-void __warning(const char *fmt, ...);
-void __pr_stat(const char *fmt, ...);
-
-void __vdie(const char *fmt, ...);
-void __vwarning(const char *fmt, ...);
-void __vpr_stat(const char *fmt, ...);
-
 static inline unsigned short
 __data2host2(struct pevent *pevent, unsigned short data)
 {
@@ -734,7 +720,7 @@ struct filter_arg_str {
 struct filter_arg {
 	enum filter_arg_type	type;
 	union {
-		struct filter_arg_boolean	bool;
+		struct filter_arg_boolean	boolean;
 		struct filter_arg_field		field;
 		struct filter_arg_value		value;
 		struct filter_arg_op		op;
tools/lib/traceevent/event-utils.h +16 -0
index a8fb48f..0829638 100644
@@ -23,6 +23,22 @@
 
 #include <ctype.h>
 
+/* Can be overridden */
+void die(const char *fmt, ...);
+void *malloc_or_die(unsigned int size);
+void warning(const char *fmt, ...);
+void pr_stat(const char *fmt, ...);
+void vpr_stat(const char *fmt, va_list ap);
+
+/* Always available */
+void __die(const char *fmt, ...);
+void __warning(const char *fmt, ...);
+void __pr_stat(const char *fmt, ...);
+
+void __vdie(const char *fmt, ...);
+void __vwarning(const char *fmt, ...);
+void __vpr_stat(const char *fmt, ...);
+
 static inline char *strim(char *string)
 {
 	char *ret;
tools/lib/traceevent/parse-filter.c +16 -16
index 1df9966..fe37182 100644
@@ -359,7 +359,7 @@ create_arg_item(struct event_format *event,
 			if (strcmp(token, COMM) != 0) {
 				/* not a field, Make it false */
 				arg->type = FILTER_ARG_BOOLEAN;
-				arg->bool.value = FILTER_FALSE;
+				arg->boolean.value = FILTER_FALSE;
 				break;
 			}
 			/* If token is 'COMM' then it is special */
@@ -487,7 +487,7 @@ static int add_right(struct filter_arg *op, struct filter_arg *arg,
 				free_arg(left);
 				free_arg(arg);
 				op->type = FILTER_ARG_BOOLEAN;
-				op->bool.value = FILTER_FALSE;
+				op->boolean.value = FILTER_FALSE;
 				break;
 			}
 
@@ -772,7 +772,7 @@ enum filter_vals test_arg(struct filter_arg *parent, struct filter_arg *arg)
 
 		/* bad case */
 	case FILTER_ARG_BOOLEAN:
-		return FILTER_VAL_FALSE + arg->bool.value;
+		return FILTER_VAL_FALSE + arg->boolean.value;
 
 		/* good cases: */
 	case FILTER_ARG_STR:
@@ -871,7 +871,7 @@ static struct filter_arg *collapse_tree(struct filter_arg *arg)
 		free_arg(arg);
 		arg = allocate_arg();
 		arg->type = FILTER_ARG_BOOLEAN;
-		arg->bool.value = ret == FILTER_VAL_TRUE;
+		arg->boolean.value = ret == FILTER_VAL_TRUE;
 	}
 
 	return arg;
@@ -1116,7 +1116,7 @@ process_event(struct event_format *event, const char *filter_str,
 	if (!*parg) {
 		*parg = allocate_arg();
 		(*parg)->type = FILTER_ARG_BOOLEAN;
-		(*parg)->bool.value = FILTER_FALSE;
+		(*parg)->boolean.value = FILTER_FALSE;
 	}
 
 	return 0;
@@ -1139,7 +1139,7 @@ static int filter_event(struct event_filter *filter,
 		/* just add a TRUE arg */
 		arg = allocate_arg();
 		arg->type = FILTER_ARG_BOOLEAN;
-		arg->bool.value = FILTER_TRUE;
+		arg->boolean.value = FILTER_TRUE;
 	}
 
 	filter_type = add_filter_type(filter, event->id);
@@ -1369,9 +1369,9 @@ static int copy_filter_type(struct event_filter *filter,
 		arg = allocate_arg();
 		arg->type = FILTER_ARG_BOOLEAN;
 		if (strcmp(str, "TRUE") == 0)
-			arg->bool.value = 1;
+			arg->boolean.value = 1;
 		else
-			arg->bool.value = 0;
+			arg->boolean.value = 0;
 
 		filter_type = add_filter_type(filter, event->id);
 		filter_type->filter = arg;
@@ -1442,8 +1442,8 @@ int pevent_update_trivial(struct event_filter *dest, struct event_filter *source
 		arg = filter_type->filter;
 		if (arg->type != FILTER_ARG_BOOLEAN)
 			continue;
-		if ((arg->bool.value && type == FILTER_TRIVIAL_FALSE) ||
-		    (!arg->bool.value && type == FILTER_TRIVIAL_TRUE))
+		if ((arg->boolean.value && type == FILTER_TRIVIAL_FALSE) ||
+		    (!arg->boolean.value && type == FILTER_TRIVIAL_TRUE))
 			continue;
 
 		event = filter_type->event;
@@ -1497,10 +1497,10 @@ void pevent_filter_clear_trivial(struct event_filter *filter,
 			continue;
 		switch (type) {
 		case FILTER_TRIVIAL_FALSE:
-			if (filter_type->filter->bool.value)
+			if (filter_type->filter->boolean.value)
 				continue;
 		case FILTER_TRIVIAL_TRUE:
-			if (!filter_type->filter->bool.value)
+			if (!filter_type->filter->boolean.value)
 				continue;
 		default:
 			break;
@@ -1551,10 +1551,10 @@ int pevent_filter_event_has_trivial(struct event_filter *filter,
 
 	switch (type) {
 	case FILTER_TRIVIAL_FALSE:
-		return !filter_type->filter->bool.value;
+		return !filter_type->filter->boolean.value;
 
 	case FILTER_TRIVIAL_TRUE:
-		return filter_type->filter->bool.value;
+		return filter_type->filter->boolean.value;
 	default:
 		return 1;
 	}
@@ -1783,7 +1783,7 @@ static int test_filter(struct event_format *event,
 	switch (arg->type) {
 	case FILTER_ARG_BOOLEAN:
 		/* easy case */
-		return arg->bool.value;
+		return arg->boolean.value;
 
 	case FILTER_ARG_OP:
 		return test_op(event, arg, record);
@@ -2147,7 +2147,7 @@ static char *arg_to_str(struct event_filter *filter, struct filter_arg *arg)
 	switch (arg->type) {
 	case FILTER_ARG_BOOLEAN:
 		str = malloc_or_die(6);
-		if (arg->bool.value)
+		if (arg->boolean.value)
 			strcpy(str, "TRUE");
 		else
 			strcpy(str, "FALSE");
tools/lib/traceevent/trace-seq.c +1 -0
index d2f265b..b1ccc92 100644
@@ -24,6 +24,7 @@
 #include <stdarg.h>
 
 #include "event-parse.h"
+#include "event-utils.h"
 
 /*
  * The TRACE_SEQ_POISON is to catch the use of using
Signature · 1 line
1.7.5.4
#5 lore raw

PATCH 5/15 perf: Have perf use the new libtraceevent.a library

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

The event parsing code in perf was originally copied from trace-cmd but never was kept up-to-date with the changes that was done there. The trace-cmd libtraceevent.a code is much more mature than what is currently in perf.

This updates the code to use wrappers to handle the calls to the new event parsing code. The new code requires a handle to be pass around, which removes the global event variables and allows more than one event structure to be read from different files (and different machines).

But perf still has the old global events and the code throughout perf does not yet have a nice way to pass around a handle. A global 'pevent' has been made for perf and the old calls have been created as wrappers to the new event parsing code that uses the global pevent.

With this change, perf can later incorporate the pevent handle into the perf structures and allow more than one file to be read and compared, that contains different events.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/perf/Makefile                                |   20 +-
 tools/perf/builtin-kmem.c                          |    6 +-
 tools/perf/builtin-lock.c                          |   26 +-
 tools/perf/builtin-sched.c                         |   42 +-
 tools/perf/builtin-script.c                        |    2 +-
 .../util/scripting-engines/trace-event-python.c    |   16 +-
 tools/perf/util/trace-event-info.c                 |    4 +-
 tools/perf/util/trace-event-parse.c                |  350 +++-
 tools/perf/util/trace-event-read.c                 |   34 +-
 tools/perf/util/trace-event.h                      |   50 +-
 tools/perf/util/trace-parse-events.c               | 3125 --------------------
 tools/perf/util/trace-parse-events.h               |  273 --
 12 files changed, 481 insertions(+), 3467 deletions(-)
 delete mode 100644 tools/perf/util/trace-parse-events.c
 delete mode 100644 tools/perf/util/trace-parse-events.h
tools/perf/Makefile +13 -7
index 46150ab..af0e5d6 100644
@@ -149,7 +149,7 @@ endif
 
 ### --- END CONFIGURATION SECTION ---
 
-BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)/util -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
+BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include -I$(OUTPUT)/util -I$(EVENT_PARSE_DIR) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 BASIC_LDFLAGS =
 
 # Guard against environment variables
@@ -179,7 +179,15 @@ $(OUTPUT)python/perf.so: $(PYRF_OBJS) $(PYTHON_EXT_SRCS) $(PYTHON_EXT_DEPS)
 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
 
 EVENT_PARSE_DIR = ../lib/traceevent/
-LIBTRACEEVENT = $(OUTPUT)$(EVENT_PARSE_DIR)libtraceevent.a
+
+ifeq ("$(origin O)", "command line")
+	EP_PATH=$(OUTPUT)/
+else
+	EP_PATH=$(EVENT_PARSE_DIR)/
+endif
+
+LIBPARSEVENT = $(EP_PATH)libtraceevent.a
+EP_LIB := -L$(EP_PATH) -ltraceevent
 
 #
 # Single 'perf' binary right now:
@@ -295,7 +303,6 @@ LIB_H += util/hist.h
 LIB_H += util/thread.h
 LIB_H += util/thread_map.h
 LIB_H += util/trace-event.h
-LIB_H += util/trace-parse-events.h
 LIB_H += util/probe-finder.h
 LIB_H += util/dwarf-aux.h
 LIB_H += util/probe-event.h
@@ -358,7 +365,6 @@ LIB_OBJS += $(OUTPUT)util/pmu-bison.o
 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
-LIB_OBJS += $(OUTPUT)util/trace-parse-events.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
 LIB_OBJS += $(OUTPUT)util/hist.o
@@ -402,7 +408,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
 
-PERFLIBS = $(LIB_FILE)
+PERFLIBS = $(LIB_FILE) $(LIBPARSEVENT)
 
 # Files needed for the python binding, perf.so
 # pyrf is just an internal name needed for all those wrappers.
@@ -699,7 +705,7 @@ $(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS
 		'-DPERF_HTML_PATH="$(htmldir_SQ)"' \
 		$(ALL_CFLAGS) -c $(filter %.c,$^) -o $@
 
-$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) $(LIBTRACEEVENT)
+$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \
                $(BUILTIN_OBJS) $(LIBS) -o $@
 
@@ -806,7 +812,7 @@ $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
 
 # libparsevent.a
-$(LIBTRACEEVENT):
+$(LIBPARSEVENT):
 	make -C $(EVENT_PARSE_DIR) $(COMMAND_O) libtraceevent.a
 
 help:
tools/perf/builtin-kmem.c +3 -3
index 39104c0..547af48 100644
@@ -192,7 +192,7 @@ static void insert_caller_stat(unsigned long call_site,
 }
 
 static void process_alloc_event(void *data,
-				struct event *event,
+				struct event_format *event,
 				int cpu,
 				u64 timestamp __used,
 				struct thread *thread __used,
@@ -253,7 +253,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr,
 }
 
 static void process_free_event(void *data,
-			       struct event *event,
+			       struct event_format *event,
 			       int cpu,
 			       u64 timestamp __used,
 			       struct thread *thread __used)
@@ -281,7 +281,7 @@ static void process_free_event(void *data,
 static void process_raw_event(union perf_event *raw_event __used, void *data,
 			      int cpu, u64 timestamp, struct thread *thread)
 {
-	struct event *event;
+	struct event_format *event;
 	int type;
 
 	type = trace_parse_common_type(data);
tools/perf/builtin-lock.c +13 -13
index 12c8148..fd53319 100644
@@ -356,25 +356,25 @@ struct trace_release_event {
 
 struct trace_lock_handler {
 	void (*acquire_event)(struct trace_acquire_event *,
-			      struct event *,
+			      struct event_format *,
 			      int cpu,
 			      u64 timestamp,
 			      struct thread *thread);
 
 	void (*acquired_event)(struct trace_acquired_event *,
-			       struct event *,
+			       struct event_format *,
 			       int cpu,
 			       u64 timestamp,
 			       struct thread *thread);
 
 	void (*contended_event)(struct trace_contended_event *,
-				struct event *,
+				struct event_format *,
 				int cpu,
 				u64 timestamp,
 				struct thread *thread);
 
 	void (*release_event)(struct trace_release_event *,
-			      struct event *,
+			      struct event_format *,
 			      int cpu,
 			      u64 timestamp,
 			      struct thread *thread);
@@ -416,7 +416,7 @@ enum acquire_flags {
 
 static void
 report_lock_acquire_event(struct trace_acquire_event *acquire_event,
-			struct event *__event __used,
+			struct event_format *__event __used,
 			int cpu __used,
 			u64 timestamp __used,
 			struct thread *thread __used)
@@ -480,7 +480,7 @@ end:
 
 static void
 report_lock_acquired_event(struct trace_acquired_event *acquired_event,
-			 struct event *__event __used,
+			 struct event_format *__event __used,
 			 int cpu __used,
 			 u64 timestamp __used,
 			 struct thread *thread __used)
@@ -536,7 +536,7 @@ end:
 
 static void
 report_lock_contended_event(struct trace_contended_event *contended_event,
-			  struct event *__event __used,
+			  struct event_format *__event __used,
 			  int cpu __used,
 			  u64 timestamp __used,
 			  struct thread *thread __used)
@@ -583,7 +583,7 @@ end:
 
 static void
 report_lock_release_event(struct trace_release_event *release_event,
-			struct event *__event __used,
+			struct event_format *__event __used,
 			int cpu __used,
 			u64 timestamp __used,
 			struct thread *thread __used)
@@ -647,7 +647,7 @@ static struct trace_lock_handler *trace_handler;
 
 static void
 process_lock_acquire_event(void *data,
-			   struct event *event __used,
+			   struct event_format *event __used,
 			   int cpu __used,
 			   u64 timestamp __used,
 			   struct thread *thread __used)
@@ -666,7 +666,7 @@ process_lock_acquire_event(void *data,
 
 static void
 process_lock_acquired_event(void *data,
-			    struct event *event __used,
+			    struct event_format *event __used,
 			    int cpu __used,
 			    u64 timestamp __used,
 			    struct thread *thread __used)
@@ -684,7 +684,7 @@ process_lock_acquired_event(void *data,
 
 static void
 process_lock_contended_event(void *data,
-			     struct event *event __used,
+			     struct event_format *event __used,
 			     int cpu __used,
 			     u64 timestamp __used,
 			     struct thread *thread __used)
@@ -702,7 +702,7 @@ process_lock_contended_event(void *data,
 
 static void
 process_lock_release_event(void *data,
-			   struct event *event __used,
+			   struct event_format *event __used,
 			   int cpu __used,
 			   u64 timestamp __used,
 			   struct thread *thread __used)
@@ -721,7 +721,7 @@ process_lock_release_event(void *data,
 static void
 process_raw_event(void *data, int cpu, u64 timestamp, struct thread *thread)
 {
-	struct event *event;
+	struct event_format *event;
 	int type;
 
 	type = trace_parse_common_type(data);
tools/perf/builtin-sched.c +21 -21

167 lines not on this page · raw message

tools/perf/builtin-script.c +1 -1
index d4ce733..8e395a5 100644
@@ -261,7 +261,7 @@ static void print_sample_start(struct perf_sample *sample,
 			       struct perf_event_attr *attr)
 {
 	int type;
-	struct event *event;
+	struct event_format *event;
 	const char *evname = NULL;
 	unsigned long secs;
 	unsigned long usecs;
tools/perf/util/scripting-engines/trace-event-python.c +10 -6
index c2623c6..acb9795 100644
@@ -37,7 +37,7 @@ PyMODINIT_FUNC initperf_trace_context(void);
 #define FTRACE_MAX_EVENT				\
 	((1 << (sizeof(unsigned short) * 8)) - 1)
 
-struct event *events[FTRACE_MAX_EVENT];
+struct event_format *events[FTRACE_MAX_EVENT];
 
 #define MAX_FIELDS	64
 #define N_COMMON_FIELDS	7
@@ -136,7 +136,7 @@ static void define_field(enum print_arg_type field_type,
 	Py_DECREF(t);
 }
 
-static void define_event_symbols(struct event *event,
+static void define_event_symbols(struct event_format *event,
 				 const char *ev_name,
 				 struct print_arg *args)
 {
@@ -178,6 +178,10 @@ static void define_event_symbols(struct event *event,
 		define_event_symbols(event, ev_name, args->op.right);
 		break;
 	default:
+		/* gcc warns for these? */
+	case PRINT_BSTRING:
+	case PRINT_DYNAMIC_ARRAY:
+	case PRINT_FUNC:
 		/* we should warn... */
 		return;
 	}
@@ -186,10 +190,10 @@ static void define_event_symbols(struct event *event,
 		define_event_symbols(event, ev_name, args->next);
 }
 
-static inline struct event *find_cache_event(int type)
+static inline struct event_format *find_cache_event(int type)
 {
 	static char ev_name[256];
-	struct event *event;
+	struct event_format *event;
 
 	if (events[type])
 		return events[type];
@@ -216,7 +220,7 @@ static void python_process_event(union perf_event *pevent __unused,
 	struct format_field *field;
 	unsigned long long val;
 	unsigned long s, ns;
-	struct event *event;
+	struct event_format *event;
 	unsigned n = 0;
 	int type;
 	int pid;
@@ -436,7 +440,7 @@ out:
 
 static int python_generate_script(const char *outfile)
 {
-	struct event *event = NULL;
+	struct event_format *event = NULL;
 	struct format_field *f;
 	char fname[PATH_MAX];
 	int not_first, count;
tools/perf/util/trace-event-info.c +3 -1
index fc22cf5..a8d81c3 100644
@@ -68,7 +68,7 @@ struct events {
 };
 
 
-void *malloc_or_die(unsigned int size)
+static void *malloc_or_die(unsigned int size)
 {
 	void *data;
 
@@ -448,6 +448,8 @@ static void tracing_data_header(void)
 	else
 		buf[0] = 0;
 
+	read_trace_init(buf[0], buf[0]);
+
 	write_or_die(buf, 1);
 
 	/* save size of long */
tools/perf/util/trace-event-parse.c +345 -5

363 lines not on this page · raw message

tools/perf/util/trace-event-read.c +23 -11
index b9592e0..29b9206 100644
@@ -52,6 +52,16 @@ static unsigned long	page_size;
 static ssize_t calc_data_size;
 static bool repipe;
 
+static void *malloc_or_die(int size)
+{
+	void *ret;
+
+	ret = malloc(size);
+	if (!ret)
+		die("malloc");
+	return ret;
+}
+
 static int do_read(int fd, void *buf, int size)
 {
 	int rsize = size;
@@ -109,7 +119,7 @@ static unsigned int read4(void)
 	unsigned int data;
 
 	read_or_die(&data, 4);
-	return __data2host4(data);
+	return __data2host4(perf_pevent, data);
 }
 
 static unsigned long long read8(void)
@@ -117,7 +127,7 @@ static unsigned long long read8(void)
 	unsigned long long data;
 
 	read_or_die(&data, 8);
-	return __data2host8(data);
+	return __data2host8(perf_pevent, data);
 }
 
 static char *read_string(void)
@@ -389,15 +399,15 @@ struct record *trace_peek_data(int cpu)
 		/* FIXME: handle header page */
 		if (header_page_ts_size != 8)
 			die("expected a long long type for timestamp");
-		cpu_data[cpu].timestamp = data2host8(ptr);
+		cpu_data[cpu].timestamp = data2host8(perf_pevent, ptr);
 		ptr += 8;
 		switch (header_page_size_size) {
 		case 4:
-			cpu_data[cpu].page_size = data2host4(ptr);
+			cpu_data[cpu].page_size = data2host4(perf_pevent, ptr);
 			ptr += 4;
 			break;
 		case 8:
-			cpu_data[cpu].page_size = data2host8(ptr);
+			cpu_data[cpu].page_size = data2host8(perf_pevent, ptr);
 			ptr += 8;
 			break;
 		default:
@@ -414,7 +424,7 @@ read_again:
 		return trace_peek_data(cpu);
 	}
 
-	type_len_ts = data2host4(ptr);
+	type_len_ts = data2host4(perf_pevent, ptr);
 	ptr += 4;
 
 	type_len = type_len4host(type_len_ts);
@@ -424,14 +434,14 @@ read_again:
 	case RINGBUF_TYPE_PADDING:
 		if (!delta)
 			die("error, hit unexpected end of page");
-		length = data2host4(ptr);
+		length = data2host4(perf_pevent, ptr);
 		ptr += 4;
 		length *= 4;
 		ptr += length;
 		goto read_again;
 
 	case RINGBUF_TYPE_TIME_EXTEND:
-		extend = data2host4(ptr);
+		extend = data2host4(perf_pevent, ptr);
 		ptr += 4;
 		extend <<= TS_SHIFT;
 		extend += delta;
@@ -442,7 +452,7 @@ read_again:
 		ptr += 12;
 		break;
 	case 0:
-		length = data2host4(ptr);
+		length = data2host4(perf_pevent, ptr);
 		ptr += 4;
 		die("here! length=%d", length);
 		break;
@@ -509,6 +519,8 @@ ssize_t trace_report(int fd, bool __repipe)
 	file_bigendian = buf[0];
 	host_bigendian = bigendian();
 
+	read_trace_init(file_bigendian, host_bigendian);
+
 	read_or_die(buf, 1);
 	long_size = buf[0];
 
@@ -526,11 +538,11 @@ ssize_t trace_report(int fd, bool __repipe)
 	repipe = false;
 
 	if (show_funcs) {
-		print_funcs();
+		pevent_print_funcs(perf_pevent);
 		return size;
 	}
 	if (show_printk) {
-		print_printk();
+		pevent_print_printk(perf_pevent);
 		return size;
 	}
 
tools/perf/util/trace-event.h +49 -1

62 lines not on this page · raw message

tools/perf/util/trace-parse-events.c deleted +0 -3125

2,040 lines not on this page · raw message

tools/perf/util/trace-parse-events.h deleted +0 -273

273 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.5.4

Part of the diff is not shown here. View the raw message.

#6 lore raw

PATCH 6/15 perf/events: Add flag to produce nsec output

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

libtraceevent library prints out in usecs but perf wants to print out in nsecs. Add a flag that lets the user decide to print out in usec or nsec times.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c  |   15 ++++++++++++---
 tools/lib/traceevent/event-parse.h  |   12 ++++++++++++
 tools/perf/util/trace-event-parse.c |    1 +
 3 files changed, 25 insertions(+), 3 deletions(-)
tools/lib/traceevent/event-parse.c +12 -3
index 3ce75b5..c799c19 100644
@@ -3940,15 +3940,16 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
 	struct event_format *event;
 	unsigned long secs;
 	unsigned long usecs;
+	unsigned long nsecs;
 	const char *comm;
 	void *data = record->data;
 	int type;
 	int pid;
 	int len;
+	int p;
 
 	secs = record->ts / NSECS_PER_SEC;
-	usecs = record->ts - secs * NSECS_PER_SEC;
-	usecs = (usecs + 500) / NSECS_PER_USEC;
+	nsecs = record->ts - secs * NSECS_PER_SEC;
 
 	if (record->size < 0) {
 		do_warning("ug! negative record size %d", record->size);
@@ -3973,7 +3974,15 @@ void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
 	} else
 		trace_seq_printf(s, "%16s-%-5d [%03d]", comm, pid, record->cpu);
 
-	trace_seq_printf(s, " %5lu.%06lu: %s: ", secs, usecs, event->name);
+	if (pevent->flags & PEVENT_NSEC_OUTPUT) {
+		usecs = nsecs;
+		p = 9;
+	} else {
+		usecs = (nsecs + 500) / NSECS_PER_USEC;
+		p = 6;
+	}
+
+	trace_seq_printf(s, " %5lu.%0*lu: %s: ", secs, p, usecs, event->name);
 
 	/* Space out the event names evenly. */
 	len = strlen(event->name);
tools/lib/traceevent/event-parse.h +12 -0
index 2e0222d..8852827 100644
@@ -334,6 +334,10 @@ enum pevent_func_arg_type {
 	PEVENT_FUNC_ARG_MAX_TYPES
 };
 
+enum pevent_flag {
+	PEVENT_NSEC_OUTPUT		= 1,	/* output in NSECS */
+};
+
 struct cmdline;
 struct cmdline_list;
 struct func_map;
@@ -373,6 +377,7 @@ struct pevent {
 	struct printk_list *printklist;
 	unsigned int printk_count;
 
+
 	struct event_format **events;
 	int nr_events;
 	struct event_format **sort_events;
@@ -397,6 +402,8 @@ struct pevent {
 
 	int test_filters;
 
+	int flags;
+
 	struct format_field *bprint_ip_field;
 	struct format_field *bprint_fmt_field;
 	struct format_field *bprint_buf_field;
@@ -408,6 +415,11 @@ struct pevent {
 	struct event_format *last_event;
 };
 
+static inline void pevent_set_flag(struct pevent *pevent, int flag)
+{
+	pevent->flags |= flag;
+}
+
 static inline unsigned short
 __data2host2(struct pevent *pevent, unsigned short data)
 {
tools/perf/util/trace-event-parse.c +1 -0
index 4ec165a..39f22f8 100644
@@ -45,6 +45,7 @@ int read_trace_init(int file_bigendian, int host_bigendian)
 	perf_pevent = pevent_alloc();
 	pevent = perf_pevent;
 
+	pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
 	pevent_set_file_bigendian(pevent, file_bigendian);
 	pevent_set_host_bigendian(pevent, host_bigendian);
 
Signature · 1 line
1.7.5.4
#7 lore raw

PATCH 7/15 perf/events: Add flag/symbol format_flags

In reply to Frederic Weisbecker

From: Tom Zanussi <[email protected]>

This is a port of commit eb9a42caa7a92
perf trace: Add flag/symbolic format_flags
of the old trace-event-parse.c to the new event-parse.c that was written by Tom Zanussi and forward ported by Steven Rostedt.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
tools/lib/traceevent/event-parse.c +15 -0
index c799c19..f012395 100644
@@ -39,6 +39,9 @@ static const char *input_buf;
 static unsigned long long input_buf_ptr;
 static unsigned long long input_buf_siz;
 
+static int is_flag_field;
+static int is_symbolic_field;
+
 static int show_warning = 1;
 
 #define do_warning(fmt, ...)				\
@@ -1789,6 +1792,16 @@ process_entry(struct event_format *event __unused, struct print_arg *arg,
 	arg->type = PRINT_FIELD;
 	arg->field.name = field;
 
+	if (is_flag_field) {
+		arg->field.field = pevent_find_any_field(event, arg->field.name);
+		arg->field.field->flags |= FIELD_IS_FLAG;
+		is_flag_field = 0;
+	} else if (is_symbolic_field) {
+		arg->field.field = pevent_find_any_field(event, arg->field.name);
+		arg->field.field->flags |= FIELD_IS_SYMBOLIC;
+		is_symbolic_field = 0;
+	}
+
 	type = read_token(&token);
 	*tok = token;
 
@@ -2398,10 +2411,12 @@ process_function(struct event_format *event, struct print_arg *arg,
 
 	if (strcmp(token, "__print_flags") == 0) {
 		free_token(token);
+		is_flag_field = 1;
 		return process_flags(event, arg, tok);
 	}
 	if (strcmp(token, "__print_symbolic") == 0) {
 		free_token(token);
+		is_symbolic_field = 1;
 		return process_symbols(event, arg, tok);
 	}
 	if (strcmp(token, "__get_str") == 0) {
Signature · 1 line
1.7.5.4
#8 lore raw

PATCH 8/15 perf/events: Correct size given to memset

In reply to Frederic Weisbecker

From: Julia Lawall <[email protected]>

This is a forward port of commit 5660ce34241ab
perf tools: Correct size given to memset
written by Julia Lawall and forward ported by Steven Rostedt.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/lib/traceevent/event-parse.c +1 -1
index f012395..16da20c 100644
@@ -2076,7 +2076,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 			goto out_free;
 
 		field = malloc_or_die(sizeof(*field));
-		memset(field, 0, sizeof(field));
+		memset(field, 0, sizeof(*field));
 
 		value = arg_eval(arg);
 		field->value = strdup(value);
Signature · 1 line
1.7.5.4
#9 lore raw

PATCH 9/15 parse-events: Handle invalid opcode parsing gracefully

In reply to Frederic Weisbecker

From: Vaibhav Nagarnaik <[email protected]>

If an invalid opcode is encountered, trace-cmd exits with an error. Instead it can be treated as a soft error where the event's print format is not parsed and its binary data is dumped out.

This patch adds a return value to arg_num_eval() function to indicate if the parsing was successful. If not, then the error is considered soft and the parsing of the offending event fails.

Cc Michael Rubin <[email protected]>
Cc David Sharp <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |  125 ++++++++++++++++++++++++------------
 1 files changed, 83 insertions(+), 42 deletions(-)
tools/lib/traceevent/event-parse.c +83 -42
index 16da20c..ef2c65f 100644
@@ -1915,90 +1915,120 @@ eval_type(unsigned long long val, struct print_arg *arg, int pointer)
 	return eval_type_str(val, arg->typecast.type, pointer);
 }
 
-static long long arg_num_eval(struct print_arg *arg)
+static int arg_num_eval(struct print_arg *arg, long long *val)
 {
 	long long left, right;
-	long long val = 0;
+	int ret = 1;
 
 	switch (arg->type) {
 	case PRINT_ATOM:
-		val = strtoll(arg->atom.atom, NULL, 0);
+		*val = strtoll(arg->atom.atom, NULL, 0);
 		break;
 	case PRINT_TYPE:
-		val = arg_num_eval(arg->typecast.item);
-		val = eval_type(val, arg, 0);
+		ret = arg_num_eval(arg->typecast.item, val);
+		if (!ret)
+			break;
+		*val = eval_type(*val, arg, 0);
 		break;
 	case PRINT_OP:
 		switch (arg->op.op[0]) {
 		case '|':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 			if (arg->op.op[1])
-				val = left || right;
+				*val = left || right;
 			else
-				val = left | right;
+				*val = left | right;
 			break;
 		case '&':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 			if (arg->op.op[1])
-				val = left && right;
+				*val = left && right;
 			else
-				val = left & right;
+				*val = left & right;
 			break;
 		case '<':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 			switch (arg->op.op[1]) {
 			case 0:
-				val = left < right;
+				*val = left < right;
 				break;
 			case '<':
-				val = left << right;
+				*val = left << right;
 				break;
 			case '=':
-				val = left <= right;
+				*val = left <= right;
 				break;
 			default:
-				die("unknown op '%s'", arg->op.op);
+				do_warning("unknown op '%s'", arg->op.op);
+				ret = 0;
 			}
 			break;
 		case '>':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 			switch (arg->op.op[1]) {
 			case 0:
-				val = left > right;
+				*val = left > right;
 				break;
 			case '>':
-				val = left >> right;
+				*val = left >> right;
 				break;
 			case '=':
-				val = left >= right;
+				*val = left >= right;
 				break;
 			default:
-				die("unknown op '%s'", arg->op.op);
+				do_warning("unknown op '%s'", arg->op.op);
+				ret = 0;
 			}
 			break;
 		case '=':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
-
-			if (arg->op.op[1] != '=')
-				die("unknown op '%s'", arg->op.op);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 
-			val = left == right;
+			if (arg->op.op[1] != '=') {
+				do_warning("unknown op '%s'", arg->op.op);
+				ret = 0;
+			} else
+				*val = left == right;
 			break;
 		case '!':
-			left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
+			ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
 
 			switch (arg->op.op[1]) {
 			case '=':
-				val = left != right;
+				*val = left != right;
 				break;
 			default:
-				die("unknown op '%s'", arg->op.op);
+				do_warning("unknown op '%s'", arg->op.op);
+				ret = 0;
 			}
 			break;
 		case '-':
@@ -2006,12 +2036,17 @@ static long long arg_num_eval(struct print_arg *arg)
 			if (arg->op.left->type == PRINT_NULL)
 				left = 0;
 			else
-				left = arg_num_eval(arg->op.left);
-			right = arg_num_eval(arg->op.right);
-			val = left - right;
+				ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
+			*val = left - right;
 			break;
 		default:
-			die("unknown op '%s'", arg->op.op);
+			do_warning("unknown op '%s'", arg->op.op);
+			ret = 0;
 		}
 		break;
 
@@ -2020,10 +2055,11 @@ static long long arg_num_eval(struct print_arg *arg)
 	case PRINT_STRING:
 	case PRINT_BSTRING:
 	default:
-		die("invalid eval type %d", arg->type);
+		do_warning("invalid eval type %d", arg->type);
+		ret = 0;
 
 	}
-	return val;
+	return ret;
 }
 
 static char *arg_eval (struct print_arg *arg)
@@ -2037,7 +2073,8 @@ static char *arg_eval (struct print_arg *arg)
 	case PRINT_TYPE:
 		return arg_eval(arg->typecast.item);
 	case PRINT_OP:
-		val = arg_num_eval(arg);
+		if (!arg_num_eval(arg, &val))
+			break;
 		sprintf(buf, "%lld", val);
 		return buf;
 
@@ -2079,6 +2116,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 		memset(field, 0, sizeof(*field));
 
 		value = arg_eval(arg);
+		if (value == NULL)
+			goto out_free;
 		field->value = strdup(value);
 
 		free_arg(arg);
@@ -2090,6 +2129,8 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 			goto out_free;
 
 		value = arg_eval(arg);
+		if (value == NULL)
+			goto out_free;
 		field->str = strdup(value);
 		free_arg(arg);
 		arg = NULL;
Signature · 1 line
1.7.5.4
#10 lore raw

PATCH 10/15 parse-events: Handle opcode parsing error

In reply to Frederic Weisbecker

From: Vaibhav Nagarnaik <[email protected]>

If an invalid opcode is encountered in parsing event print format, the trace-cmd calls exit() without parsing any other events.

This patch adds handling for such an error where the get_op_prio() is called. If the return value is -1, then the event print format parsing is skipped and parsing continues.

Cc Michael Rubin <[email protected]>
Cc David Sharp <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
tools/lib/traceevent/event-parse.c +11 -8
index ef2c65f..cdb32c7 100644
@@ -1592,7 +1592,7 @@ static int get_op_prio(char *op)
 		case '?':
 			return 16;
 		default:
-			die("unknown op '%c'", op[0]);
+			do_warning("unknown op '%c'", op[0]);
 			return -1;
 		}
 	} else {
@@ -1613,22 +1613,22 @@ static int get_op_prio(char *op)
 		} else if (strcmp(op, "||") == 0) {
 			return 15;
 		} else {
-			die("unknown op '%s'", op);
+			do_warning("unknown op '%s'", op);
 			return -1;
 		}
 	}
 }
 
-static void set_op_prio(struct print_arg *arg)
+static int set_op_prio(struct print_arg *arg)
 {
 
 	/* single ops are the greatest */
-	if (!arg->op.left || arg->op.left->type == PRINT_NULL) {
+	if (!arg->op.left || arg->op.left->type == PRINT_NULL)
 		arg->op.prio = 0;
-		return;
-	}
+	else
+		arg->op.prio = get_op_prio(arg->op.op);
 
-	arg->op.prio = get_op_prio(arg->op.op);
+	return arg->op.prio;
 }
 
 /* Note, *tok does not get freed, but will most likely be saved */
@@ -1710,7 +1710,10 @@ process_op(struct event_format *event, struct print_arg *arg, char **tok)
 		arg->op.op = token;
 		arg->op.left = left;
 
-		set_op_prio(arg);
+		if (set_op_prio(arg) == -1) {
+			event->flags |= EVENT_FL_FAILED;
+			goto out_free;
+		}
 
 		type = read_token_item(&token);
 		*tok = token;
Signature · 1 line
1.7.5.4
#11 lore raw

PATCH 11/15 parse-events: Let pevent_free() take a NULL pointer

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

The pevent_free() should ack like other free()s and allow a NULL pointer to be passed to it which makes error handling a bit easier for the users of pevent_free().

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)
tools/lib/traceevent/event-parse.c +10 -3
index cdb32c7..4d5092f 100644
@@ -4960,13 +4960,20 @@ static void free_event(struct event_format *event)
  */
 void pevent_free(struct pevent *pevent)
 {
-	struct cmdline_list *cmdlist = pevent->cmdlist, *cmdnext;
-	struct func_list *funclist = pevent->funclist, *funcnext;
-	struct printk_list *printklist = pevent->printklist, *printknext;
+	struct cmdline_list *cmdlist, *cmdnext;
+	struct func_list *funclist, *funcnext;
+	struct printk_list *printklist, *printknext;
 	struct pevent_function_handler *func_handler;
 	struct event_handler *handle;
 	int i;
 
+	if (!pevent)
+		return;
+
+	cmdlist = pevent->cmdlist;
+	funclist = pevent->funclist;
+	printklist = pevent->printklist;
+
 	pevent->ref_count--;
 	if (pevent->ref_count)
 		return;
Signature · 1 line
1.7.5.4
#12 lore raw

PATCH 12/15 parse-events: Support '+' opcode in print format

In reply to Frederic Weisbecker

From: Vaibhav Nagarnaik <[email protected]>

The '+' opcode is not supported in the arguments for the print format. This patch adds support for it.

Cc Michael Rubin <[email protected]>
Cc David Sharp <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
tools/lib/traceevent/event-parse.c +12 -0
index 4d5092f..476626a 100644
@@ -2047,6 +2047,18 @@ static int arg_num_eval(struct print_arg *arg, long long *val)
 				break;
 			*val = left - right;
 			break;
+		case '+':
+			if (arg->op.left->type == PRINT_NULL)
+				left = 0;
+			else
+				ret = arg_num_eval(arg->op.left, &left);
+			if (!ret)
+				break;
+			ret = arg_num_eval(arg->op.right, &right);
+			if (!ret)
+				break;
+			*val = left + right;
+			break;
 		default:
 			do_warning("unknown op '%s'", arg->op.op);
 			ret = 0;
Signature · 1 line
1.7.5.4
#13 lore raw

PATCH 13/15 parse-events: Allow '*' and '/' operations in TP_printk

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

Add multiply and divide operations in the printk format.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
tools/lib/traceevent/event-parse.c +6 -0
index 476626a..876b2720 100644
@@ -3130,6 +3130,12 @@ eval_num_arg(void *data, int size, struct event_format *event, struct print_arg
 		case '+':
 			val = left + right;
 			break;
+		case '/':
+			val = left / right;
+			break;
+		case '*':
+			val = left * right;
+			break;
 		default:
 			die("unknown op '%s'", arg->op.op);
 		}
Signature · 1 line
1.7.5.4
#14 lore raw

PATCH 14/15 parse-event: Fix memset pointer size bug in handle

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

Fix memset(ptr, 0, sizeof(ptr)) to memset(ptr, 0, sizeof(*ptr))

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/lib/traceevent/event-parse.c +1 -1
index 876b2720..ec13174 100644
@@ -4904,7 +4904,7 @@ int pevent_register_event_handler(struct pevent *pevent,
  not_found:
 	/* Save for later use. */
 	handle = malloc_or_die(sizeof(*handle));
-	memset(handle, 0, sizeof(handle));
+	memset(handle, 0, sizeof(*handle));
 	handle->id = id;
 	if (event_name)
 		handle->event_name = strdup(event_name);
Signature · 1 line
1.7.5.4
#15 lore raw

PATCH 15/15 parse-events: Rename struct record to struct pevent_record

In reply to Frederic Weisbecker

From: Steven Rostedt <[email protected]>

As libtraceevent will be a library, having struct record is far too generic of a name to use. Renaming it to be consistent with the rest of the functions will be a better long term solution.

Cc Ingo Molnar <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Arun Sharma <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc David Ahern <[email protected]>
---
 tools/lib/traceevent/event-parse.c  |   22 +++++++++++-----------
 tools/lib/traceevent/event-parse.h  |   30 +++++++++++++++---------------
 tools/lib/traceevent/parse-filter.c |   24 ++++++++++++------------
 tools/perf/util/trace-event-parse.c |    8 ++++----
 tools/perf/util/trace-event-read.c  |   10 +++++-----
 tools/perf/util/trace-event.h       |    4 ++--
 6 files changed, 49 insertions(+), 49 deletions(-)
tools/lib/traceevent/event-parse.c +11 -11
index ec13174..9985349 100644
@@ -3872,7 +3872,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
  * and lock depth) and places it into the trace_seq.
  */
 void pevent_data_lat_fmt(struct pevent *pevent,
-			 struct trace_seq *s, struct record *record)
+			 struct trace_seq *s, struct pevent_record *record)
 {
 	static int check_lock_depth = 1;
 	static int lock_depth_exists;
@@ -3933,7 +3933,7 @@ void pevent_data_lat_fmt(struct pevent *pevent,
  *
  * This returns the event id from the @rec.
  */
-int pevent_data_type(struct pevent *pevent, struct record *rec)
+int pevent_data_type(struct pevent *pevent, struct pevent_record *rec)
 {
 	return trace_parse_common_type(pevent, rec->data);
 }
@@ -3957,7 +3957,7 @@ struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type
  *
  * This returns the PID from a raw data.
  */
-int pevent_data_pid(struct pevent *pevent, struct record *rec)
+int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec)
 {
 	return parse_common_pid(pevent, rec->data);
 }
@@ -3991,7 +3991,7 @@ const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid)
  * writes the print format into the trace_seq.
  */
 void pevent_event_info(struct trace_seq *s, struct event_format *event,
-		       struct record *record)
+		       struct pevent_record *record)
 {
 	int print_pretty = 1;
 
@@ -4011,7 +4011,7 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
 }
 
 void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
-			struct record *record)
+			struct pevent_record *record)
 {
 	static char *spaces = "                    "; /* 20 spaces */
 	struct event_format *event;
@@ -4587,7 +4587,7 @@ int pevent_parse_event(struct pevent *pevent,
 }
 
 int get_field_val(struct trace_seq *s, struct format_field *field,
-		  const char *name, struct record *record,
+		  const char *name, struct pevent_record *record,
 		  unsigned long long *val, int err)
 {
 	if (!field) {
@@ -4620,7 +4620,7 @@ int get_field_val(struct trace_seq *s, struct format_field *field,
  * On failure, it returns NULL.
  */
 void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
-			   const char *name, struct record *record,
+			   const char *name, struct pevent_record *record,
 			   int *len, int err)
 {
 	struct format_field *field;
@@ -4667,7 +4667,7 @@ void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
  * Returns 0 on success -1 on field not found.
  */
 int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
-			 const char *name, struct record *record,
+			 const char *name, struct pevent_record *record,
 			 unsigned long long *val, int err)
 {
 	struct format_field *field;
@@ -4692,7 +4692,7 @@ int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
  * Returns 0 on success -1 on field not found.
  */
 int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
-				const char *name, struct record *record,
+				const char *name, struct pevent_record *record,
 				unsigned long long *val, int err)
 {
 	struct format_field *field;
@@ -4717,7 +4717,7 @@ int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
  * Returns 0 on success -1 on field not found.
  */
 int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
-			     const char *name, struct record *record,
+			     const char *name, struct pevent_record *record,
 			     unsigned long long *val, int err)
 {
 	struct format_field *field;
@@ -4743,7 +4743,7 @@ int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
  */
 int pevent_print_num_field(struct trace_seq *s, const char *fmt,
 			   struct event_format *event, const char *name,
-			   struct record *record, int err)
+			   struct pevent_record *record, int err)
 {
 	struct format_field *field = pevent_find_field(event, name);
 	unsigned long long val;
tools/lib/traceevent/event-parse.h +15 -15
index 8852827..ac997bc 100644
@@ -39,7 +39,7 @@
 #define DEBUG_RECORD 0
 #endif
 
-struct record {
+struct pevent_record {
 	unsigned long long	ts;
 	unsigned long long	offset;
 	long long		missed_events;	/* buffer dropped events before */
@@ -51,8 +51,8 @@ struct record {
 	int			locked;		/* Do not free, even if ref_count is zero */
 	void			*private;
 #if DEBUG_RECORD
-	struct record		*prev;
-	struct record		*next;
+	struct pevent_record	*prev;
+	struct pevent_record	*next;
 	long			alloc_addr;
 #endif
 };
@@ -91,7 +91,7 @@ struct pevent;
 struct event_format;
 
 typedef int (*pevent_event_handler_func)(struct trace_seq *s,
-					 struct record *record,
+					 struct pevent_record *record,
 					 struct event_format *event,
 					 void *context);
 
@@ -497,7 +497,7 @@ int pevent_register_print_string(struct pevent *pevent, char *fmt,
 int pevent_pid_is_registered(struct pevent *pevent, int pid);
 
 void pevent_print_event(struct pevent *pevent, struct trace_seq *s,
-			struct record *record);
+			struct pevent_record *record);
 
 int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long size,
 			     int long_size);
@@ -506,22 +506,22 @@ int pevent_parse_event(struct pevent *pevent, const char *buf,
 		       unsigned long size, const char *sys);
 
 void *pevent_get_field_raw(struct trace_seq *s, struct event_format *event,
-			   const char *name, struct record *record,
+			   const char *name, struct pevent_record *record,
 			   int *len, int err);
 
 int pevent_get_field_val(struct trace_seq *s, struct event_format *event,
-			 const char *name, struct record *record,
+			 const char *name, struct pevent_record *record,
 			 unsigned long long *val, int err);
 int pevent_get_common_field_val(struct trace_seq *s, struct event_format *event,
-				const char *name, struct record *record,
+				const char *name, struct pevent_record *record,
 				unsigned long long *val, int err);
 int pevent_get_any_field_val(struct trace_seq *s, struct event_format *event,
-			     const char *name, struct record *record,
+			     const char *name, struct pevent_record *record,
 			     unsigned long long *val, int err);
 
 int pevent_print_num_field(struct trace_seq *s, const char *fmt,
 			   struct event_format *event, const char *name,
-			   struct record *record, int err);
+			   struct pevent_record *record, int err);
 
 int pevent_register_event_handler(struct pevent *pevent, int id, char *sys_name, char *event_name,
 				  pevent_event_handler_func func, void *context);
@@ -547,13 +547,13 @@ struct event_format *
 pevent_find_event_by_name(struct pevent *pevent, const char *sys, const char *name);
 
 void pevent_data_lat_fmt(struct pevent *pevent,
-			 struct trace_seq *s, struct record *record);
-int pevent_data_type(struct pevent *pevent, struct record *rec);
+			 struct trace_seq *s, struct pevent_record *record);
+int pevent_data_type(struct pevent *pevent, struct pevent_record *rec);
 struct event_format *pevent_data_event_from_type(struct pevent *pevent, int type);
-int pevent_data_pid(struct pevent *pevent, struct record *rec);
+int pevent_data_pid(struct pevent *pevent, struct pevent_record *rec);
 const char *pevent_data_comm_from_pid(struct pevent *pevent, int pid);
 void pevent_event_info(struct trace_seq *s, struct event_format *event,
-		       struct record *record);
+		       struct pevent_record *record);
 
 struct event_format **pevent_list_events(struct pevent *pevent, enum event_sort_type);
 struct format_field **pevent_event_common_fields(struct event_format *event);
@@ -773,7 +773,7 @@ int pevent_filter_add_filter_str(struct event_filter *filter,
 
 
 int pevent_filter_match(struct event_filter *filter,
-			struct record *record);
+			struct pevent_record *record);
 
 int pevent_event_filtered(struct event_filter *filter,
 			  int event_id);
tools/lib/traceevent/parse-filter.c +12 -12
index fe37182..2d40c5e 100644
@@ -1561,10 +1561,10 @@ int pevent_filter_event_has_trivial(struct event_filter *filter,
 }
 
 static int test_filter(struct event_format *event,
-		       struct filter_arg *arg, struct record *record);
+		       struct filter_arg *arg, struct pevent_record *record);
 
 static const char *
-get_comm(struct event_format *event, struct record *record)
+get_comm(struct event_format *event, struct pevent_record *record)
 {
 	const char *comm;
 	int pid;
@@ -1576,7 +1576,7 @@ get_comm(struct event_format *event, struct record *record)
 
 static unsigned long long
 get_value(struct event_format *event,
-	  struct format_field *field, struct record *record)
+	  struct format_field *field, struct pevent_record *record)
 {
 	unsigned long long val;
 
@@ -1607,10 +1607,10 @@ get_value(struct event_format *event,
 }
 
 static unsigned long long
-get_arg_value(struct event_format *event, struct filter_arg *arg, struct record *record);
+get_arg_value(struct event_format *event, struct filter_arg *arg, struct pevent_record *record);
 
 static unsigned long long
-get_exp_value(struct event_format *event, struct filter_arg *arg, struct record *record)
+get_exp_value(struct event_format *event, struct filter_arg *arg, struct pevent_record *record)
 {
 	unsigned long long lval, rval;
 
@@ -1656,7 +1656,7 @@ get_exp_value(struct event_format *event, struct filter_arg *arg, struct record
 }
 
 static unsigned long long
-get_arg_value(struct event_format *event, struct filter_arg *arg, struct record *record)
+get_arg_value(struct event_format *event, struct filter_arg *arg, struct pevent_record *record)
 {
 	switch (arg->type) {
 	case FILTER_ARG_FIELD:
@@ -1677,7 +1677,7 @@ get_arg_value(struct event_format *event, struct filter_arg *arg, struct record
 }
 
 static int test_num(struct event_format *event,
-		    struct filter_arg *arg, struct record *record)
+		    struct filter_arg *arg, struct pevent_record *record)
 {
 	unsigned long long lval, rval;
 
@@ -1709,7 +1709,7 @@ static int test_num(struct event_format *event,
 	}
 }
 
-static const char *get_field_str(struct filter_arg *arg, struct record *record)
+static const char *get_field_str(struct filter_arg *arg, struct pevent_record *record)
 {
 	const char *val = record->data + arg->str.field->offset;
 
@@ -1727,7 +1727,7 @@ static const char *get_field_str(struct filter_arg *arg, struct record *record)
 }
 
 static int test_str(struct event_format *event,
-		    struct filter_arg *arg, struct record *record)
+		    struct filter_arg *arg, struct pevent_record *record)
 {
 	const char *val;
 
@@ -1757,7 +1757,7 @@ static int test_str(struct event_format *event,
 }
 
 static int test_op(struct event_format *event,
-		   struct filter_arg *arg, struct record *record)
+		   struct filter_arg *arg, struct pevent_record *record)
 {
 	switch (arg->op.type) {
 	case FILTER_OP_AND:
@@ -1778,7 +1778,7 @@ static int test_op(struct event_format *event,
 }
 
 static int test_filter(struct event_format *event,
-		       struct filter_arg *arg, struct record *record)
+		       struct filter_arg *arg, struct pevent_record *record)
 {
 	switch (arg->type) {
 	case FILTER_ARG_BOOLEAN:
@@ -1843,7 +1843,7 @@ int pevent_event_filtered(struct event_filter *filter,
  * -2 - if no filters exist
  */
 int pevent_filter_match(struct event_filter *filter,
-			struct record *record)
+			struct pevent_record *record)
 {
 	struct pevent *pevent = filter->pevent;
 	struct filter_type *filter_type;
tools/perf/util/trace-event-parse.c +4 -4
index 39f22f8..df2fddb 100644
@@ -152,7 +152,7 @@ void *raw_field_ptr(struct event_format *event, const char *name, void *data)
 
 int trace_parse_common_type(void *data)
 {
-	struct record record;
+	struct pevent_record record;
 
 	record.data = data;
 	return pevent_data_type(pevent, &record);
@@ -160,7 +160,7 @@ int trace_parse_common_type(void *data)
 
 int trace_parse_common_pid(void *data)
 {
-	struct record record;
+	struct pevent_record record;
 
 	record.data = data;
 	return pevent_data_pid(pevent, &record);
@@ -180,7 +180,7 @@ struct event_format *trace_find_event(int type)
 void print_trace_event(int cpu, void *data, int size)
 {
 	struct event_format *event;
-	struct record record;
+	struct pevent_record record;
 	struct trace_seq s;
 	int type;
 
@@ -206,7 +206,7 @@ void print_trace_event(int cpu, void *data, int size)
 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
 		  char *comm)
 {
-	struct record record;
+	struct pevent_record record;
 	struct trace_seq s;
 	int pid;
 
tools/perf/util/trace-event-read.c +5 -5
index 29b9206..f097e0d 100644
@@ -292,7 +292,7 @@ struct cpu_data {
 	unsigned long long	offset;
 	unsigned long long	size;
 	unsigned long long	timestamp;
-	struct record		*next;
+	struct pevent_record	*next;
 	char			*page;
 	int			cpu;
 	int			index;
@@ -377,9 +377,9 @@ static int calc_index(void *ptr, int cpu)
 	return (unsigned long)ptr - (unsigned long)cpu_data[cpu].page;
 }
 
-struct record *trace_peek_data(int cpu)
+struct pevent_record *trace_peek_data(int cpu)
 {
-	struct record *data;
+	struct pevent_record *data;
 	void *page = cpu_data[cpu].page;
 	int idx = cpu_data[cpu].index;
 	void *ptr = page + idx;
@@ -477,9 +477,9 @@ read_again:
 	return data;
 }
 
-struct record *trace_read_data(int cpu)
+struct pevent_record *trace_read_data(int cpu)
 {
-	struct record *data;
+	struct pevent_record *data;
 
 	data = trace_peek_data(cpu);
 	cpu_data[cpu].next = NULL;
tools/perf/util/trace-event.h +2 -2
index 112bc2a..639852a 100644
@@ -38,7 +38,7 @@ void print_event(int cpu, void *data, int size, unsigned long long nsecs,
 int parse_ftrace_file(char *buf, unsigned long size);
 int parse_event_file(char *buf, unsigned long size, char *sys);
 
-struct record *trace_peek_data(int cpu);
+struct pevent_record *trace_peek_data(int cpu);
 struct event_format *trace_find_event(int type);
 
 unsigned long long
@@ -57,7 +57,7 @@ struct event_format *trace_find_next_event(struct event_format *event);
 unsigned long long read_size(void *ptr, int size);
 unsigned long long eval_flag(const char *flag);
 
-struct record *trace_read_data(int cpu);
+struct pevent_record *trace_read_data(int cpu);
 int read_tracing_data(int fd, struct list_head *pattrs);
 
 struct tracing_data {
Signature · 1 line
1.7.5.4
#16 lore raw
In reply to Frederic Weisbecker
Quoted 9 lines · Frederic Weisbecker

Hi,

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Quoted 6 lines

Default target is a static library in tools/libtraceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

It gives me:

/home/mingo/tip/tools/lib/traceevent/parse-filter.c: In function ‘create_arg_item’:
/home/mingo/tip/tools/lib/traceevent/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare] /home/mingo/tip/tools/lib/traceevent/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]

Had this been in tools/perf/ it would use -Werror already and you'd have fixed it, not requiring me to unpull these bits :-/

So can we please make a libevent.so, built sanely within tools/perf/lib/ or such and distributed together with perf so that the two can never get out of sync?

Thanks,

Ingo

#17 lore raw

Hi,

Quoted 18 lines · Ingo Molnar
Quoted 9 lines · Frederic Weisbecker

Hi,

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Quoted 6 lines

Default target is a static library in tools/libtraceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

Quoted 9 lines

It gives me:

/home/mingo/tip/tools/lib/traceevent/parse-filter.c: In function ‘create_arg_item’:
/home/mingo/tip/tools/lib/traceevent/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare] /home/mingo/tip/tools/lib/traceevent/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]

Had this been in tools/perf/ it would use -Werror already and you'd have fixed it, not requiring me to unpull these bits :-/

I already submitted a patch for it (along with other fixes) to Steven.

lkml.indiana.edu/hypermail/linux/kernel/1204.2/03713.html

Thanks,
Namhyung

Quoted 7 lines

So can we please make a libevent.so, built sanely within tools/perf/lib/ or such and distributed together with perf so that the two can never get out of sync?

Thanks,

Ingo

#18 lore raw
Quoted 4 lines · Namhyung Kim

I already submitted a patch for it (along with other fixes) to Steven.

lkml.indiana.edu/hypermail/linux/kernel/1204.2/03713.html

Thanks for the reminder. I've tested the patches and even added my own
patch on top. But I never pushed it to kernel.org :-p I think
kernel.org was acting funny that day, so I did other things, and then forgot that I never did the final step.

Pushed now.

Thanks!

-- Steve

#19 lore raw
In reply to Ingo Molnar
Quoted 5 lines · Ingo Molnar

It gives me:

/home/mingo/tip/tools/lib/traceevent/parse-filter.c: In function ‘create_arg_item’:
/home/mingo/tip/tools/lib/traceevent/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare] /home/mingo/tip/tools/lib/traceevent/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]

Note, older gcc did not error with these (as I'm still on F13 I have an older gcc). Otherwise I would have fixed them a long time ago. And -Werror would have not helped.

-- Steve

#20 lore raw
In reply to Ingo Molnar
Quoted 3 lines · Ingo Molnar

So can we please make a libevent.so, built sanely within tools/perf/lib/ or such and distributed together with perf so that the two can never get out of sync?

If you do this, you need to find a way to turn off -Wswitch-enum as that seems to (at least on my gcc) ignore defaults.

Thus we end up with:

Makefile +0 -0
index 18ad079..217548b 100644
parse-filter.c +0 -0
index d09fbd2..0ac249c 100644
@@ -367,6 +367,12 @@ create_arg_item(struct event_format *event, const

char *token,
arg->type = FILTER_ARG_FIELD; arg->field.field = field;
break;
+ case EVENT_ERROR:
+ case EVENT_NONE:
+ case EVENT_SPACE:
+ case EVENT_NEWLINE:
+ case EVENT_OP:
+ case EVENT_DELIM:
default:
free_arg(arg);
show_error(error_str, "expected a value but found %s",

I found that I added over 20 of these trying to keep -Wswitch-enum happy, before i decided to give up (there's many more than 20 places that need updates).

Looking at what was done in the current code, there's lots of :

case PRINT_NULL:
case PRINT_FIELD ... PRINT_SYMBOL:
case PRINT_STRING:
default:

Which looks more of a maintenance nightmare. How does this help? The FOO ... BAR, will hide the same errors that you are trying to prevent. If you were suppose to handle something between FOO and BAR, then you just ignored it too.

It also makes that "default" redundant.

This is one of those warnings that causes more pain than it helps.

If you strongly believe that all these warnings are helpful, than we should push to add these warnings to the kernel too.

-- Steve

#21 lore raw
Quoted 31 lines · Steven Rostedt
Quoted 3 lines · Ingo Molnar

So can we please make a libevent.so, built sanely within tools/perf/lib/ or such and distributed together with perf so that the two can never get out of sync?

If you do this, you need to find a way to turn off -Wswitch-enum as that seems to (at least on my gcc) ignore defaults.

Thus we end up with:

Makefile +0 -0
index 18ad079..217548b 100644
parse-filter.c +6 -0
index d09fbd2..0ac249c 100644
@@ -367,6 +367,12 @@ create_arg_item(struct event_format *event, const
 char *token,
 		arg->type = FILTER_ARG_FIELD;
 		arg->field.field = field;
 		break;
+	case EVENT_ERROR:
+	case EVENT_NONE:
+	case EVENT_SPACE:
+	case EVENT_NEWLINE:
+	case EVENT_OP:
+	case EVENT_DELIM:
 	default:
 		free_arg(arg);
Quoted 1 line

show_error(error_str, "expected a value but found %s",

The advantage of this warning is that when a new enum value is added, every usage site is forced to consider it.

Code not using it indeed needs to be updated.

Quoted 9 lines

Looking at what was done in the current code, there's lots of :

case PRINT_NULL:
case PRINT_FIELD ... PRINT_SYMBOL:
case PRINT_STRING:
default:

Which looks more of a maintenance nightmare. How does this help? The FOO ... BAR, will hide the same errors that you are trying to prevent.

Indeed the FOO...BAR pattern should not be used (i.e. the above is a bug in essence), unless it's clearly some genuine same-type numeric range that is expressed, where new fields can never get inbetween.

Quoted 2 lines

If you were suppose to handle something between FOO and BAR, then you just ignored it too.

Correct.

Quoted 1 line

It also makes that "default" redundant.

Yes.

Quoted 2 lines

This is one of those warnings that causes more pain than it helps.

I disagree, when I switched to it then it found some real bugs and new changes were incremental.

Quoted 2 lines

If you strongly believe that all these warnings are helpful, than we should push to add these warnings to the kernel too.

For subsystems I maintain we could consider it - but for the kernel as a whole it would be quite some work.

Thanks,

Ingo

#22 lore raw
In reply to Ingo Molnar

Hi, Ingo

Quoted 21 lines · Ingo Molnar
Quoted 7 lines · Frederic Weisbecker

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Quoted 6 lines

Default target is a static library in tools/lib/traceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

It gives me:

/home/mingo/tip/tools/lib/traceevent/parse-filter.c: In function ‘create_arg_item’:
/home/mingo/tip/tools/lib/traceevent/parse-filter.c:343:9: warning: comparison between ‘enum filter_arg_type’ and ‘enum event_type’ [-Wenum-compare] /home/mingo/tip/tools/lib/traceevent/parse-filter.c:339:2: warning: case value ‘8’ not in enumerated type ‘enum filter_arg_type’ [-Wswitch]

Quoted 7 lines

Had this been in tools/perf/ it would use -Werror already and you'd have fixed it, not requiring me to unpull these bits :-/

So can we please make a libevent.so, built sanely within tools/perf/lib/ or such and distributed together with perf so that the two can never get out of sync?

So what are you gonna do with this patchset? If you merge this series, I can back-port latest changes on trace-cmd and do my further work like 'die' removal on it.

Thanks,
Namhyung

#23 lore raw
In reply to Frederic Weisbecker
Quoted 59 lines · Frederic Weisbecker

Hi,

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Default target is a static library in tools/libtraceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

Thanks.

Julia Lawall (1):
perf/events: Correct size given to memset

Steven Rostedt (10):
perf: Separate out trace-cmd parse-events from perf files tools/events: Add files to create libtraceevent.a
perf: Build libtraceevent.a
events: Update tools/lib/traceevent to work with perf
perf: Have perf use the new libtraceevent.a library perf/events: Add flag to produce nsec output
parse-events: Let pevent_free() take a NULL pointer
parse-events: Allow '*' and '/' operations in TP_printk
parse-event: Fix memset pointer size bug in handle
parse-events: Rename struct record to struct pevent_record

Tom Zanussi (1):
perf/events: Add flag/symbol format_flags

Vaibhav Nagarnaik (3):
parse-events: Handle invalid opcode parsing gracefully
parse-events: Handle opcode parsing error
parse-events: Support '+' opcode in print format

 tools/lib/traceevent/Makefile                      |  303 ++
 tools/lib/traceevent/event-parse.c                 | 5065 ++++++++++++++++++++
 tools/lib/traceevent/event-parse.h                 |  804 ++++
 tools/lib/traceevent/event-utils.h                 |   80 +
 tools/lib/traceevent/parse-filter.c                | 2262 +++++++++
 tools/lib/traceevent/parse-utils.c                 |  110 +
 tools/lib/traceevent/trace-seq.c                   |  200 +
 tools/perf/Makefile                                |   20 +-
 tools/perf/builtin-kmem.c                          |    6 +-
 tools/perf/builtin-lock.c                          |   26 +-
 tools/perf/builtin-sched.c                         |   42 +-
 tools/perf/builtin-script.c                        |    2 +-
 .../util/scripting-engines/trace-event-python.c    |   16 +-
 tools/perf/util/trace-event-info.c                 |    4 +-
 tools/perf/util/trace-event-parse.c                | 3220 +------------
 tools/perf/util/trace-event-read.c                 |   44 +-
 tools/perf/util/trace-event.h                      |  269 +-
 tools/scripts/Makefile.include                     |    1 +
Quoted 8 lines
 18 files changed, 9161 insertions(+), 3313 deletions(-)
 create mode 100644 tools/lib/traceevent/Makefile
 create mode 100644 tools/lib/traceevent/event-parse.c
 create mode 100644 tools/lib/traceevent/event-parse.h
 create mode 100644 tools/lib/traceevent/event-utils.h
 create mode 100644 tools/lib/traceevent/parse-filter.c
 create mode 100644 tools/lib/traceevent/parse-utils.c
 create mode 100644 tools/lib/traceevent/trace-seq.c

Pulled, thanks a lot Frederic!

Ingo

#24 lore raw
Quoted 71 lines · Ingo Molnar
Quoted 59 lines · Frederic Weisbecker

Hi,

This is essentially a rebase against latest tip:perf/core updates. Mostly due to conflicts against the perf Makefile updates.

I think we all agree that this library needs improvements but these should rather be done incrementally. The current perf trace event parsing is anyway much backward compared to that library.

Default target is a static library in tools/libtraceevent/libtraceevent.a

This can be pulled from:

git://github.com/fweisbec/tracing.git
perf/parse-events-4

Thanks.

Julia Lawall (1):
perf/events: Correct size given to memset

Steven Rostedt (10):
perf: Separate out trace-cmd parse-events from perf files tools/events: Add files to create libtraceevent.a
perf: Build libtraceevent.a
events: Update tools/lib/traceevent to work with perf
perf: Have perf use the new libtraceevent.a library perf/events: Add flag to produce nsec output
parse-events: Let pevent_free() take a NULL pointer
parse-events: Allow '*' and '/' operations in TP_printk
parse-event: Fix memset pointer size bug in handle
parse-events: Rename struct record to struct pevent_record

Tom Zanussi (1):
perf/events: Add flag/symbol format_flags

Vaibhav Nagarnaik (3):
parse-events: Handle invalid opcode parsing gracefully
parse-events: Handle opcode parsing error
parse-events: Support '+' opcode in print format

 tools/lib/traceevent/Makefile                      |  303 ++
 tools/lib/traceevent/event-parse.c                 | 5065 ++++++++++++++++++++
 tools/lib/traceevent/event-parse.h                 |  804 ++++
 tools/lib/traceevent/event-utils.h                 |   80 +
 tools/lib/traceevent/parse-filter.c                | 2262 +++++++++
 tools/lib/traceevent/parse-utils.c                 |  110 +
 tools/lib/traceevent/trace-seq.c                   |  200 +
 tools/perf/Makefile                                |   20 +-
 tools/perf/builtin-kmem.c                          |    6 +-
 tools/perf/builtin-lock.c                          |   26 +-
 tools/perf/builtin-sched.c                         |   42 +-
 tools/perf/builtin-script.c                        |    2 +-
 .../util/scripting-engines/trace-event-python.c    |   16 +-
 tools/perf/util/trace-event-info.c                 |    4 +-
 tools/perf/util/trace-event-parse.c                | 3220 +------------
 tools/perf/util/trace-event-read.c                 |   44 +-
 tools/perf/util/trace-event.h                      |  269 +-
 tools/scripts/Makefile.include                     |    1 +
Quoted 8 lines
 18 files changed, 9161 insertions(+), 3313 deletions(-)
 create mode 100644 tools/lib/traceevent/Makefile
 create mode 100644 tools/lib/traceevent/event-parse.c
 create mode 100644 tools/lib/traceevent/event-parse.h
 create mode 100644 tools/lib/traceevent/event-utils.h
 create mode 100644 tools/lib/traceevent/parse-filter.c
 create mode 100644 tools/lib/traceevent/parse-utils.c
 create mode 100644 tools/lib/traceevent/trace-seq.c
Quoted 3 lines

Pulled, thanks a lot Frederic!

Ingo

Thanks a lot Ingo, this is a great step forward for our tools.

Now I guess we can start to think of backporting the remaining fixes on the parse event code that reside in trace-cmd and then trace-cmd can start using that library.