[RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2

April 05th, 2012 - 06:50 pm ET by Frederic Weisbecker | Report spam
Hi,

So this is a new iteration of the libtracevent library, basically a
rebase of https://lkml.org/lkml/2011/8/5/299 against latest progresses
(latest tip/perf/core + tip/perf/urgent).

This library unifies the trace events parsing code between perf and
trace-cmd. I initially took this parsing code from trace-cmd to make
perf able to display trace-events and play with their contents.

But there is a continuous drift between perf and trace-cmd trace event
parsing code since then because the fork I did and the original code in
trace-cmd have never merged into a common entity. As a result, perf
stays backward because we haven't ported all the progresses that
trace-cmd did in this area.

Considering the reactions after the last attempt, it appears the
unification of this code is uncontroversial. What seem to cause
problems is how we do it:

- as an internal library inside perf, where other tools can hook
- as a self-contained library in tools/lib, independant from perf

The argument for the first solution was that trace events format
is not mature enough to be available for any tool and thus it's too
early to release a library that would engrave into the stone an
interface to it, preventing the events format from evolving in the
future.

However users of trace events are there already and they all use
their own parsing. They sometimes wrongly rely on the stability of a
whole event layout or its ascii structure. The lack of a common and
independant library is eventually what prevents us from doing progresses
or make evolutions on trace events.

So I think we really need to restart the debate. We strongly need to make
progresses in this area so I'm posting this iteration in the hope we
can move forward. With the coming of uprobes, there are some chances
that our tracing becomes more important in the future. Let's join
our efforts.

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/perf/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 | 17 +-
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 +-
17 files changed, 9157 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

1.7.5.4

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
email Follow the discussionReplies 41 repliesReplies Make a reply

Similar topics

Replies

#21 Frederic Weisbecker
April 06th, 2012 - 11:20 am ET | Report spam
2012/4/6 David Sharp :
On Thu, Apr 5, 2012 at 3:47 PM, Frederic Weisbecker wrote:

Hi,

So this is a new iteration of the libtracevent library, basically a
rebase of https://lkml.org/lkml/2011/8/5/299 against latest progresses
(latest tip/perf/core + tip/perf/urgent).

This library unifies the trace events parsing code between perf and
trace-cmd. I initially took this parsing code from trace-cmd to make
perf able to display trace-events and play with their contents.



Hi Frederic. Thanks for taking this on.

Could you consider adding these patches to this set?
https://lkml.org/lkml/2011/3/21/335



Oh sure! I'll catch up with the commits I missed in trace-cmd.

Thanks!
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
#22 Frederic Weisbecker
April 06th, 2012 - 11:30 am ET | Report spam
2012/4/6 Borislav Petkov :
On Fri, Apr 06, 2012 at 12:47:52AM +0200, Frederic Weisbecker wrote:
From: Steven Rostedt

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.

Signed-off-by: Steven Rostedt
Cc: Ingo Molnar
Cc: Thomas Gleixner
Cc: Peter Zijlstra
Cc: Arnaldo Carvalho de Melo
Cc: Steven Rostedt
Cc: Borislav Petkov
Cc: Jiri Olsa
Cc: Arun Sharma
Cc: Namhyung Kim
Signed-off-by: Frederic Weisbecker

 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



Err, maybe I'm missing something but why this additional step? I mean,
you could do:

patch 1: Add libtraceevent.a from trace-cmd
patch 2: Fixup perf so that it is ready to be switched to the new lib (specific
               wrappers, etc)
patch 3: switch it to libtraceevent.a

Only three patches, right?



Because this step splits what is purely perf code and what isn't. Then
later on we remove the non-perf part only.
I think it makes it smoother that way: we first identify what we want
to delete and layout the things in advance
by separating it. It makes the removal easier to review.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
#23 Frederic Weisbecker
April 06th, 2012 - 11:30 am ET | Report spam
2012/4/6 Borislav Petkov :
On Fri, Apr 06, 2012 at 12:47:54AM +0200, Frederic Weisbecker wrote:
From: Steven Rostedt

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

Signed-off-by: Steven Rostedt
Cc: Ingo Molnar
Cc: Thomas Gleixner
Cc: Peter Zijlstra
Cc: Arnaldo Carvalho de Melo
Cc: Steven Rostedt
Cc: Borislav Petkov
Cc: Jiri Olsa
Cc: Arun Sharma
Cc: Namhyung Kim
Signed-off-by: Frederic Weisbecker

 tools/perf/Makefile |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 6f93a99..8e60e51 100644
a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -1,5 +1,6 @@
 ifeq ("$(origin O)", "command line")
      OUTPUT := $(O)/
+     COMMAND_O := O=$(O)
 endif

 # The default target of this Makefile is...
@@ -211,6 +212,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:
 #
@@ -335,6 +339,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
@@ -741,7 +746,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 $@

@@ -847,6 +852,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
+



With a toplevel Makefile in tools/, this should be made into its own
target residing in tools/lib/traceevent/Makefile and a perf build should
be dependent on it instead of adding a perf-specific libtraceevent
target here.



Not sure what you mean. The libtraceevent makefile is standalone and
perf is dependant on it.
What am I missing?
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
#24 Borislav Petkov
April 06th, 2012 - 12:00 pm ET | Report spam
On Fri, Apr 06, 2012 at 05:26:35PM +0200, Frederic Weisbecker wrote:
2012/4/6 Borislav Petkov :
> On Fri, Apr 06, 2012 at 12:47:54AM +0200, Frederic Weisbecker wrote:
>> From: Steven Rostedt
>>
>> Have building perf also build libtraceevent.a. Currently, perf does
>> not use the code within libtraceevent.a, but it soon will.
>>
>> Signed-off-by: Steven Rostedt
>> Cc: Ingo Molnar
>> Cc: Thomas Gleixner
>> Cc: Peter Zijlstra
>> Cc: Arnaldo Carvalho de Melo
>> Cc: Steven Rostedt
>> Cc: Borislav Petkov
>> Cc: Jiri Olsa
>> Cc: Arun Sharma
>> Cc: Namhyung Kim
>> Signed-off-by: Frederic Weisbecker
>>
>>  tools/perf/Makefile |   11 ++++++++++-
>>  1 files changed, 10 insertions(+), 1 deletions(-)
>>
>> diff --git a/tools/perf/Makefile b/tools/perf/Makefile
>> index 6f93a99..8e60e51 100644
>> a/tools/perf/Makefile
>> +++ b/tools/perf/Makefile
>> @@ -1,5 +1,6 @@
>>  ifeq ("$(origin O)", "command line")
>>       OUTPUT := $(O)/
>> +     COMMAND_O := O=$(O)
>>  endif
>>
>>  # The default target of this Makefile is...
>> @@ -211,6 +212,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:
>>  #
>> @@ -335,6 +339,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
>> @@ -741,7 +746,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 $@
>>
>> @@ -847,6 +852,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
>> +
>
> With a toplevel Makefile in tools/, this should be made into its own
> target residing in tools/lib/traceevent/Makefile and a perf build should
> be dependent on it instead of adding a perf-specific libtraceevent
> target here.

Not sure what you mean. The libtraceevent makefile is standalone and
perf is dependant on it.
What am I missing?



Right, what I meant was to add the $(LIBTRACEEVENT): target above to the
toplevel Makefile so that when you're in the kernel source tree, you do

$ make tools/perf

it has a target $(LIBTRACEEVENT) dependent on it in the toplevel
Makefile instead of perf's Makefile to avoid duplication. Then, when
perf is rebuilt, it simply links with this lib. IOW, not have the "make
-C" call in perf's Makefile but in the toplevel Makefile because other
tools will want to use libtraceevent.a too and link against it.

Oh well, the toplevel Makefile patches aren't upstream either so we're
wasting cycles here, I'll fix that up when the times comes.

Thanks.

Regards/Gruss,
Boris.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
#25 Borislav Petkov
April 07th, 2012 - 05:10 am ET | Report spam
On Fri, Apr 06, 2012 at 06:15:44PM -0400, Steven Rostedt wrote:
> Yeah, the name "do_warning" is awkward. Can we call it emit_warning or
> _warning or whatever?

As this is just a macro defined as a helper in this file (not global),
I'm not sure it needs to be changed. "emit" has two more characters to
type over "do" ;-)



I know you're lazy :-) but "do_warning"? That's just nasty. How about
"_warning" or something?

[..]

> I see you're using kernel-doc style comments. Is this aimed at providing
> documentation for this library? If so, good idea!

That was the plan. It also forced me to document the API.



I like that. This'll probably give more users to the lib.

> > + * pevent_buffer_init - init buffer for parsing
> > + * @buf: buffer to parse
> > + * @size: the size of the buffer
> > + *
> > + * For use with pevent_read_token(), this initializes the internal
> > + * buffer that pevent_read_token() will parse.
> > + */
> > +void pevent_buffer_init(const char *buf, unsigned long long size)
> > +{
> > + init_input_buf(buf, size);
> > +}
>
> Can't we unify pevent_buffer_init and init_input_buf()? I mean, it is
> useless to have that kind of indirection.

Yeah I agree. This was more of a historical artifact. It use to be just
init_input_buf() then I needed to export it for other users. Instead of
doing a full rename, I cheesed out and did this.



:-)

> In general, is "pevent" the prefix for this library's functions which
> are getting exported to users?

Yep. It's the "namespace" used. But if people do not like it, we can
come up with another name. I just want it to be a short prefix.



Agreed, maybe even shorter: "te" for "traceevent" See, the namespace
of the kernel userspace tools is not that polluted yet so two-letter
namespaces are still up for grabs.

[..]

> > + * pevent_print_funcs - print out the stored functions
> > + * @pevent: handle for the pevent
> > + *
> > + * This prints out the stored functions.
> > + */
> > +void pevent_print_funcs(struct pevent *pevent)
> > +{
> > + int i;
> > +
> > + if (!pevent->func_map)
> > + func_map_init(pevent);
> > +
> > + for (i = 0; i < (int)pevent->func_count; i++) {
>
> simply declare i as "unsigned int" and you don't need the cast here.

I think I did that once but it caused problems elsewhere. But we can
look at it again.



It shouldn't since the 'i' is a local variable to that function and it
doesn't prevent you from keeping pevent->func_count an unsigned int
which is probably visible elsewhere.

[..]

>
> Ok, enough for today. I'll review the rest only if you really want me to
> :-).
>

Sure thanks for the comments now. The checkpatch clean ups should
probably be fixed before this goes in, and removing the breakpoint
function. But the other changes probably should wait. I would like what
goes in to be as close to what is in trace-cmd as possible. Perhaps, we
should add the cleanups as a separate patch. Just to have a nice
transition.



Ok, makes sense. Let's leave those for another day.

Regards/Gruss,
Boris.
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Replies Reply to this message
Help Create a new topicNext page Previous pageReplies Make a reply
Search Make your own search