Skip to contentSkip to conversation

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

RFC PATCH In review Frederic Weisbecker 11 participants 50 messages Apr 5, 2012 – Apr 25, 2012 perf events

lore
Share & tools
lore
#0 lore raw

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

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
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]>
---
 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 820371f..6f93a99 100644
@@ -326,6 +326,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
@@ -387,6 +388,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.

#21 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]>
---
 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
#26 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]>
---
 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
#27 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]>
---
 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
#32 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]>
---
 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
#34 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]>
---
 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
#37 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]>
---
 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
#36 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]>
---
 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
#35 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]>
---
 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
#33 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]>
---
 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
#31 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]>
---
 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
#25 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]>
---
 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
#24 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]>
---
 tools/perf/Makefile                                |   16 +-
 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, 477 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 +9 -7
index 8e60e51..04c077a 100644
@@ -1,6 +1,9 @@
 ifeq ("$(origin O)", "command line")
 	OUTPUT := $(O)/
 	COMMAND_O := O=$(O)
+	EP_PATH = $(OUTPUT)/
+else
+	EP_PATH = $(EVENT_PARSE_DIR)/
 endif
 
 # The default target of this Makefile is...
@@ -183,7 +186,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
@@ -213,7 +216,8 @@ $(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
+LIBPARSEVENT = $(EP_PATH)libtraceevent.a
+EP_LIB := -L$(EP_PATH) -ltraceevent
 
 #
 # Single 'perf' binary right now:
@@ -330,7 +334,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
@@ -393,7 +396,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
@@ -437,7 +439,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.
@@ -746,7 +748,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 $@
 
@@ -853,7 +855,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,038 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.

#16 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]>
---
 tools/perf/Makefile |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/Makefile +10 -1
index 6f93a99..8e60e51 100644
@@ -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
+
 help:
 	@echo 'Perf make targets:'
 	@echo '  doc		- make *all* documentation (see below)'
Signature · 1 line
1.7.5.4
#4 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]>
---
 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.

#5 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

Quoted 18 lines · 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:

Quoted 7 lines

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.

I found that this lib needs to be an .so to work with trace-cmd's plugins.

David

#6 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

Quoted 3 lines · David Ahern

I found that this lib needs to be an .so to work with trace-cmd's plugins.

And not just trace-cmd. I want to get those plugins to also work with perf. That is, have the kvm plugin (et. al.) make it so that perf does not need to rely only on the TP_printk() in the format file.

But that said, it is trivial to make this into a .so. Just having a separate library would be a huge first step.

-- Steve

#7 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

Quoted 6 lines · Steven Rostedt
Quoted 3 lines · David Ahern

I found that this lib needs to be an .so to work with trace-cmd's plugins.

Quoted 6 lines

And not just trace-cmd. I want to get those plugins to also work with perf. That is, have the kvm plugin (et. al.) make it so that perf does not need to rely only on the TP_printk() in the format file.

But that said, it is trivial to make this into a .so. Just having a separate library would be a huge first step.

Right, I meant to get trace-cmd's plugins to work with perf.

I have a patch that applies to your set from last August for that purpose; it applies to Frederic's version just working on a header file name collision. I've been using the plugins-modified perf specifically for kvm events.

David

#38 lore raw
In reply to Frederic Weisbecker
Quoted 10 lines · Frederic Weisbecker

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

#28 lore raw

Re: [PATCH 08/15] perf/events: Correct size given to memset

In reply to Frederic Weisbecker
Quoted 27 lines · 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]>
---
 tools/lib/traceevent/event-parse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/lib/traceevent/event-parse.c +0 -0
index f012395..16da20c 100644

tools/lib/traceevent/event-parse.c process_fields(struct event_format *event, struct print_flag_sym **list, char ** · line 2079

Quoted 5 lines
tools/lib/traceevent/event-parse.c +1 -1
@@ -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));

This one is already upstream, you can drop it: 5660ce34241ab

Signature · 2 lines
Regards/Gruss,
    Boris.
#2 lore raw

Re: [PATCH 01/15] perf: Separate out trace-cmd parse-events from perf files

In reply to Frederic Weisbecker
Quoted 24 lines · Frederic Weisbecker

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]>
Quoted 9 lines
---
 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?

Signature · 2 lines
Regards/Gruss,
    Boris.
#8 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

In reply to Frederic Weisbecker
Quoted 101 lines · 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]>
---
 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 +41 -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))'

tools/lib/traceevent/Makefile line 51

Quoted 10 lines
tools/lib/traceevent/Makefile new file +10 -0
+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

FWIW, I'm moving all the Kbuild-related stuff into tools/scripts/Makefile.include: http://lkml.org/lkml/2012/3/23/167
so it could shave off a couple of lines from this one here.

Signature · 2 lines
Regards/Gruss,
    Boris.
#17 lore raw

Re: [PATCH 03/15] perf: Build libtraceevent.a

In reply to Frederic Weisbecker
Quoted 59 lines · 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]>
---
 tools/perf/Makefile |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/Makefile +6 -1
index 6f93a99..8e60e51 100644
@@ -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 $@
 

tools/perf/Makefile $(sort $(dir $(DIRECTORY_DEPS))): · line 858

Quoted 7 lines
tools/perf/Makefile +4 -0
@@ -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.

Signature · 2 lines
Regards/Gruss,
    Boris.
#22 lore raw

Re: [PATCH 04/15] events: Update tools/lib/traceevent to work with perf

In reply to Frederic Weisbecker
Quoted 4 lines · 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

Minor: judging by the patch below, you mean "event-utils.h" here.

Quoted 29 lines

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]>
---
 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 +0 -0
index 47a3227..3ce75b5 100644

tools/lib/traceevent/event-parse.c line 36

Quoted 4 lines
tools/lib/traceevent/event-parse.c +1 -0
@@ -33,6 +33,7 @@
 #include <errno.h>
 
 #include "event-parse.h"
+#include "event-utils.h"
	     ^^^^^^^^^^^^^
Signature · 2 lines
Regards/Gruss,
    Boris.
#29 lore raw

Re: [PATCH 08/15] perf/events: Correct size given to memset

In reply to Borislav Petkov
Quoted 30 lines · Borislav Petkov
Quoted 29 lines · 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]>
---
 tools/lib/traceevent/event-parse.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/lib/traceevent/event-parse.c +0 -0
index f012395..16da20c 100644
@@ -2076,7 +2076,7 @@ process_fields(struct event_format *event, struct print_flag_sym **list, char **
 			goto out_free;
 
Quoted 5 lines

tools/lib/traceevent/event-parse.c process_fields(struct event_format *event, struct print_flag_sym **list, char ** · line 2079

Quoted 3 lines
tools/lib/traceevent/event-parse.c +1 -1
 		field = malloc_or_die(sizeof(*field));
-		memset(field, 0, sizeof(field));
+		memset(field, 0, sizeof(*field));

This one is already upstream, you can drop it: 5660ce34241ab

Uf, nevermind, you're forward-porting those.

Signature · 2 lines
Regards/Gruss,
    Boris.
#30 lore raw

Re: [PATCH 08/15] perf/events: Correct size given to memset

Quoted 4 lines · Borislav Petkov
Quoted 1 line

This one is already upstream, you can drop it: 5660ce34241ab

Uf, nevermind, you're forward-porting those.

Yeah, I worked hard to keep the "author" of the original fixes done in perf.

-- Steve

#9 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

In reply to Frederic Weisbecker
Quoted 37 lines · 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]>
Quoted 1 line

---

<snip>

Btw, running this through checkpatch generates a load of warnings/errors and some of them actually could be worth fixing...

Quoted 44 lines
tools/lib/traceevent/event-parse.c new file +38 -0
new file mode 100644
index 0000000..47a3227
@@ -0,0 +1,4971 @@
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  The parts for function graph printing was taken and modified from the
+ *  Linux Kernel that were written by
+ *    - Copyright (C) 2009  Frederic Weisbecker,
+ *  Frederic Weisbecker gave his permission to relicense the code to
+ *  the Lesser General Public License.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "event-parse.h"
+
+static const char *input_buf;
+static unsigned long long input_buf_ptr;

tools/lib/traceevent/event-parse.c line 48

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+static unsigned long long input_buf_siz;
+
+static int show_warning = 1;
+
+#define do_warning(fmt, ...)				\
+	do {						\
+		if (show_warning)			\
+			warning(fmt, ##__VA_ARGS__);	\
+	} while (0)
+

Yeah, the name "do_warning" is awkward. Can we call it emit_warning or _warning or whatever?

Quoted 37 lines
tools/lib/traceevent/event-parse.c new file +37 -0
+static void init_input_buf(const char *buf, unsigned long long size)
+{
+	input_buf = buf;
+	input_buf_siz = size;
+	input_buf_ptr = 0;
+}
+
+const char *pevent_get_input_buf(void)
+{
+	return input_buf;
+}
+
+unsigned long long pevent_get_input_buf_ptr(void)
+{
+	return input_buf_ptr;
+}
+
+struct event_handler {
+	struct event_handler		*next;
+	int				id;
+	const char			*sys_name;
+	const char			*event_name;
+	pevent_event_handler_func	func;
+	void				*context;
+};
+
+struct pevent_func_params {
+	struct pevent_func_params	*next;
+	enum pevent_func_arg_type	type;
+};
+
+struct pevent_function_handler {
+	struct pevent_function_handler	*next;
+	enum pevent_func_arg_type	ret_type;
+	char				*name;
+	pevent_func_handler		func;
+	struct pevent_func_params	*params;

tools/lib/traceevent/event-parse.c line 95

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	int				nr_args;
+};
+
+static unsigned long long
+process_defined_func(struct trace_seq *s, void *data, int size,
+		     struct event_format *event, struct print_arg *arg);
+
+static void free_func_handle(struct pevent_function_handler *func);
+
+/**

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

tools/lib/traceevent/event-parse.c line 106

Quoted 11 lines
tools/lib/traceevent/event-parse.c new file +11 -0
+ * 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.

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

tools/lib/traceevent/event-parse.c line 112

Quoted 6 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+
+void breakpoint(void)
+{
+	static int x;
+	x++;
+}

This looks like a debugging leftover since it is not used anywhere...?

Quoted 103 lines
tools/lib/traceevent/event-parse.c new file +103 -0
+
+struct print_arg *alloc_arg(void)
+{
+	struct print_arg *arg;
+
+	arg = malloc_or_die(sizeof(*arg));
+	if (!arg)
+		return NULL;
+	memset(arg, 0, sizeof(*arg));
+
+	return arg;
+}
+
+struct cmdline {
+	char *comm;
+	int pid;
+};
+
+static int cmdline_cmp(const void *a, const void *b)
+{
+	const struct cmdline *ca = a;
+	const struct cmdline *cb = b;
+
+	if (ca->pid < cb->pid)
+		return -1;
+	if (ca->pid > cb->pid)
+		return 1;
+
+	return 0;
+}
+
+struct cmdline_list {
+	struct cmdline_list	*next;
+	char			*comm;
+	int			pid;
+};
+
+static int cmdline_init(struct pevent *pevent)
+{
+	struct cmdline_list *cmdlist = pevent->cmdlist;
+	struct cmdline_list *item;
+	struct cmdline *cmdlines;
+	int i;
+
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);
+
+	i = 0;
+	while (cmdlist) {
+		cmdlines[i].pid = cmdlist->pid;
+		cmdlines[i].comm = cmdlist->comm;
+		i++;
+		item = cmdlist;
+		cmdlist = cmdlist->next;
+		free(item);
+	}
+
+	qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
+
+	pevent->cmdlines = cmdlines;
+	pevent->cmdlist = NULL;
+
+	return 0;
+}
+
+static char *find_cmdline(struct pevent *pevent, int pid)
+{
+	const struct cmdline *comm;
+	struct cmdline key;
+
+	if (!pid)
+		return "<idle>";
+
+	if (!pevent->cmdlines)
+		cmdline_init(pevent);
+
+	key.pid = pid;
+
+	comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+
+	if (comm)
+		return comm->comm;
+	return "<...>";
+}
+
+/**
+ * pevent_pid_is_registered - return if a pid has a cmdline registered
+ * @pevent: handle for the pevent
+ * @pid: The pid to check if it has a cmdline registered with.
+ *
+ * Returns 1 if the pid has a cmdline mapped to it
+ * 0 otherwise.
+ */
+int pevent_pid_is_registered(struct pevent *pevent, int pid)
+{
+	const struct cmdline *comm;
+	struct cmdline key;
+
+	if (!pid)
+		return 1;
+
+	if (!pevent->cmdlines)
+		cmdline_init(pevent);

tools/lib/traceevent/event-parse.c line 225

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+
+	key.pid = pid;
+
+	comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+
+	if (comm)
+		return 1;
+	return 0;
+}

This one looks almost identical to find_cmdline() above, maybe unify?

Quoted 26 lines
tools/lib/traceevent/event-parse.c new file +26 -0
+
+/*
+ * If the command lines have been converted to an array, then
+ * we must add this pid. This is much slower than when cmdlines
+ * are added before the array is initialized.
+ */
+static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
+{
+	struct cmdline *cmdlines = pevent->cmdlines;
+	const struct cmdline *cmdline;
+	struct cmdline key;
+
+	if (!pid)
+		return 0;
+
+	/* avoid duplicates */
+	key.pid = pid;
+
+	cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+	if (cmdline) {
+		errno = EEXIST;
+		return -1;
+	}
+
+	cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1));

tools/lib/traceevent/event-parse.c line 261

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	if (!cmdlines) {
+		errno = ENOMEM;
+		return -1;
+	}
+
+	cmdlines[pevent->cmdline_count].pid = pid;
+	cmdlines[pevent->cmdline_count].comm = strdup(comm);
+	if (!cmdlines[pevent->cmdline_count].comm)
+		die("malloc comm");
+		

extraneous whitespace

Quoted 65 lines
tools/lib/traceevent/event-parse.c new file +65 -0
+	if (cmdlines[pevent->cmdline_count].comm)
+		pevent->cmdline_count++;
+
+	qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
+	pevent->cmdlines = cmdlines;
+
+	return 0;
+}
+
+/**
+ * pevent_register_comm - register a pid / comm mapping
+ * @pevent: handle for the pevent
+ * @comm: the command line to register
+ * @pid: the pid to map the command line to
+ *
+ * This adds a mapping to search for command line names with
+ * a given pid. The comm is duplicated.
+ */
+int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
+{
+	struct cmdline_list *item;
+
+	if (pevent->cmdlines)
+		return add_new_comm(pevent, comm, pid);
+
+	item = malloc_or_die(sizeof(*item));
+	item->comm = strdup(comm);
+	if (!item->comm)
+		die("malloc comm");
+	item->pid = pid;
+	item->next = pevent->cmdlist;
+
+	pevent->cmdlist = item;
+	pevent->cmdline_count++;
+
+	return 0;
+}
+
+struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+};
+
+struct func_list {
+	struct func_list	*next;
+	unsigned long long	addr;
+	char			*func;
+	char			*mod;
+};
+
+static int func_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+/*

tools/lib/traceevent/event-parse.c line 336

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ * We are searching for a record in between, not an exact
+ * match.
+ */
+static int func_bcmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if ((fa->addr == fb->addr) ||
+

superfluous newline?

Quoted 51 lines
tools/lib/traceevent/event-parse.c new file +51 -0
+	    (fa->addr > fb->addr &&
+	     fa->addr < (fb+1)->addr))
+		return 0;
+
+	if (fa->addr < fb->addr)
+		return -1;
+
+	return 1;
+}
+
+static int func_map_init(struct pevent *pevent)
+{
+	struct func_list *funclist;
+	struct func_list *item;
+	struct func_map *func_map;
+	int i;
+
+	func_map = malloc_or_die(sizeof(*func_map) * (pevent->func_count + 1));
+	funclist = pevent->funclist;
+
+	i = 0;
+	while (funclist) {
+		func_map[i].func = funclist->func;
+		func_map[i].addr = funclist->addr;
+		func_map[i].mod = funclist->mod;
+		i++;
+		item = funclist;
+		funclist = funclist->next;
+		free(item);
+	}
+
+	qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp);
+
+	/*
+	 * Add a special record at the end.
+	 */
+	func_map[pevent->func_count].func = NULL;
+	func_map[pevent->func_count].addr = 0;
+	func_map[pevent->func_count].mod = NULL;
+
+	pevent->func_map = func_map;
+	pevent->funclist = NULL;
+
+	return 0;
+}
+
+static struct func_map *
+find_func(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *func;
+	struct func_map key;

tools/lib/traceevent/event-parse.c line 397

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+
+	if (!pevent->func_map)
+		func_map_init(pevent);
+
+	key.addr = addr;
+
+	func = bsearch(&key, pevent->func_map, pevent->func_count,
+		       sizeof(*pevent->func_map), func_bcmp);
+
+	return func;

Simply do:

	return bsearch(&key, ...);
Quoted 79 lines
tools/lib/traceevent/event-parse.c new file +79 -0
+}
+
+/**
+ * pevent_find_function - find a function by a given address
+ * @pevent: handle for the pevent
+ * @addr: the address to find the function with
+ *
+ * Returns a pointer to the function stored that has the given
+ * address. Note, the address does not have to be exact, it
+ * will select the function that would contain the address.
+ */
+const char *pevent_find_function(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *map;
+
+	map = find_func(pevent, addr);
+	if (!map)
+		return NULL;
+
+	return map->func;
+}
+
+/**
+ * pevent_find_function_address - find a function address by a given address
+ * @pevent: handle for the pevent
+ * @addr: the address to find the function with
+ *
+ * Returns the address the function starts at. This can be used in
+ * conjunction with pevent_find_function to print both the function
+ * name and the function offset.
+ */
+unsigned long long
+pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *map;
+
+	map = find_func(pevent, addr);
+	if (!map)
+		return 0;
+
+	return map->addr;
+}
+
+/**
+ * pevent_register_function - register a function with a given address
+ * @pevent: handle for the pevent
+ * @function: the function name to register
+ * @addr: the address the function starts at
+ * @mod: the kernel module the function may be in (NULL for none)
+ *
+ * This registers a function name with an address and module.
+ * The @func passed in is duplicated.
+ */
+int pevent_register_function(struct pevent *pevent, char *func,
+			     unsigned long long addr, char *mod)
+{
+	struct func_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->funclist;
+	item->func = strdup(func);
+	if (mod)
+		item->mod = strdup(mod);
+	else
+		item->mod = NULL;
+	item->addr = addr;
+
+	pevent->funclist = item;
+
+	pevent->func_count++;
+
+	return 0;
+}
+
+/**
+ * pevent_print_funcs - print out the stored functions
+ * @pevent: handle for the pevent
+ *

tools/lib/traceevent/event-parse.c line 486

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ * 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.

Quoted 59 lines
tools/lib/traceevent/event-parse.c new file +59 -0
+		printf("%016llx %s",
+		       pevent->func_map[i].addr,
+		       pevent->func_map[i].func);
+		if (pevent->func_map[i].mod)
+			printf(" [%s]\n", pevent->func_map[i].mod);
+		else
+			printf("\n");
+	}
+}
+
+struct printk_map {
+	unsigned long long		addr;
+	char				*printk;
+};
+
+struct printk_list {
+	struct printk_list	*next;
+	unsigned long long	addr;
+	char			*printk;
+};
+
+static int printk_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+static void printk_map_init(struct pevent *pevent)
+{
+	struct printk_list *printklist;
+	struct printk_list *item;
+	struct printk_map *printk_map;
+	int i;
+
+	printk_map = malloc_or_die(sizeof(*printk_map) * (pevent->printk_count + 1));
+
+	printklist = pevent->printklist;
+
+	i = 0;
+	while (printklist) {
+		printk_map[i].printk = printklist->printk;
+		printk_map[i].addr = printklist->addr;
+		i++;
+		item = printklist;
+		printklist = printklist->next;
+		free(item);
+	}
+
+	qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp);
+
+	pevent->printk_map = printk_map;
+	pevent->printklist = NULL;

tools/lib/traceevent/event-parse.c line 555

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+}
+
+static struct printk_map *
+find_printk(struct pevent *pevent, unsigned long long addr)
+{
+	struct printk_map *printk;
+	struct printk_map key;
+
+	if (!pevent->printk_map)
+		printk_map_init(pevent);

You could pull those existence tests in the _init function above, i.e:

static void printk_map_init(struct pevent *pevent)

{
	if (pevent->printk_map)
		return;

so that you can keep the init details to the init functions. Ditto for the remaining _init(..) calls.

Quoted 37 lines
tools/lib/traceevent/event-parse.c new file +37 -0
+
+	key.addr = addr;
+
+	printk = bsearch(&key, pevent->printk_map, pevent->printk_count,
+			 sizeof(*pevent->printk_map), printk_cmp);
+
+	return printk;
+}
+
+/**
+ * pevent_register_print_string - register a string by its address
+ * @pevent: handle for the pevent
+ * @fmt: the string format to register
+ * @addr: the address the string was located at
+ *
+ * This registers a string by the address it was stored in the kernel.
+ * The @fmt passed in is duplicated.
+ */
+int pevent_register_print_string(struct pevent *pevent, char *fmt,
+				 unsigned long long addr)
+{
+	struct printk_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->printklist;
+	pevent->printklist = item;
+	item->printk = strdup(fmt);
+	item->addr = addr;
+
+	pevent->printk_count++;
+
+	return 0;
+}
+
+/**
+ * pevent_print_printk - print out the stored strings

tools/lib/traceevent/event-parse.c line 602

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ * @pevent: handle for the pevent
+ *
+ * This prints the string formats that were stored.
+ */
+void pevent_print_printk(struct pevent *pevent)
+{
+	int i;
+
+	if (!pevent->printk_map)
+		printk_map_init(pevent);

ditto.

tools/lib/traceevent/event-parse.c line 604

Quoted 2 lines
tools/lib/traceevent/event-parse.c new file +2 -0
+
+	for (i = 0; i < (int)pevent->printk_count; i++) {

ditto for making i an unsigned int.

tools/lib/traceevent/event-parse.c line 616

Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +12 -0
+		printf("%016llx %s\n",
+		       pevent->printk_map[i].addr,
+		       pevent->printk_map[i].printk);
+	}
+}
+
+static struct event_format *alloc_event(void)
+{
+	struct event_format *event;
+
+	event = malloc_or_die(sizeof(*event));
+	memset(event, 0, sizeof(*event));

perf (or tools/) probably needs a zalloc_or_die which memset's the ptr to 0 - this'll save a bunch of code.

Quoted 343 lines
tools/lib/traceevent/event-parse.c new file +343 -0
+
+	return event;
+}
+
+static void add_event(struct pevent *pevent, struct event_format *event)
+{
+	int i;
+
+	if (!pevent->events)
+		pevent->events = malloc_or_die(sizeof(event));
+	else
+		pevent->events =
+			realloc(pevent->events, sizeof(event) *
+				(pevent->nr_events + 1));
+	if (!pevent->events)
+		die("Can not allocate events");
+
+	for (i = 0; i < pevent->nr_events; i++) {
+		if (pevent->events[i]->id > event->id)
+			break;
+	}
+	if (i < pevent->nr_events)
+		memmove(&pevent->events[i + 1],
+			&pevent->events[i],
+			sizeof(event) * (pevent->nr_events - i));
+
+	pevent->events[i] = event;
+	pevent->nr_events++;
+
+	event->pevent = pevent;
+}
+
+static int event_item_type(enum event_type type)
+{
+	switch (type) {
+	case EVENT_ITEM ... EVENT_SQUOTE:
+		return 1;
+	case EVENT_ERROR ... EVENT_DELIM:
+	default:
+		return 0;
+	}
+}
+
+static void free_flag_sym(struct print_flag_sym *fsym)
+{
+	struct print_flag_sym *next;
+
+	while (fsym) {
+		next = fsym->next;
+		free(fsym->value);
+		free(fsym->str);
+		free(fsym);
+		fsym = next;
+	}
+}
+
+static void free_arg(struct print_arg *arg)
+{
+	struct print_arg *farg;
+
+	if (!arg)
+		return;
+
+	switch (arg->type) {
+	case PRINT_ATOM:
+		free(arg->atom.atom);
+		break;
+	case PRINT_FIELD:
+		free(arg->field.name);
+		break;
+	case PRINT_FLAGS:
+		free_arg(arg->flags.field);
+		free(arg->flags.delim);
+		free_flag_sym(arg->flags.flags);
+		break;
+	case PRINT_SYMBOL:
+		free_arg(arg->symbol.field);
+		free_flag_sym(arg->symbol.symbols);
+		break;
+	case PRINT_TYPE:
+		free(arg->typecast.type);
+		free_arg(arg->typecast.item);
+		break;
+	case PRINT_STRING:
+	case PRINT_BSTRING:
+		free(arg->string.string);
+		break;
+	case PRINT_DYNAMIC_ARRAY:
+		free(arg->dynarray.index);
+		break;
+	case PRINT_OP:
+		free(arg->op.op);
+		free_arg(arg->op.left);
+		free_arg(arg->op.right);
+		break;
+	case PRINT_FUNC:
+		while (arg->func.args) {
+			farg = arg->func.args;
+			arg->func.args = farg->next;
+			free_arg(farg);
+		}
+		break;
+
+	case PRINT_NULL:
+	default:
+		break;
+	}
+
+	free(arg);
+}
+
+static enum event_type get_type(int ch)
+{
+	if (ch == '\n')
+		return EVENT_NEWLINE;
+	if (isspace(ch))
+		return EVENT_SPACE;
+	if (isalnum(ch) || ch == '_')
+		return EVENT_ITEM;
+	if (ch == '\'')
+		return EVENT_SQUOTE;
+	if (ch == '"')
+		return EVENT_DQUOTE;
+	if (!isprint(ch))
+		return EVENT_NONE;
+	if (ch == '(' || ch == ')' || ch == ',')
+		return EVENT_DELIM;
+
+	return EVENT_OP;
+}
+
+static int __read_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr++];
+}
+
+static int __peek_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr];
+}
+
+/**
+ * pevent_peek_char - peek at the next character that will be read
+ *
+ * Returns the next character read, or -1 if end of buffer.
+ */
+int pevent_peek_char(void)
+{
+	return __peek_char();
+}
+
+static enum event_type force_token(const char *str, char **tok);
+
+static enum event_type __read_token(char **tok)
+{
+	char buf[BUFSIZ];
+	int ch, last_ch, quote_ch, next_ch;
+	int i = 0;
+	int tok_size = 0;
+	enum event_type type;
+
+	*tok = NULL;
+
+
+	ch = __read_char();
+	if (ch < 0)
+		return EVENT_NONE;
+
+	type = get_type(ch);
+	if (type == EVENT_NONE)
+		return type;
+
+	buf[i++] = ch;
+
+	switch (type) {
+	case EVENT_NEWLINE:
+	case EVENT_DELIM:
+		*tok = malloc_or_die(2);
+		(*tok)[0] = ch;
+		(*tok)[1] = 0;
+		return type;
+
+	case EVENT_OP:
+		switch (ch) {
+		case '-':
+			next_ch = __peek_char();
+			if (next_ch == '>') {
+				buf[i++] = __read_char();
+				break;
+			}
+			/* fall through */
+		case '+':
+		case '|':
+		case '&':
+		case '>':
+		case '<':
+			last_ch = ch;
+			ch = __peek_char();
+			if (ch != last_ch)
+				goto test_equal;
+			buf[i++] = __read_char();
+			switch (last_ch) {
+			case '>':
+			case '<':
+				goto test_equal;
+			default:
+				break;
+			}
+			break;
+		case '!':
+		case '=':
+			goto test_equal;
+		default: /* what should we do instead? */
+			break;
+		}
+		buf[i] = 0;
+		*tok = strdup(buf);
+		return type;
+
+ test_equal:
+		ch = __peek_char();
+		if (ch == '=')
+			buf[i++] = __read_char();
+		goto out;
+
+	case EVENT_DQUOTE:
+	case EVENT_SQUOTE:
+		/* don't keep quotes */
+		i--;
+		quote_ch = ch;
+		last_ch = 0;
+ concat:
+		do {
+			if (i == (BUFSIZ - 1)) {
+				buf[i] = 0;
+				if (*tok) {
+					*tok = realloc(*tok, tok_size + BUFSIZ);
+					if (!*tok)
+						return EVENT_NONE;
+					strcat(*tok, buf);
+				} else
+					*tok = strdup(buf);
+
+				if (!*tok)
+					return EVENT_NONE;
+				tok_size += BUFSIZ;
+				i = 0;
+			}
+			last_ch = ch;
+			ch = __read_char();
+			buf[i++] = ch;
+			/* the '\' '\' will cancel itself */
+			if (ch == '\\' && last_ch == '\\')
+				last_ch = 0;
+		} while (ch != quote_ch || last_ch == '\\');
+		/* remove the last quote */
+		i--;
+
+		/*
+		 * For strings (double quotes) check the next token.
+		 * If it is another string, concatinate the two.
+		 */
+		if (type == EVENT_DQUOTE) {
+			unsigned long long save_input_buf_ptr = input_buf_ptr;
+
+			do {
+				ch = __read_char();
+			} while (isspace(ch));
+			if (ch == '"')
+				goto concat;
+			input_buf_ptr = save_input_buf_ptr;
+		}
+
+		goto out;
+
+	case EVENT_ERROR ... EVENT_SPACE:
+	case EVENT_ITEM:
+	default:
+		break;
+	}
+
+	while (get_type(__peek_char()) == type) {
+		if (i == (BUFSIZ - 1)) {
+			buf[i] = 0;
+			if (*tok) {
+				*tok = realloc(*tok, tok_size + BUFSIZ);
+				if (!*tok)
+					return EVENT_NONE;
+				strcat(*tok, buf);
+			} else
+				*tok = strdup(buf);
+
+			if (!*tok)
+				return EVENT_NONE;
+			tok_size += BUFSIZ;
+			i = 0;
+		}
+		ch = __read_char();
+		buf[i++] = ch;
+	}
+
+ out:
+	buf[i] = 0;
+	if (*tok) {
+		*tok = realloc(*tok, tok_size + i);
+		if (!*tok)
+			return EVENT_NONE;
+		strcat(*tok, buf);
+	} else
+		*tok = strdup(buf);
+	if (!*tok)
+		return EVENT_NONE;
+
+	if (type == EVENT_ITEM) {
+		/*
+		 * Older versions of the kernel has a bug that
+		 * creates invalid symbols and will break the mac80211
+		 * parsing. This is a work around to that bug.
+		 *
+		 * See Linux kernel commit:
+		 *  811cb50baf63461ce0bdb234927046131fc7fa8b
+		 */
+		if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\"\%s\" ", tok);
+		} else if (strcmp(*tok, "STA_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\" sta:%pM\" ", tok);
+		} else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\" vif:%p(%d)\" ", tok);
+		}
+	}
+

tools/lib/traceevent/event-parse.c line 969

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	return type;
+}
+
+static enum event_type force_token(const char *str, char **tok)
+{
+	const char *save_input_buf;
+	unsigned long long save_input_buf_ptr;
+	unsigned long long save_input_buf_siz;
+	enum event_type type;
+	

Superfluous \t

Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +12 -0
+	/* save off the current input pointers */
+	save_input_buf = input_buf;
+	save_input_buf_ptr = input_buf_ptr;
+	save_input_buf_siz = input_buf_siz;
+
+	init_input_buf(str, strlen(str));
+
+	type = __read_token(tok);
+
+	/* reset back to original token */
+	input_buf = save_input_buf;
+	input_buf_ptr = save_input_buf_ptr;

tools/lib/traceevent/event-parse.c line 991

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	input_buf_siz = save_input_buf_siz;
+
+	return type;
+}
+
+static void free_token(char *tok)
+{
+	if (tok)
+		free(tok);
+}

According to MALLOC(3), free() can stomach NULL ptrs: "If ptr is NULL, no operation is performed."

Quoted 21 lines
tools/lib/traceevent/event-parse.c new file +21 -0
+
+static enum event_type read_token(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);
+		if (type != EVENT_SPACE)
+			return type;
+
+		free_token(*tok);
+	}
+
+	/* not reached */
+	*tok = NULL;
+	return EVENT_NONE;
+}
+
+/**
+ * pevent_read_token - access to utilites to use the pevent parser
+ * @tok: The token to return

tools/lib/traceevent/event-parse.c line 1022

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ *
+ * This will parse tokens from the string given by
+ * pevent_init_data().
+ *
+ * Returns the token type.
+ */
+enum event_type pevent_read_token(char **tok)
+{
+	return read_token(tok);
+}

Same here: can't we remove all those wrappers and have the library routines be called "pevent_" or whatever and all users of the library simply call them?

tools/lib/traceevent/event-parse.c line 1031

Quoted 9 lines
tools/lib/traceevent/event-parse.c new file +9 -0
+
+/**
+ * pevent_free_token - free a token returned by pevent_read_token
+ * @token: the token to free
+ */
+void pevent_free_token(char *token)
+{
+	free_token(token);
+}

Ditto.

tools/lib/traceevent/event-parse.c line 1033

Quoted 2 lines
tools/lib/traceevent/event-parse.c new file +2 -0
+
+/* no newline */

Please elaborate. Ah, event type cannot be NEWLINE additionally... Well, if that enum event_type were bits, you could unify this function with the read_token() above.

Quoted 6 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+static enum event_type read_token_item(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);

tools/lib/traceevent/event-parse.c line 1049

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+		if (type != EVENT_SPACE && type != EVENT_NEWLINE)
+			return type;
+		free_token(*tok);
+		*tok = NULL;
+	}
+
+	/* not reached */
+	*tok = NULL;
+	return EVENT_NONE;
+}

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

Signature · 2 lines
Regards/Gruss,
    Boris.
#39 lore raw
In reply to David Sharp

2012/4/6 David Sharp <[email protected]>:

Quoted 8 lines · Frederic Weisbecker
Quoted 7 lines

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).

Quoted 8 lines
Quoted 3 lines

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!

#3 lore raw

Re: [PATCH 01/15] perf: Separate out trace-cmd parse-events from perf files

In reply to Borislav Petkov

2012/4/6 Borislav Petkov <[email protected]>:

Quoted 38 lines · Frederic Weisbecker
Quoted 30 lines

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]>

---
 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 +++

Quoted 3 lines
 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:

Quoted 6 lines

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.

#18 lore raw

Re: [PATCH 03/15] perf: Build libtraceevent.a

In reply to Borislav Petkov

2012/4/6 Borislav Petkov <[email protected]>:

Quoted 63 lines · Frederic Weisbecker
Quoted 62 lines

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]>

---
 tools/perf/Makefile |   11 ++++++++++-

 1 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/Makefile +0 -0
index 6f93a99..8e60e51 100644
@@ -1,5 +1,6 @@
  ifeq ("$(origin O)", "command line")

      OUTPUT := $(O)/
+     COMMAND_O := O=$(O)
 endif

 # The default target of this Makefile is...

tools/perf/Makefile +3 -0
@@ -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

tools/perf/Makefile +0 -0
@@ -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 $@

tools/perf/Makefile +0 -0
@@ -847,6 +852,10 @@ $(sort $(dir $(DIRECTORY_DEPS))):
  $(LIB_FILE): $(LIB_OBJS)
       $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
 
Quoted 9 lines

tools/perf/Makefile $(sort $(dir $(DIRECTORY_DEPS))): · line 858

Quoted 4 lines
tools/perf/Makefile +4 -0
+# 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?

#19 lore raw

Re: [PATCH 03/15] perf: Build libtraceevent.a

Quoted 74 lines · Frederic Weisbecker

2012/4/6 Borislav Petkov <[email protected]>:

Quoted 63 lines · Frederic Weisbecker
Quoted 62 lines

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]>

---
 tools/perf/Makefile |   11 ++++++++++-

 1 files changed, 10 insertions(+), 1 deletions(-)
tools/perf/Makefile +0 -0
index 6f93a99..8e60e51 100644
@@ -1,5 +1,6 @@
  ifeq ("$(origin O)", "command line")

      OUTPUT := $(O)/
+     COMMAND_O := O=$(O)
 endif

 # The default target of this Makefile is...

tools/perf/Makefile +3 -0
@@ -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

tools/perf/Makefile +0 -0
@@ -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 $@

tools/perf/Makefile +0 -0
@@ -847,6 +852,10 @@ $(sort $(dir $(DIRECTORY_DEPS))):
  $(LIB_FILE): $(LIB_OBJS)
       $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS)
 
Quoted 9 lines

tools/perf/Makefile $(sort $(dir $(DIRECTORY_DEPS))): · line 858

Quoted 4 lines
tools/perf/Makefile +4 -0
+# 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.

Quoted 3 lines

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.

Signature · 2 lines
Regards/Gruss,
Boris.
#10 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

In reply to Borislav Petkov
Quoted 4 lines · Borislav Petkov

<snip>

Btw, running this through checkpatch generates a load of warnings/errors and some of them actually could be worth fixing...

Yeah, there were patches I added without running checkpatch (in the trace-cmd code).

Quoted 50 lines
Quoted 50 lines
tools/lib/traceevent/event-parse.c new file +43 -0
new file mode 100644
index 0000000..47a3227
@@ -0,0 +1,4971 @@
+/*
+ * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <[email protected]>
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License (not later!)
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ *  The parts for function graph printing was taken and modified from the
+ *  Linux Kernel that were written by
+ *    - Copyright (C) 2009  Frederic Weisbecker,
+ *  Frederic Weisbecker gave his permission to relicense the code to
+ *  the Lesser General Public License.
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <errno.h>
+
+#include "event-parse.h"
+
+static const char *input_buf;
+static unsigned long long input_buf_ptr;
+static unsigned long long input_buf_siz;
+
+static int show_warning = 1;
+
+#define do_warning(fmt, ...)				\
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 48

Quoted 5 lines
tools/lib/traceevent/event-parse.c new file +5 -0
+	do {						\
+		if (show_warning)			\
+			warning(fmt, ##__VA_ARGS__);	\
+	} while (0)
+

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" ;-)

Quoted 43 lines
Quoted 43 lines
tools/lib/traceevent/event-parse.c new file +42 -0
+static void init_input_buf(const char *buf, unsigned long long size)
+{
+	input_buf = buf;
+	input_buf_siz = size;
+	input_buf_ptr = 0;
+}
+
+const char *pevent_get_input_buf(void)
+{
+	return input_buf;
+}
+
+unsigned long long pevent_get_input_buf_ptr(void)
+{
+	return input_buf_ptr;
+}
+
+struct event_handler {
+	struct event_handler		*next;
+	int				id;
+	const char			*sys_name;
+	const char			*event_name;
+	pevent_event_handler_func	func;
+	void				*context;
+};
+
+struct pevent_func_params {
+	struct pevent_func_params	*next;
+	enum pevent_func_arg_type	type;
+};
+
+struct pevent_function_handler {
+	struct pevent_function_handler	*next;
+	enum pevent_func_arg_type	ret_type;
+	char				*name;
+	pevent_func_handler		func;
+	struct pevent_func_params	*params;
+	int				nr_args;
+};
+
+static unsigned long long
+process_defined_func(struct trace_seq *s, void *data, int size,
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 95

Quoted 5 lines
tools/lib/traceevent/event-parse.c new file +5 -0
+		     struct event_format *event, struct print_arg *arg);
+
+static void free_func_handle(struct pevent_function_handler *func);
+
+/**

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.

Quoted 15 lines

tools/lib/traceevent/event-parse.c line 106

Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +11 -0
+ * 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.

Quoted 3 lines

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.

Quoted 9 lines

tools/lib/traceevent/event-parse.c line 112

Quoted 7 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+
+void breakpoint(void)
+{
+	static int x;
+	x++;
+}

This looks like a debugging leftover since it is not used anywhere...?

Sorta. I kept it in trace-cmd on purpose, as I would set a breakpoint on this function, and just manually add this function around the code, and gdb would break on them. I found this easier than constantly needing to add a breakpoint somewhere.

That said, it does not belong here and should be removed.

Quoted 108 lines
Quoted 108 lines
tools/lib/traceevent/event-parse.c new file +107 -0
+
+struct print_arg *alloc_arg(void)
+{
+	struct print_arg *arg;
+
+	arg = malloc_or_die(sizeof(*arg));
+	if (!arg)
+		return NULL;
+	memset(arg, 0, sizeof(*arg));
+
+	return arg;
+}
+
+struct cmdline {
+	char *comm;
+	int pid;
+};
+
+static int cmdline_cmp(const void *a, const void *b)
+{
+	const struct cmdline *ca = a;
+	const struct cmdline *cb = b;
+
+	if (ca->pid < cb->pid)
+		return -1;
+	if (ca->pid > cb->pid)
+		return 1;
+
+	return 0;
+}
+
+struct cmdline_list {
+	struct cmdline_list	*next;
+	char			*comm;
+	int			pid;
+};
+
+static int cmdline_init(struct pevent *pevent)
+{
+	struct cmdline_list *cmdlist = pevent->cmdlist;
+	struct cmdline_list *item;
+	struct cmdline *cmdlines;
+	int i;
+
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);
+
+	i = 0;
+	while (cmdlist) {
+		cmdlines[i].pid = cmdlist->pid;
+		cmdlines[i].comm = cmdlist->comm;
+		i++;
+		item = cmdlist;
+		cmdlist = cmdlist->next;
+		free(item);
+	}
+
+	qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
+
+	pevent->cmdlines = cmdlines;
+	pevent->cmdlist = NULL;
+
+	return 0;
+}
+
+static char *find_cmdline(struct pevent *pevent, int pid)
+{
+	const struct cmdline *comm;
+	struct cmdline key;
+
+	if (!pid)
+		return "<idle>";
+
+	if (!pevent->cmdlines)
+		cmdline_init(pevent);
+
+	key.pid = pid;
+
+	comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+
+	if (comm)
+		return comm->comm;
+	return "<...>";
+}
+
+/**
+ * pevent_pid_is_registered - return if a pid has a cmdline registered
+ * @pevent: handle for the pevent
+ * @pid: The pid to check if it has a cmdline registered with.
+ *
+ * Returns 1 if the pid has a cmdline mapped to it
+ * 0 otherwise.
+ */
+int pevent_pid_is_registered(struct pevent *pevent, int pid)
+{
+	const struct cmdline *comm;
+	struct cmdline key;
+
+	if (!pid)
+		return 1;
+
+	if (!pevent->cmdlines)
+		cmdline_init(pevent);
+
+	key.pid = pid;
+
+	comm = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 225

Quoted 6 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+
+	if (comm)
+		return 1;
+	return 0;
+}

This one looks almost identical to find_cmdline() above, maybe unify?

Similar but slightly different. Maybe they can be merged, but as they are so small, it may not matter (for now).

Quoted 182 lines
Quoted 27 lines
tools/lib/traceevent/event-parse.c new file +26 -0
+
+/*
+ * If the command lines have been converted to an array, then
+ * we must add this pid. This is much slower than when cmdlines
+ * are added before the array is initialized.
+ */
+static int add_new_comm(struct pevent *pevent, const char *comm, int pid)
+{
+	struct cmdline *cmdlines = pevent->cmdlines;
+	const struct cmdline *cmdline;
+	struct cmdline key;
+
+	if (!pid)
+		return 0;
+
+	/* avoid duplicates */
+	key.pid = pid;
+
+	cmdline = bsearch(&key, pevent->cmdlines, pevent->cmdline_count,
+		       sizeof(*pevent->cmdlines), cmdline_cmp);
+	if (cmdline) {
+		errno = EEXIST;
+		return -1;
+	}
+
+	cmdlines = realloc(cmdlines, sizeof(*cmdlines) * (pevent->cmdline_count + 1));

tools/lib/traceevent/event-parse.c line 261

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	if (!cmdlines) {
+		errno = ENOMEM;
+		return -1;
+	}
+
+	cmdlines[pevent->cmdline_count].pid = pid;
+	cmdlines[pevent->cmdline_count].comm = strdup(comm);
+	if (!cmdlines[pevent->cmdline_count].comm)
+		die("malloc comm");
+		

extraneous whitespace

Quoted 65 lines
tools/lib/traceevent/event-parse.c new file +65 -0
+	if (cmdlines[pevent->cmdline_count].comm)
+		pevent->cmdline_count++;
+
+	qsort(cmdlines, pevent->cmdline_count, sizeof(*cmdlines), cmdline_cmp);
+	pevent->cmdlines = cmdlines;
+
+	return 0;
+}
+
+/**
+ * pevent_register_comm - register a pid / comm mapping
+ * @pevent: handle for the pevent
+ * @comm: the command line to register
+ * @pid: the pid to map the command line to
+ *
+ * This adds a mapping to search for command line names with
+ * a given pid. The comm is duplicated.
+ */
+int pevent_register_comm(struct pevent *pevent, const char *comm, int pid)
+{
+	struct cmdline_list *item;
+
+	if (pevent->cmdlines)
+		return add_new_comm(pevent, comm, pid);
+
+	item = malloc_or_die(sizeof(*item));
+	item->comm = strdup(comm);
+	if (!item->comm)
+		die("malloc comm");
+	item->pid = pid;
+	item->next = pevent->cmdlist;
+
+	pevent->cmdlist = item;
+	pevent->cmdline_count++;
+
+	return 0;
+}
+
+struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+};
+
+struct func_list {
+	struct func_list	*next;
+	unsigned long long	addr;
+	char			*func;
+	char			*mod;
+};
+
+static int func_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+/*

tools/lib/traceevent/event-parse.c line 336

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ * We are searching for a record in between, not an exact
+ * match.
+ */
+static int func_bcmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if ((fa->addr == fb->addr) ||
+

superfluous newline?

Quoted 51 lines
tools/lib/traceevent/event-parse.c new file +51 -0
+	    (fa->addr > fb->addr &&
+	     fa->addr < (fb+1)->addr))
+		return 0;
+
+	if (fa->addr < fb->addr)
+		return -1;
+
+	return 1;
+}
+
+static int func_map_init(struct pevent *pevent)
+{
+	struct func_list *funclist;
+	struct func_list *item;
+	struct func_map *func_map;
+	int i;
+
+	func_map = malloc_or_die(sizeof(*func_map) * (pevent->func_count + 1));
+	funclist = pevent->funclist;
+
+	i = 0;
+	while (funclist) {
+		func_map[i].func = funclist->func;
+		func_map[i].addr = funclist->addr;
+		func_map[i].mod = funclist->mod;
+		i++;
+		item = funclist;
+		funclist = funclist->next;
+		free(item);
+	}
+
+	qsort(func_map, pevent->func_count, sizeof(*func_map), func_cmp);
+
+	/*
+	 * Add a special record at the end.
+	 */
+	func_map[pevent->func_count].func = NULL;
+	func_map[pevent->func_count].addr = 0;
+	func_map[pevent->func_count].mod = NULL;
+
+	pevent->func_map = func_map;
+	pevent->funclist = NULL;
+
+	return 0;
+}
+
+static struct func_map *
+find_func(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *func;
+	struct func_map key;

tools/lib/traceevent/event-parse.c line 397

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+
+	if (!pevent->func_map)
+		func_map_init(pevent);
+
+	key.addr = addr;
+
+	func = bsearch(&key, pevent->func_map, pevent->func_count,
+		       sizeof(*pevent->func_map), func_bcmp);
+
+	return func;

Simply do:

Quoted 1 line
	return bsearch(&key, ...);

That may have been caused by removing code (or adding debug between the two).

But yeah, that should be simplified.

Quoted 84 lines
Quoted 84 lines
tools/lib/traceevent/event-parse.c new file +83 -0
+}
+
+/**
+ * pevent_find_function - find a function by a given address
+ * @pevent: handle for the pevent
+ * @addr: the address to find the function with
+ *
+ * Returns a pointer to the function stored that has the given
+ * address. Note, the address does not have to be exact, it
+ * will select the function that would contain the address.
+ */
+const char *pevent_find_function(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *map;
+
+	map = find_func(pevent, addr);
+	if (!map)
+		return NULL;
+
+	return map->func;
+}
+
+/**
+ * pevent_find_function_address - find a function address by a given address
+ * @pevent: handle for the pevent
+ * @addr: the address to find the function with
+ *
+ * Returns the address the function starts at. This can be used in
+ * conjunction with pevent_find_function to print both the function
+ * name and the function offset.
+ */
+unsigned long long
+pevent_find_function_address(struct pevent *pevent, unsigned long long addr)
+{
+	struct func_map *map;
+
+	map = find_func(pevent, addr);
+	if (!map)
+		return 0;
+
+	return map->addr;
+}
+
+/**
+ * pevent_register_function - register a function with a given address
+ * @pevent: handle for the pevent
+ * @function: the function name to register
+ * @addr: the address the function starts at
+ * @mod: the kernel module the function may be in (NULL for none)
+ *
+ * This registers a function name with an address and module.
+ * The @func passed in is duplicated.
+ */
+int pevent_register_function(struct pevent *pevent, char *func,
+			     unsigned long long addr, char *mod)
+{
+	struct func_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->funclist;
+	item->func = strdup(func);
+	if (mod)
+		item->mod = strdup(mod);
+	else
+		item->mod = NULL;
+	item->addr = addr;
+
+	pevent->funclist = item;
+
+	pevent->func_count++;
+
+	return 0;
+}
+
+/**
+ * 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)
+{
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 486

Quoted 6 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+	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.

Quoted 73 lines
Quoted 60 lines
tools/lib/traceevent/event-parse.c new file +59 -0
+		printf("%016llx %s",
+		       pevent->func_map[i].addr,
+		       pevent->func_map[i].func);
+		if (pevent->func_map[i].mod)
+			printf(" [%s]\n", pevent->func_map[i].mod);
+		else
+			printf("\n");
+	}
+}
+
+struct printk_map {
+	unsigned long long		addr;
+	char				*printk;
+};
+
+struct printk_list {
+	struct printk_list	*next;
+	unsigned long long	addr;
+	char			*printk;
+};
+
+static int printk_cmp(const void *a, const void *b)
+{
+	const struct func_map *fa = a;
+	const struct func_map *fb = b;
+
+	if (fa->addr < fb->addr)
+		return -1;
+	if (fa->addr > fb->addr)
+		return 1;
+
+	return 0;
+}
+
+static void printk_map_init(struct pevent *pevent)
+{
+	struct printk_list *printklist;
+	struct printk_list *item;
+	struct printk_map *printk_map;
+	int i;
+
+	printk_map = malloc_or_die(sizeof(*printk_map) * (pevent->printk_count + 1));
+
+	printklist = pevent->printklist;
+
+	i = 0;
+	while (printklist) {
+		printk_map[i].printk = printklist->printk;
+		printk_map[i].addr = printklist->addr;
+		i++;
+		item = printklist;
+		printklist = printklist->next;
+		free(item);
+	}
+
+	qsort(printk_map, pevent->printk_count, sizeof(*printk_map), printk_cmp);
+
+	pevent->printk_map = printk_map;
+	pevent->printklist = NULL;

tools/lib/traceevent/event-parse.c line 555

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+}
+
+static struct printk_map *
+find_printk(struct pevent *pevent, unsigned long long addr)
+{
+	struct printk_map *printk;
+	struct printk_map key;
+
+	if (!pevent->printk_map)
+		printk_map_init(pevent);

You could pull those existence tests in the _init function above, i.e:

Quoted 7 lines

static void printk_map_init(struct pevent *pevent)

{
	if (pevent->printk_map)
		return;

so that you can keep the init details to the init functions. Ditto for the remaining _init(..) calls.

Sure.

Quoted 56 lines
Quoted 38 lines
tools/lib/traceevent/event-parse.c new file +37 -0
+
+	key.addr = addr;
+
+	printk = bsearch(&key, pevent->printk_map, pevent->printk_count,
+			 sizeof(*pevent->printk_map), printk_cmp);
+
+	return printk;
+}
+
+/**
+ * pevent_register_print_string - register a string by its address
+ * @pevent: handle for the pevent
+ * @fmt: the string format to register
+ * @addr: the address the string was located at
+ *
+ * This registers a string by the address it was stored in the kernel.
+ * The @fmt passed in is duplicated.
+ */
+int pevent_register_print_string(struct pevent *pevent, char *fmt,
+				 unsigned long long addr)
+{
+	struct printk_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->printklist;
+	pevent->printklist = item;
+	item->printk = strdup(fmt);
+	item->addr = addr;
+
+	pevent->printk_count++;
+
+	return 0;
+}
+
+/**
+ * pevent_print_printk - print out the stored strings

tools/lib/traceevent/event-parse.c line 602

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+ * @pevent: handle for the pevent
+ *
+ * This prints the string formats that were stored.
+ */
+void pevent_print_printk(struct pevent *pevent)
+{
+	int i;
+
+	if (!pevent->printk_map)
+		printk_map_init(pevent);

ditto.

tools/lib/traceevent/event-parse.c line 604

Quoted 2 lines
tools/lib/traceevent/event-parse.c new file +2 -0
+
+	for (i = 0; i < (int)pevent->printk_count; i++) {

ditto for making i an unsigned int.

Quoted 15 lines

tools/lib/traceevent/event-parse.c line 616

Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +12 -0
+		printf("%016llx %s\n",
+		       pevent->printk_map[i].addr,
+		       pevent->printk_map[i].printk);
+	}
+}
+
+static struct event_format *alloc_event(void)
+{
+	struct event_format *event;
+
+	event = malloc_or_die(sizeof(*event));
+	memset(event, 0, sizeof(*event));

perf (or tools/) probably needs a zalloc_or_die which memset's the ptr to 0 - this'll save a bunch of code.

Yeah, agreed. I've just been too lazy to add them ;-)

Quoted 374 lines
Quoted 344 lines
tools/lib/traceevent/event-parse.c new file +343 -0
+
+	return event;
+}
+
+static void add_event(struct pevent *pevent, struct event_format *event)
+{
+	int i;
+
+	if (!pevent->events)
+		pevent->events = malloc_or_die(sizeof(event));
+	else
+		pevent->events =
+			realloc(pevent->events, sizeof(event) *
+				(pevent->nr_events + 1));
+	if (!pevent->events)
+		die("Can not allocate events");
+
+	for (i = 0; i < pevent->nr_events; i++) {
+		if (pevent->events[i]->id > event->id)
+			break;
+	}
+	if (i < pevent->nr_events)
+		memmove(&pevent->events[i + 1],
+			&pevent->events[i],
+			sizeof(event) * (pevent->nr_events - i));
+
+	pevent->events[i] = event;
+	pevent->nr_events++;
+
+	event->pevent = pevent;
+}
+
+static int event_item_type(enum event_type type)
+{
+	switch (type) {
+	case EVENT_ITEM ... EVENT_SQUOTE:
+		return 1;
+	case EVENT_ERROR ... EVENT_DELIM:
+	default:
+		return 0;
+	}
+}
+
+static void free_flag_sym(struct print_flag_sym *fsym)
+{
+	struct print_flag_sym *next;
+
+	while (fsym) {
+		next = fsym->next;
+		free(fsym->value);
+		free(fsym->str);
+		free(fsym);
+		fsym = next;
+	}
+}
+
+static void free_arg(struct print_arg *arg)
+{
+	struct print_arg *farg;
+
+	if (!arg)
+		return;
+
+	switch (arg->type) {
+	case PRINT_ATOM:
+		free(arg->atom.atom);
+		break;
+	case PRINT_FIELD:
+		free(arg->field.name);
+		break;
+	case PRINT_FLAGS:
+		free_arg(arg->flags.field);
+		free(arg->flags.delim);
+		free_flag_sym(arg->flags.flags);
+		break;
+	case PRINT_SYMBOL:
+		free_arg(arg->symbol.field);
+		free_flag_sym(arg->symbol.symbols);
+		break;
+	case PRINT_TYPE:
+		free(arg->typecast.type);
+		free_arg(arg->typecast.item);
+		break;
+	case PRINT_STRING:
+	case PRINT_BSTRING:
+		free(arg->string.string);
+		break;
+	case PRINT_DYNAMIC_ARRAY:
+		free(arg->dynarray.index);
+		break;
+	case PRINT_OP:
+		free(arg->op.op);
+		free_arg(arg->op.left);
+		free_arg(arg->op.right);
+		break;
+	case PRINT_FUNC:
+		while (arg->func.args) {
+			farg = arg->func.args;
+			arg->func.args = farg->next;
+			free_arg(farg);
+		}
+		break;
+
+	case PRINT_NULL:
+	default:
+		break;
+	}
+
+	free(arg);
+}
+
+static enum event_type get_type(int ch)
+{
+	if (ch == '\n')
+		return EVENT_NEWLINE;
+	if (isspace(ch))
+		return EVENT_SPACE;
+	if (isalnum(ch) || ch == '_')
+		return EVENT_ITEM;
+	if (ch == '\'')
+		return EVENT_SQUOTE;
+	if (ch == '"')
+		return EVENT_DQUOTE;
+	if (!isprint(ch))
+		return EVENT_NONE;
+	if (ch == '(' || ch == ')' || ch == ',')
+		return EVENT_DELIM;
+
+	return EVENT_OP;
+}
+
+static int __read_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr++];
+}
+
+static int __peek_char(void)
+{
+	if (input_buf_ptr >= input_buf_siz)
+		return -1;
+
+	return input_buf[input_buf_ptr];
+}
+
+/**
+ * pevent_peek_char - peek at the next character that will be read
+ *
+ * Returns the next character read, or -1 if end of buffer.
+ */
+int pevent_peek_char(void)
+{
+	return __peek_char();
+}
+
+static enum event_type force_token(const char *str, char **tok);
+
+static enum event_type __read_token(char **tok)
+{
+	char buf[BUFSIZ];
+	int ch, last_ch, quote_ch, next_ch;
+	int i = 0;
+	int tok_size = 0;
+	enum event_type type;
+
+	*tok = NULL;
+
+
+	ch = __read_char();
+	if (ch < 0)
+		return EVENT_NONE;
+
+	type = get_type(ch);
+	if (type == EVENT_NONE)
+		return type;
+
+	buf[i++] = ch;
+
+	switch (type) {
+	case EVENT_NEWLINE:
+	case EVENT_DELIM:
+		*tok = malloc_or_die(2);
+		(*tok)[0] = ch;
+		(*tok)[1] = 0;
+		return type;
+
+	case EVENT_OP:
+		switch (ch) {
+		case '-':
+			next_ch = __peek_char();
+			if (next_ch == '>') {
+				buf[i++] = __read_char();
+				break;
+			}
+			/* fall through */
+		case '+':
+		case '|':
+		case '&':
+		case '>':
+		case '<':
+			last_ch = ch;
+			ch = __peek_char();
+			if (ch != last_ch)
+				goto test_equal;
+			buf[i++] = __read_char();
+			switch (last_ch) {
+			case '>':
+			case '<':
+				goto test_equal;
+			default:
+				break;
+			}
+			break;
+		case '!':
+		case '=':
+			goto test_equal;
+		default: /* what should we do instead? */
+			break;
+		}
+		buf[i] = 0;
+		*tok = strdup(buf);
+		return type;
+
+ test_equal:
+		ch = __peek_char();
+		if (ch == '=')
+			buf[i++] = __read_char();
+		goto out;
+
+	case EVENT_DQUOTE:
+	case EVENT_SQUOTE:
+		/* don't keep quotes */
+		i--;
+		quote_ch = ch;
+		last_ch = 0;
+ concat:
+		do {
+			if (i == (BUFSIZ - 1)) {
+				buf[i] = 0;
+				if (*tok) {
+					*tok = realloc(*tok, tok_size + BUFSIZ);
+					if (!*tok)
+						return EVENT_NONE;
+					strcat(*tok, buf);
+				} else
+					*tok = strdup(buf);
+
+				if (!*tok)
+					return EVENT_NONE;
+				tok_size += BUFSIZ;
+				i = 0;
+			}
+			last_ch = ch;
+			ch = __read_char();
+			buf[i++] = ch;
+			/* the '\' '\' will cancel itself */
+			if (ch == '\\' && last_ch == '\\')
+				last_ch = 0;
+		} while (ch != quote_ch || last_ch == '\\');
+		/* remove the last quote */
+		i--;
+
+		/*
+		 * For strings (double quotes) check the next token.
+		 * If it is another string, concatinate the two.
+		 */
+		if (type == EVENT_DQUOTE) {
+			unsigned long long save_input_buf_ptr = input_buf_ptr;
+
+			do {
+				ch = __read_char();
+			} while (isspace(ch));
+			if (ch == '"')
+				goto concat;
+			input_buf_ptr = save_input_buf_ptr;
+		}
+
+		goto out;
+
+	case EVENT_ERROR ... EVENT_SPACE:
+	case EVENT_ITEM:
+	default:
+		break;
+	}
+
+	while (get_type(__peek_char()) == type) {
+		if (i == (BUFSIZ - 1)) {
+			buf[i] = 0;
+			if (*tok) {
+				*tok = realloc(*tok, tok_size + BUFSIZ);
+				if (!*tok)
+					return EVENT_NONE;
+				strcat(*tok, buf);
+			} else
+				*tok = strdup(buf);
+
+			if (!*tok)
+				return EVENT_NONE;
+			tok_size += BUFSIZ;
+			i = 0;
+		}
+		ch = __read_char();
+		buf[i++] = ch;
+	}
+
+ out:
+	buf[i] = 0;
+	if (*tok) {
+		*tok = realloc(*tok, tok_size + i);
+		if (!*tok)
+			return EVENT_NONE;
+		strcat(*tok, buf);
+	} else
+		*tok = strdup(buf);
+	if (!*tok)
+		return EVENT_NONE;
+
+	if (type == EVENT_ITEM) {
+		/*
+		 * Older versions of the kernel has a bug that
+		 * creates invalid symbols and will break the mac80211
+		 * parsing. This is a work around to that bug.
+		 *
+		 * See Linux kernel commit:
+		 *  811cb50baf63461ce0bdb234927046131fc7fa8b
+		 */
+		if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\"\%s\" ", tok);
+		} else if (strcmp(*tok, "STA_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\" sta:%pM\" ", tok);
+		} else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
+			free(*tok);
+			*tok = NULL;
+			return force_token("\" vif:%p(%d)\" ", tok);
+		}
+	}
+

tools/lib/traceevent/event-parse.c line 969

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	return type;
+}
+
+static enum event_type force_token(const char *str, char **tok)
+{
+	const char *save_input_buf;
+	unsigned long long save_input_buf_ptr;
+	unsigned long long save_input_buf_siz;
+	enum event_type type;
+	

Superfluous \t

Quoted 17 lines
tools/lib/traceevent/event-parse.c new file +17 -0
+	/* save off the current input pointers */
+	save_input_buf = input_buf;
+	save_input_buf_ptr = input_buf_ptr;
+	save_input_buf_siz = input_buf_siz;
+
+	init_input_buf(str, strlen(str));
+
+	type = __read_token(tok);
+
+	/* reset back to original token */
+	input_buf = save_input_buf;
+	input_buf_ptr = save_input_buf_ptr;
+	input_buf_siz = save_input_buf_siz;
+
+	return type;
+}
+
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 991

Quoted 5 lines
tools/lib/traceevent/event-parse.c new file +5 -0
+static void free_token(char *tok)
+{
+	if (tok)
+		free(tok);
+}

According to MALLOC(3), free() can stomach NULL ptrs: "If ptr is NULL, no operation is performed."

Hmm, I know that. I wonder why I did it that way?

Quoted 28 lines
Quoted 28 lines
tools/lib/traceevent/event-parse.c new file +27 -0
+
+static enum event_type read_token(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);
+		if (type != EVENT_SPACE)
+			return type;
+
+		free_token(*tok);
+	}
+
+	/* not reached */
+	*tok = NULL;
+	return EVENT_NONE;
+}
+
+/**
+ * pevent_read_token - access to utilites to use the pevent parser
+ * @tok: The token to return
+ *
+ * This will parse tokens from the string given by
+ * pevent_init_data().
+ *
+ * Returns the token type.
+ */
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 1022

Quoted 4 lines
tools/lib/traceevent/event-parse.c new file +4 -0
+enum event_type pevent_read_token(char **tok)
+{
+	return read_token(tok);
+}

Same here: can't we remove all those wrappers and have the library routines be called "pevent_" or whatever and all users of the library simply call them?

Sure, we can. I probably did this just to keep the typing down ;-)

Quoted 12 lines

tools/lib/traceevent/event-parse.c line 1031

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +9 -0
+
+/**
+ * pevent_free_token - free a token returned by pevent_read_token
+ * @token: the token to free
+ */
+void pevent_free_token(char *token)
+{
+	free_token(token);
+}

Ditto.

Ditto too!

Quoted 7 lines

tools/lib/traceevent/event-parse.c line 1033

Quoted 3 lines
tools/lib/traceevent/event-parse.c new file +2 -0
+
+/* no newline */

Please elaborate. Ah, event type cannot be NEWLINE additionally... Well, if that enum event_type were bits, you could unify this function with the read_token() above.

Perhaps, but that change is for another day.

Quoted 12 lines
Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +11 -0
+static enum event_type read_token_item(char **tok)
+{
+	enum event_type type;
+
+	for (;;) {
+		type = __read_token(tok);
+		if (type != EVENT_SPACE && type != EVENT_NEWLINE)
+			return type;
+		free_token(*tok);
+		*tok = NULL;
+	}
Quoted 9 lines

tools/lib/traceevent/event-parse.c line 1008

Quoted 5 lines
tools/lib/traceevent/event-parse.c new file +5 -0
+
+	/* not reached */
+	*tok = NULL;
+	return EVENT_NONE;
+}

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.

Thanks!

-- Steve

#11 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

Quoted 6 lines · Steven Rostedt
Quoted 2 lines

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?

[..]

Quoted 4 lines
Quoted 2 lines

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.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

+ * 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.

Quoted 8 lines

tools/lib/traceevent/event-parse.c line 106

Quoted 5 lines

+ */

tools/lib/traceevent/event-parse.c new file +4 -0
+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.

Quoted 3 lines

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.

:-)

Quoted 5 lines
Quoted 2 lines

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.

[..]

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines

+ * pevent_print_funcs - print out the stored functions
+ * @pevent: handle for the pevent
+ *
+ * This prints out the stored functions.
+ */

(quoted diff) +2 -0
+void pevent_print_funcs(struct pevent *pevent)
+{
Quoted 8 lines

tools/lib/traceevent/event-parse.c line 486

Quoted 6 lines
tools/lib/traceevent/event-parse.c new file +6 -0
+	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.

Quoted 2 lines

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.

[..]

Quoted 11 lines
Quoted 4 lines

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.

Signature · 2 lines
Regards/Gruss,
    Boris.
#40 lore raw
In reply to Frederic Weisbecker

Hi,

Quoted 6 lines · Frederic Weisbecker

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.

My concern is its error reporting mechanism - being a generic library it should support various environments like GUI as well as stdio. I see current warning, pr_stat and die can be overridden via strong symbol binding but it's just briefly documented and need more explicit handling IMHO - something like setup/reset_error_functions or so.

In addition, I think we should avoid using die-like functions that can terminate a client program in the middle of library calls. Instead, return proper error codes so that the client can handle its failure and take appropriate actions it needs. Making the library more robust is also needed of course - please see my other posting today [1].

Thanks,
Namhyung

[1] https://lkml.org/lkml/2012/4/8/177

#20 lore raw

Re: [PATCH 03/15] perf: Build libtraceevent.a

In reply to Borislav Petkov

2012/4/6 Borislav Petkov <[email protected]>:

Quoted 5 lines

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
Quoted 8 lines

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.

Yeah let's sort those details out once we have that library merged ;)

#23 lore raw

Re: [PATCH 04/15] events: Update tools/lib/traceevent to work with perf

In reply to Borislav Petkov

2012/4/6 Borislav Petkov <[email protected]>:

Quoted 7 lines · Frederic Weisbecker
Quoted 4 lines

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

Minor: judging by the patch below, you mean "event-utils.h" here.

Right, will fix the changelog.

#12 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

In reply to Frederic Weisbecker

Em Fri, Apr 06, 2012 at 12:47:53AM +0200, Frederic Weisbecker escreveu:

tools/lib/traceevent/event-parse.c line 129

Quoted 5 lines

From: Steven Rostedt <[email protected]>

tools/lib/traceevent/event-parse.c new file +4 -0
+struct cmdline {
+	char *comm;
+	int pid;
+};

In perf we have 'struct thread' for that and some more stuff, they are kept in an rb_tree located in a 'struct machine', 'machine's exist to support KVM.

At some point would be good to avoid this, but then it would make this code need parts of perf, that would have to then be moved to tools/libsymbol/ or some other more suitable name.

Quoted 17 lines
tools/lib/traceevent/event-parse.c new file +17 -0
+static int cmdline_cmp(const void *a, const void *b)
+{
+	const struct cmdline *ca = a;
+	const struct cmdline *cb = b;
+
+	if (ca->pid < cb->pid)
+		return -1;
+	if (ca->pid > cb->pid)
+		return 1;
+
+	return 0;
+}
+
+struct cmdline_list {
+	struct cmdline_list	*next;
+	char			*comm;
+	int			pid;

tools/lib/traceevent/event-parse.c line 157

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+};
+
+static int cmdline_init(struct pevent *pevent)
+{
+	struct cmdline_list *cmdlist = pevent->cmdlist;
+	struct cmdline_list *item;
+	struct cmdline *cmdlines;
+	int i;
+
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);

My biggest pet peeve, looks like this is New Hampshire code, all these "do foo or die" strikes a nerve in me :-(

Die calls in library code should just... die.

Only tools can die, libraries just can't, IMHO.

tools/lib/traceevent/event-parse.c line 311

Quoted 12 lines
tools/lib/traceevent/event-parse.c new file +12 -0
+struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+};
+
+struct func_list {
+	struct func_list	*next;
+	unsigned long long	addr;
+	char			*func;
+	char			*mod;
+};

For this we have tools/perf/utils/symbol.c, that supports userland as well as java JIT maps, etc. The perf.data file doesn't have to carry a copy of kallsyms, etc, build-id support is there to make sure we don't misresolve symbols using the right DSO found in a cache or in -debuginfo packages, etc.

tools/lib/traceevent/event-parse.c line 463

Quoted 13 lines
tools/lib/traceevent/event-parse.c new file +13 -0
+int pevent_register_function(struct pevent *pevent, char *func,
+			     unsigned long long addr, char *mod)
+{
+	struct func_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->funclist;
+	item->func = strdup(func);
+	if (mod)
+		item->mod = strdup(mod);
+	else
+		item->mod = NULL;

strdup can fail, and no, we shouldn't die if that happens :-)

#13 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

Quoted 11 lines · Arnaldo Carvalho de Melo

Em Fri, Apr 06, 2012 at 12:47:53AM +0200, Frederic Weisbecker escreveu:

tools/lib/traceevent/event-parse.c line 129

Quoted 5 lines

From: Steven Rostedt <[email protected]>

tools/lib/traceevent/event-parse.c new file +4 -0
+struct cmdline {
+	char *comm;
+	int pid;
+};

In perf we have 'struct thread' for that and some more stuff, they are kept in an rb_tree located in a 'struct machine', 'machine's exist to support KVM.

Quoted 3 lines

At some point would be good to avoid this, but then it would make this code need parts of perf, that would have to then be moved to tools/libsymbol/ or some other more suitable name.

Agreed, this can be broken out too. Lets see if we can get the code in first, and then start fixing it. As said, this would be the smoothest transition of getting trace-cmd libary into perf. As it has been tested quit intensively. Note, perf already has an older version built in. And does most of this nastiness already.

Quoted 32 lines
Quoted 18 lines
tools/lib/traceevent/event-parse.c new file +17 -0
+static int cmdline_cmp(const void *a, const void *b)
+{
+	const struct cmdline *ca = a;
+	const struct cmdline *cb = b;
+
+	if (ca->pid < cb->pid)
+		return -1;
+	if (ca->pid > cb->pid)
+		return 1;
+
+	return 0;
+}
+
+struct cmdline_list {
+	struct cmdline_list	*next;
+	char			*comm;
+	int			pid;

tools/lib/traceevent/event-parse.c line 157

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+};
+
+static int cmdline_init(struct pevent *pevent)
+{
+	struct cmdline_list *cmdlist = pevent->cmdlist;
+	struct cmdline_list *item;
+	struct cmdline *cmdlines;
+	int i;
+
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);

My biggest pet peeve, looks like this is New Hampshire code, all these "do foo or die" strikes a nerve in me :-(

Quoted 1 line

Die calls in library code should just... die.

I also agree :-) We can keep this for now, and then nuke it in the next patch. But to do so, would require an audit of this code. I could do the work in trace-cmd, and then we could port it. Or we can port this as is, and then update it.

The one thing I really wish C had, was the try/catch of C++. That would solve the error code issue. But for now we need to do it with goto's and such.

Quoted 13 lines

Only tools can die, libraries just can't, IMHO.

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+};
+
+struct func_list {
+	struct func_list	*next;
+	unsigned long long	addr;
+	char			*func;
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	char			*mod;
+};

For this we have tools/perf/utils/symbol.c, that supports userland as well as java JIT maps, etc. The perf.data file doesn't have to carry a copy of kallsyms, etc, build-id support is there to make sure we don't misresolve symbols using the right DSO found in a cache or in -debuginfo packages, etc.

This could be cleaned up too. Currently perf uses this code for the sw events (aka tracepoints) of the kernel. The func_map and friends are already used in perf.

Quoted 16 lines
Quoted 4 lines
tools/lib/traceevent/event-parse.c new file +3 -0
+int pevent_register_function(struct pevent *pevent, char *func,
+			     unsigned long long addr, char *mod)
+{

tools/lib/traceevent/event-parse.c line 463

Quoted 10 lines
tools/lib/traceevent/event-parse.c new file +10 -0
+	struct func_list *item;
+
+	item = malloc_or_die(sizeof(*item));
+
+	item->next = pevent->funclist;
+	item->func = strdup(func);
+	if (mod)
+		item->mod = strdup(mod);
+	else
+		item->mod = NULL;

strdup can fail, and no, we shouldn't die if that happens :-)

Again, this all needs to be audited. But this isn't much different than what perf already does with the tools/perf/util/trace-event-parse.c

Thus, getting the code out can be the first step. Cleaning it up into a nice library the second.

-- Steve

#14 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

2012/4/11 Steven Rostedt <[email protected]>:

Quoted 17 lines · Arnaldo Carvalho de Melo
Quoted 7 lines
Quoted 7 lines
tools/lib/traceevent/event-parse.c new file +7 -0
+int pevent_register_function(struct pevent *pevent, char *func,
+                        unsigned long long addr, char *mod)
+{
+   struct func_list *item;
+
+   item = malloc_or_die(sizeof(*item));
+
Quoted 8 lines
Quoted 6 lines

+   item->next = pevent->funclist;
+   item->func = strdup(func);
+   if (mod)
+           item->mod = strdup(mod);
+   else
+           item->mod = NULL;

strdup can fail, and no, we shouldn't die if that happens :-)

Quoted 5 lines

Again, this all needs to be audited. But this isn't much different than what perf already does with the tools/perf/util/trace-event-parse.c

Thus, getting the code out can be the first step. Cleaning it up into a nice library the second.

I agree. This is essentially moving the existing code in perf (but an improved version of it) to a standalone
library. This is a big problem on its own already. The big one in fact.

Improving it is certainly a necessary following up step. And in fact this is one of
the purposes of this library: make the improvements there easier. But I believe this
should be done incrementally, once we get the migration done.

#15 lore raw

Re: [PATCH 02/15] tools/events: Add files to create libtraceevent.a

In reply to Steven Rostedt

Em Wed, Apr 11, 2012 at 11:38:10AM -0400, Steven Rostedt escreveu:

Quoted 16 lines · Arnaldo Carvalho de Melo
Quoted 11 lines

Em Fri, Apr 06, 2012 at 12:47:53AM +0200, Frederic Weisbecker escreveu:

tools/lib/traceevent/event-parse.c line 129

Quoted 5 lines

From: Steven Rostedt <[email protected]>

tools/lib/traceevent/event-parse.c new file +4 -0
+struct cmdline {
+	char *comm;
+	int pid;
+};

In perf we have 'struct thread' for that and some more stuff, they are kept in an rb_tree located in a 'struct machine', 'machine's exist to support KVM.

Quoted 3 lines

At some point would be good to avoid this, but then it would make this code need parts of perf, that would have to then be moved to tools/libsymbol/ or some other more suitable name.

Quoted 5 lines

Agreed, this can be broken out too. Lets see if we can get the code in first, and then start fixing it. As said, this would be the smoothest transition of getting trace-cmd libary into perf. As it has been tested quit intensively. Note, perf already has an older version built in. And does most of this nastiness already.

I just wanted to make sure my main pet peeves and concerns were written down :-)

Knowing beforehand we agree on having them fixed eventually is enough for me, thanks.

Quoted 7 lines
Quoted 6 lines

tools/lib/traceevent/event-parse.c line 157

Quoted 1 line
tools/lib/traceevent/event-parse.c new file +1 -0
+	cmdlines = malloc_or_die(sizeof(*cmdlines) * pevent->cmdline_count);

My biggest pet peeve, looks like this is New Hampshire code, all these "do foo or die" strikes a nerve in me :-(

Die calls in library code should just... die.

Quoted 8 lines

I also agree :-) We can keep this for now, and then nuke it in the next patch. But to do so, would require an audit of this code. I could do the work in trace-cmd, and then we could port it. Or we can port this as is, and then update it.

The one thing I really wish C had, was the try/catch of C++. That would solve the error code issue. But for now we need to do it with goto's and such.

Yeah, we have to use what we can, and that is to do how we solve this matter in the kernel.

I.e. trying to follow the kernel coding style is something we should strive to in tools/ code, so that we encourage kernel developers to contribute as they will find the code familiar to how things are done in kernel land.

Quoted 13 lines
Quoted 12 lines

Only tools can die, libraries just can't, IMHO.

tools/lib/traceevent/event-parse.c line 304

Quoted 5 lines
tools/lib/traceevent/event-parse.c new file +5 -0
+struct func_map {
+	unsigned long long		addr;
+	char				*func;
+	char				*mod;
+};

For this we have tools/perf/utils/symbol.c, that supports userland as well as java JIT maps, etc. The perf.data file doesn't have to carry a copy of kallsyms, etc, build-id support is there to make sure we don't misresolve symbols using the right DSO found in a cache or in -debuginfo packages, etc.

Quoted 3 lines

This could be cleaned up too. Currently perf uses this code for the sw events (aka tracepoints) of the kernel. The func_map and friends are already used in perf.

Right, one more thing we agree we should fix at some point, good.

Quoted 7 lines
Quoted 6 lines

tools/lib/traceevent/event-parse.c line 463

Quoted 4 lines
tools/lib/traceevent/event-parse.c new file +4 -0
+	if (mod)
+		item->mod = strdup(mod);
+	else
+		item->mod = NULL;

strdup can fail, and no, we shouldn't die if that happens :-)

Quoted 5 lines

Again, this all needs to be audited. But this isn't much different than what perf already does with the tools/perf/util/trace-event-parse.c

Thus, getting the code out can be the first step. Cleaning it up into a nice library the second.

Ok.

- Arnaldo

#41 lore raw

Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

In reply to Frederic Weisbecker
Quoted 36 lines · Frederic Weisbecker

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.

Quoted 5 lines

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.

I'm trying to summarize some conversations that I got outside the mailing list (and I truly regret because it should have been debated publicly).

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

We indeed want to unify our tools, like merging trace-cmd into perf. And after talking with Steve about that, he told me he wants to have both tools unified as well. But he wants to keep libparseevent as a generic standalone library.

Indeed, it makes it possible for those who want to use trace events on their own tools to do it properly. I believe powertop fits into this scheme. Trace events are a generally useful feature. I wish we gather our efforts on one tool like perf but I don't want to force everyone to this path. So I personally agree with that library to be standalone.

Thus I think we are stuck again.

Now libtraceevent is perhaps going to become a separate project. I don't know.

By backporting and sending this libparsevent patch series, I felt pretty eager in that we could make a great step toward the tracing code unification.

But now with the current state of the picture, I'm worried about the future of tracing in perf tools. I don't want to spend my time to backport the features of the parse event code because I refuse to hack around politics disagreements. So probably the current code is going to rot. Unless somebody wants to handle this unpleasant task.

maintainer
#42 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

I mean, who gives a bother where all that crap lives, if its in the kernel tree its all close enough to keep an eye on.. its not like kernel/events/ and kernel/trace/ are the same directory.

Ingo, please could you lighten up and let people get stuff done? Merging the two implementations, wherever the result lives, is a better situation that two dis-joint implementations. So either let Frederic work or do it yourself but don't hand-wave and road-block stuff.

#43 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

Note, powertop has already pulled in the lib into itself, thus we now have 3 dis-joint locations. I can imagine it getting worse soon.

-- Steve

Quoted 9 lines

I mean, who gives a bother where all that crap lives, if its in the kernel tree its all close enough to keep an eye on.. its not like kernel/events/ and kernel/trace/ are the same directory.

Ingo, please could you lighten up and let people get stuff done? Merging the two implementations, wherever the result lives, is a better situation that two dis-joint implementations. So either let Frederic work or do it yourself but don't hand-wave and road-block stuff.

#44 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

Quoted 11 lines · Steven Rostedt
Quoted 7 lines · Peter Zijlstra
Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

Note, powertop has already pulled in the lib into itself, thus we now have 3 dis-joint locations. I can imagine it getting worse soon.

Oh, and there's the mce_record event which I'm going to be needing soon so this adds yet another user to this library - a minor one but still.

So yeah, we should probably get our stuff in order before going any further with events and stuff and all...

Signature · 2 lines
Regards/Gruss,
Boris.
#45 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra
Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

Quoted 8 lines

I mean, who gives a bother where all that crap lives, if its in the kernel tree its all close enough to keep an eye on.. its not like kernel/events/ and kernel/trace/ are the same directory.

Ingo, please could you lighten up and let people get stuff done? Merging the two implementations, wherever the result lives, is a better situation that two dis-joint implementations. So either let Frederic work or do it yourself but don't hand-wave and road-block stuff.

So you are saying that we have patches for a fully unified library and block it just because we have religious debates about the directory in which the library code should be?

Some folks should really visit their shrinks!

Thanks,

tglx

#46 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

In reply to Peter Zijlstra
Quoted 14 lines · Peter Zijlstra
Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

I mean, who gives a bother where all that crap lives, if its in the kernel tree its all close enough to keep an eye on.. its not like kernel/events/ and kernel/trace/ are the same directory.

Quoted 5 lines

Ingo, please could you lighten up and let people get stuff done? Merging the two implementations, wherever the result lives, is a better situation that two dis-joint implementations. So either let Frederic work or do it yourself but don't hand-wave and road-block stuff.

As long as perf builds it not as a DSO - or has it in tools/perf/libparseevent/ and co-installs the .so together with perf (and it's packaged together) I'm fine with it.

One thing that would suck is perf being bound by various versions of this library floating out there.

One reason why perf has become so popular is that it's self-sufficient to a large degree and is very easy to build/install. Lets not kill that aspect by the death of a thousand cuts.

We had nothing but pain from external libraries so far, and there's a reason why the Git project (3+ times larger than perf) avoids library dependencies like the plague...

Anyway, Frederic, mind posting a version that does the above, so I can have a look at how it all works in practice?

Thanks,

Ingo

#47 lore raw

Re: Our failure on tracing tools unification (Was: Re: [RFC][PATCH 00/15] tools: Unify perf and trace-cmd trace event format parsing v2)

Quoted 23 lines · Ingo Molnar
Quoted 14 lines · Peter Zijlstra
Quoted 2 lines · Frederic Weisbecker

Ingo doesn't seem to want this library outside perf in order to avoid the fragmentation of the efforts on tracing tools.

I really don't see the point.. parsing /debug/tracing/events/*/format gunk really is separate, furthermore things like powertop et al already are separate projects and really need this lib.

I mean, who gives a bother where all that crap lives, if its in the kernel tree its all close enough to keep an eye on.. its not like kernel/events/ and kernel/trace/ are the same directory.

Quoted 5 lines

Ingo, please could you lighten up and let people get stuff done? Merging the two implementations, wherever the result lives, is a better situation that two dis-joint implementations. So either let Frederic work or do it yourself but don't hand-wave and road-block stuff.

Quoted 3 lines

As long as perf builds it not as a DSO - or has it in tools/perf/libparseevent/ and co-installs the .so together with perf (and it's packaged together) I'm fine with it.

It's a static library (.a) in tools/lib
This way we ensure perf is not going to dynamically link to some random version. Besides it stays on the kernel tree so the sources can evolve on the same branch.

The reason why it's on tools/lib is that people don't want to force tools to depend on perf.

Quoted 2 lines

One thing that would suck is perf being bound by various versions of this library floating out there.

Sure, the fact it's static and is on the kernel tree prevents from that.

Quoted 4 lines

One reason why perf has become so popular is that it's self-sufficient to a large degree and is very easy to build/install. Lets not kill that aspect by the death of a thousand cuts.

Agreed. The perf makefile just relays on tools/lib so the dependency stays on the same tree and stays static so this is transparent to the user that doesn't need to juggle with dependencies.

Quoted 7 lines

We had nothing but pain from external libraries so far, and there's a reason why the Git project (3+ times larger than perf) avoids library dependencies like the plague...

Anyway, Frederic, mind posting a version that does the above, so I can have a look at how it all works in practice?

Ok I just rebased against latest perf/core updates and posted to you. I also pushed it to some branch in my tree (see cover letter)

Thanks!

Quoted 4 lines

Thanks,

Ingo

#48 lore raw

Re: Our failure on tracing tools unification

In reply to Ingo Molnar
Quoted 2 lines · mingo

[...] One thing that would suck is perf being bound by various versions of this library floating out there.

Could the event parser shared library be ABI-preserving? If so, what would perf have to fear?

Quoted 1 line

[...] We had nothing but pain from external libraries so far [...]

If the elfutils, newt, gtk, bfd, iberty, zlib, python libraries didn't contribute useful and un-rewriteable functionality, perf would not be using them.

- FChE

#49 lore raw

Re: Our failure on tracing tools unification

Em Wed, Apr 25, 2012 at 10:19:35AM -0400, Frank Ch. Eigler escreveu:

Quoted 8 lines
Quoted 2 lines · mingo

[...] One thing that would suck is perf being bound by various versions of this library floating out there.

Could the event parser shared library be ABI-preserving? If so, what would perf have to fear?

Perhaps its because people working on perf grew in the kernel, where we can change things as we see fit, i.e. change the networking API? Sure, we can go over the drivers and change them, its all in the same source tree, etc.

Quoted 5 lines
Quoted 1 line

[...] We had nothing but pain from external libraries so far [...]

If the elfutils, newt, gtk, bfd, iberty, zlib, python libraries didn't contribute useful and un-rewriteable functionality, perf would not be using them.

newt was a pain and will go away, 99% of things rely just on libslang, but even that one could go, bfd we use just for C++ demangling, so probably could go too.

- Arnaldo