Skip to contentSkip to conversation

perf util: More cleanups on tracepoint handling

PATCH New Namhyung Kim 1 participant 12 messages Apr 15, 2013 – Apr 17, 2013 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

cover perf util: More cleanups on tracepoint handling

Hello,

It seems some code that handle tracepoint events left unchanged when they were copied from the trace-cmd. This series tries to cleanup them by removing unnecessary function calls and variables and filling up some missing pieces.

It's based on my previous patchset on libtraceevent [1] and contains a user of the new pevent_set_page_size() API too. :)

You can get this from 'perf/cleanup' branch on my tree at:

git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git

Any comments are welcome, thanks.
Namhyung

[1] https://lkml.org/lkml/2013/4/11/194

Namhyung Kim (10):
perf util: Save page size in a trace file to pevent
perf util: Save long size of traced system
perf util: Make file/host_bigendian variable local
perf util: Skip reading header_event file
perf util: Parse header_page to get proper long size
perf util: Get rid of unused header_page_* variables
perf util: Move latency_format variable to builtin-script.c perf util: Rename read_*() functions in trace-event-info.c perf util: No need to call read_trace_init() in tracing_data_header() perf util: Remove unused enum and macro in trace-event.h

 tools/perf/builtin-script.c         |  1 +
 tools/perf/util/trace-event-info.c  | 22 ++++++++---------
 tools/perf/util/trace-event-parse.c |  6 -----
 tools/perf/util/trace-event-read.c  | 49 +++++++++++++++++++++----------------
 tools/perf/util/trace-event.h       | 15 ------------
 5 files changed, 39 insertions(+), 54 deletions(-)
Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 1/10 perf util: Save page size in a trace file to pevent

From: Namhyung Kim <[email protected]>

We now have page_size field in struct pevent, save the actual size of the system.

---
 tools/perf/util/trace-event-read.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/perf/util/trace-event-read.c +5 -2
index af215c0d2379..c6b491bcb8cd 100644
@@ -349,6 +349,7 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
 	int show_funcs = 0;
 	int show_printk = 0;
 	ssize_t size = -1;
+	int file_page_size;
 	struct pevent *pevent;
 	int err;
 
@@ -393,10 +394,12 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
 		goto out;
 	long_size = buf[0];
 
-	page_size = read4(pevent);
-	if (!page_size)
+	file_page_size = read4(pevent);
+	if (!file_page_size)
 		goto out;
 
+	pevent_set_page_size(pevent, file_page_size);
+
 	err = read_header_files(pevent);
 	if (err)
 		goto out;
Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

PATCH 2/10 perf util: Save long size of traced system

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

Save size of long type of system to struct pevent. Since original static variable was not used anywhere, just get rid of it.

---
 tools/perf/util/trace-event-read.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
tools/perf/util/trace-event-read.c +3 -8
index c6b491bcb8cd..6166294d7f22 100644
@@ -41,7 +41,6 @@ static int input_fd;
 
 int file_bigendian;
 int host_bigendian;
-static int long_size;
 
 static ssize_t trace_data_size;
 static bool repipe;
@@ -231,12 +230,6 @@ static int read_header_files(struct pevent *pevent)
 	size = read8(pevent);
 	skip(size);
 
-	/*
-	 * The size field in the page is of type long,
-	 * use that instead, since it represents the kernel.
-	 */
-	long_size = header_page_size_size;
-
 	if (do_read(buf, 13) < 0)
 		return -1;
 
@@ -349,6 +342,7 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
 	int show_funcs = 0;
 	int show_printk = 0;
 	ssize_t size = -1;
+	int file_long_size;
 	int file_page_size;
 	struct pevent *pevent;
 	int err;
@@ -392,12 +386,13 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
 
 	if (do_read(buf, 1) < 0)
 		goto out;
-	long_size = buf[0];
+	file_long_size = buf[0];
 
 	file_page_size = read4(pevent);
 	if (!file_page_size)
 		goto out;
 
+	pevent_set_long_size(pevent, file_long_size);
 	pevent_set_page_size(pevent, file_page_size);
 
 	err = read_header_files(pevent);
Signature · 1 line
1.7.11.7
author maintainer
#3 lore raw

PATCH 3/10 perf util: Make file/host_bigendian variable local

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

They're not used anywhere, just make them local variables.

---
 tools/perf/util/trace-event-read.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tools/perf/util/trace-event-read.c +2 -3
index 6166294d7f22..0dd9fbda88eb 100644
@@ -39,9 +39,6 @@
 
 static int input_fd;
 
-int file_bigendian;
-int host_bigendian;
-
 static ssize_t trace_data_size;
 static bool repipe;
 
@@ -342,6 +339,8 @@ ssize_t trace_report(int fd, struct pevent **ppevent, bool __repipe)
 	int show_funcs = 0;
 	int show_printk = 0;
 	ssize_t size = -1;
+	int file_bigendian;
+	int host_bigendian;
 	int file_long_size;
 	int file_page_size;
 	struct pevent *pevent;
Signature · 1 line
1.7.11.7
author maintainer
#4 lore raw

PATCH 4/10 perf util: Skip reading header_event file

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

It seems perf does not parse header_event file so we can skip it as we do for header_page file.

---
 tools/perf/util/trace-event-read.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
tools/perf/util/trace-event-read.c +1 -8
index 0dd9fbda88eb..fa45fca2a2d3 100644
@@ -212,7 +212,6 @@ static int read_ftrace_printk(struct pevent *pevent)
 static int read_header_files(struct pevent *pevent)
 {
 	unsigned long long size;
-	char *header_event;
 	char buf[BUFSIZ];
 	int ret = 0;
 
@@ -236,14 +235,8 @@ static int read_header_files(struct pevent *pevent)
 	}
 
 	size = read8(pevent);
-	header_event = malloc(size);
-	if (header_event == NULL)
-		return -1;
-
-	if (do_read(header_event, size) < 0)
-		ret = -1;
+	skip(size);
 
-	free(header_event);
 	return ret;
 }
 
Signature · 1 line
1.7.11.7
author maintainer
#5 lore raw

PATCH 5/10 perf util: Parse header_page to get proper long size

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

The header_page file describes the format of the ring buffer page which is used by ftrace (not perf). And size of "commit" field (I guess it's older name was 'size') represents the real size of long type used for kernel. So update the pevent's long size.

---
 tools/perf/util/trace-event-read.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
tools/perf/util/trace-event-read.c +18 -1
index fa45fca2a2d3..b4e8bdd13671 100644
@@ -212,6 +212,7 @@ static int read_ftrace_printk(struct pevent *pevent)
 static int read_header_files(struct pevent *pevent)
 {
 	unsigned long long size;
+	char *header_page;
 	char buf[BUFSIZ];
 	int ret = 0;
 
@@ -224,7 +225,23 @@ static int read_header_files(struct pevent *pevent)
 	}
 
 	size = read8(pevent);
-	skip(size);
+
+	if (do_read(buf, size) < 0)
+		return -1;
+
+	header_page = malloc(size);
+	if (header_page == NULL)
+		return -1;
+
+	if (!pevent_parse_header_page(pevent, header_page, size,
+				      pevent_get_long_size(pevent))) {
+		/*
+		 * The commit field in the page is of type long,
+		 * use that instead, since it represents the kernel.
+		 */
+		pevent_set_long_size(pevent, pevent->header_page_size_size);
+	}
+	free(header_page);
 
 	if (do_read(buf, 13) < 0)
 		return -1;
Signature · 1 line
1.7.11.7
author maintainer
#6 lore raw

PATCH v2 5/10 perf util: Parse header_page to get proper long size

From: Namhyung Kim <[email protected]>

The header_page file describes the format of the ring buffer page which is used by ftrace (not perf). And size of "commit" field (I guess it's older name was 'size') represents the real size of long type used for kernel. So update the pevent's long size.

---
It should read into header_page not buf.

 tools/perf/util/trace-event-read.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
tools/perf/util/trace-event-read.c +21 -1
index fa45fca2a2d3..f2112270c663 100644
@@ -212,6 +212,7 @@ static int read_ftrace_printk(struct pevent *pevent)
 static int read_header_files(struct pevent *pevent)
 {
 	unsigned long long size;
+	char *header_page;
 	char buf[BUFSIZ];
 	int ret = 0;
 
@@ -224,7 +225,26 @@ static int read_header_files(struct pevent *pevent)
 	}
 
 	size = read8(pevent);
-	skip(size);
+
+	header_page = malloc(size);
+	if (header_page == NULL)
+		return -1;
+
+	if (do_read(header_page, size) < 0) {
+		pr_debug("did not read header page");
+		free(header_page);
+		return -1;
+	}
+
+	if (!pevent_parse_header_page(pevent, header_page, size,
+				      pevent_get_long_size(pevent))) {
+		/*
+		 * The commit field in the page is of type long,
+		 * use that instead, since it represents the kernel.
+		 */
+		pevent_set_long_size(pevent, pevent->header_page_size_size);
+	}
+	free(header_page);
 
 	if (do_read(buf, 13) < 0)
 		return -1;
Signature · 1 line
1.7.11.7
author maintainer
#7 lore raw

PATCH 6/10 perf util: Get rid of unused header_page_* variables

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

They're not used anywhere and same information is kept in a pevent already. So let's get rid of them.

---
 tools/perf/util/trace-event-parse.c | 4 ----
 tools/perf/util/trace-event.h       | 4 ----
 2 files changed, 8 deletions(-)
tools/perf/util/trace-event-parse.c +0 -4
index 4454835a9ebc..0deae885c7ba 100644
@@ -28,10 +28,6 @@
 #include "util.h"
 #include "trace-event.h"
 
-int header_page_size_size;
-int header_page_ts_size;
-int header_page_data_offset;
-
 bool latency_format;
 
 struct pevent *read_trace_init(int file_bigendian, int host_bigendian)
tools/perf/util/trace-event.h +0 -4
index 1978c398ad87..10d6e7b202c5 100644
@@ -10,10 +10,6 @@ struct perf_sample;
 union perf_event;
 struct perf_tool;
 
-extern int header_page_size_size;
-extern int header_page_ts_size;
-extern int header_page_data_offset;
-
 extern bool latency_format;
 extern struct pevent *perf_pevent;
 
Signature · 1 line
1.7.11.7
author maintainer
#8 lore raw

PATCH 7/10 perf util: Move latency_format variable to builtin-script.c

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

It's the only user of the variable, so move it.

---
 tools/perf/builtin-script.c         | 1 +
 tools/perf/util/trace-event-parse.c | 2 --
 tools/perf/util/trace-event.h       | 1 -
 3 files changed, 1 insertion(+), 3 deletions(-)
tools/perf/builtin-script.c +1 -0
index 92d4658f56fb..3de8979fe87d 100644
@@ -24,6 +24,7 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 static bool			no_callchain;
+static bool			latency_format;
 static bool			system_wide;
 static const char		*cpu_list;
 static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
tools/perf/util/trace-event-parse.c +0 -2
index 0deae885c7ba..fe7a27d67d2b 100644
@@ -28,8 +28,6 @@
 #include "util.h"
 #include "trace-event.h"
 
-bool latency_format;
-
 struct pevent *read_trace_init(int file_bigendian, int host_bigendian)
 {
 	struct pevent *pevent = pevent_alloc();
tools/perf/util/trace-event.h +0 -1
index 10d6e7b202c5..96ad22f98726 100644
@@ -10,7 +10,6 @@ struct perf_sample;
 union perf_event;
 struct perf_tool;
 
-extern bool latency_format;
 extern struct pevent *perf_pevent;
 
 enum {
Signature · 1 line
1.7.11.7
author maintainer
#9 lore raw

PATCH 8/10 perf util: Rename read_*() functions in trace-event-info.c

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

It's confusing to have same name for two difference functions which does something opposite way. Since what they do in this file is read *AND* writing some of tracing metadata files, rename them to record_*() looks better to me.

---
 tools/perf/util/trace-event-info.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
tools/perf/util/trace-event-info.c +10 -10
index 3917eb9a8479..9648175e2a1c 100644
@@ -160,7 +160,7 @@ out:
 	return err;
 }
 
-static int read_header_files(void)
+static int record_header_files(void)
 {
 	char *path;
 	struct stat st;
@@ -299,7 +299,7 @@ out:
 	return err;
 }
 
-static int read_ftrace_files(struct tracepoint_path *tps)
+static int record_ftrace_files(struct tracepoint_path *tps)
 {
 	char *path;
 	int ret;
@@ -328,7 +328,7 @@ static bool system_in_tp_list(char *sys, struct tracepoint_path *tps)
 	return false;
 }
 
-static int read_event_files(struct tracepoint_path *tps)
+static int record_event_files(struct tracepoint_path *tps)
 {
 	struct dirent *dent;
 	struct stat st;
@@ -403,7 +403,7 @@ out:
 	return err;
 }
 
-static int read_proc_kallsyms(void)
+static int record_proc_kallsyms(void)
 {
 	unsigned int size;
 	const char *path = "/proc/kallsyms";
@@ -421,7 +421,7 @@ static int read_proc_kallsyms(void)
 	return record_file(path, 4);
 }
 
-static int read_ftrace_printk(void)
+static int record_ftrace_printk(void)
 {
 	unsigned int size;
 	char *path;
@@ -583,19 +583,19 @@ struct tracing_data *tracing_data_get(struct list_head *pattrs,
 	err = tracing_data_header();
 	if (err)
 		goto out;
-	err = read_header_files();
+	err = record_header_files();
 	if (err)
 		goto out;
-	err = read_ftrace_files(tps);
+	err = record_ftrace_files(tps);
 	if (err)
 		goto out;
-	err = read_event_files(tps);
+	err = record_event_files(tps);
 	if (err)
 		goto out;
-	err = read_proc_kallsyms();
+	err = record_proc_kallsyms();
 	if (err)
 		goto out;
-	err = read_ftrace_printk();
+	err = record_ftrace_printk();
 
 out:
 	/*
Signature · 1 line
1.7.11.7
author maintainer
#10 lore raw

PATCH 9/10 perf util: No need to call read_trace_init() in tracing_data_header()

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

It's useless to call the read_trace_init() function at this time as we don't need a returned pevent and it makes me confusing. :)

---
 tools/perf/util/trace-event-info.c | 2 --
 1 file changed, 2 deletions(-)
tools/perf/util/trace-event-info.c +0 -2
index 9648175e2a1c..e85cbcf298f3 100644
@@ -520,8 +520,6 @@ static int tracing_data_header(void)
 	else
 		buf[0] = 0;
 
-	read_trace_init(buf[0], buf[0]);
-
 	if (write(output_fd, buf, 1) != 1)
 		return -1;
 
Signature · 1 line
1.7.11.7
author maintainer
#11 lore raw

PATCH 10/10 perf util: Remove unused enum and macro in trace-event.h

In reply to Namhyung Kim

From: Namhyung Kim <[email protected]>

They're internals of ftrace ring-buffer and not used in perf code directly. As it now resides on libtraceevent/kbuffer.h, just get rid of them.

---
 tools/perf/util/trace-event.h | 10 ----------
 1 file changed, 10 deletions(-)
tools/perf/util/trace-event.h +0 -10
index 96ad22f98726..929baae82f71 100644
@@ -12,16 +12,6 @@ struct perf_tool;
 
 extern struct pevent *perf_pevent;
 
-enum {
-	RINGBUF_TYPE_PADDING		= 29,
-	RINGBUF_TYPE_TIME_EXTEND	= 30,
-	RINGBUF_TYPE_TIME_STAMP		= 31,
-};
-
-#ifndef TS_SHIFT
-#define TS_SHIFT		27
-#endif
-
 int bigendian(void);
 
 struct pevent *read_trace_init(int file_bigendian, int host_bigendian);
Signature · 1 line
1.7.11.7