Skip to contentSkip to conversation

perf: Fix timechart header handling

PATCH In review OGAWA Hirofumi 2 participants 10 messages Dec 6, 2009 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 perf: Fix timechart header handling

Hi,

Update "struct trace_entry" to match with current one. And remove "size" field from it.

If it has "size", it become cause of alignment mismatch of structure with kernel.

---

 tools/perf/builtin-timechart.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
tools/perf/builtin-timechart.c renamed from tools/perf/builtin-timechart.c~perf-fix-timechart-header-handling +8 -4
diff -puN tools/perf/builtin-timechart.c~perf-fix-timechart-header-handling tools/perf/builtin-timechart.c
@@ -302,12 +302,11 @@ process_exit_event(event_t *event)
 }
 
 struct trace_entry {
-	u32			size;
 	unsigned short		type;
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	int			tgid;
+	int			lock_depth;
 };
 
 struct power_entry {
@@ -489,6 +488,7 @@ process_sample_event(event_t *event)
 	u64 stamp = 0;
 	u32 cpu = 0;
 	u32 pid = 0;
+	u32 size, *size_ptr;
 	struct trace_entry *te;
 
 	if (sample_type & PERF_SAMPLE_IP)
@@ -518,9 +518,13 @@ process_sample_event(event_t *event)
 	if (sample_type & PERF_SAMPLE_PERIOD)
 		cursor++;
 
-	te = (void *)&event->sample.array[cursor];
+	size_ptr = (void *)&event->sample.array[cursor];
 
-	if (sample_type & PERF_SAMPLE_RAW && te->size > 0) {
+	size = *size_ptr;
+	size_ptr++;
+
+	te = (void *)size_ptr;
+	if (sample_type & PERF_SAMPLE_RAW && size > 0) {
 		char *event_str;
 		struct power_entry *pe;
 

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#1 lore raw

PATCH 2/3 perf: make common SAMPLE_EVENT parser

Currently, sample event data is parsed for each commands, and it is assuming that the data is not including other data. (E.g. timechart, trace, etc. can't parse the event if it has PERF_SAMPLE_CALLCHAIN)

So, even if we record the superset data for multiple commands at a time, commands can't parse. etc.

To fix it, this makes common sample event parser, and use it to parse sample event correctly. (PERF_SAMPLE_READ is unsupported for now though, it seems to be not using.)

---

 tools/perf/builtin-kmem.c      |   36 +++++++--------------
 tools/perf/builtin-report.c    |   39 ++++++++++-------------
 tools/perf/builtin-sched.c     |   38 +++++++---------------
 tools/perf/builtin-timechart.c |   56 ++++++++-------------------------
 tools/perf/builtin-trace.c     |   48 ++++++++--------------------
 tools/perf/util/event.c        |   67 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/event.h        |   17 +++++++++-
 7 files changed, 155 insertions(+), 146 deletions(-)
tools/perf/util/event.h renamed from tools/perf/util/event.h~perf-make-common-sample +16 -1
diff -puN tools/perf/util/event.h~perf-make-common-sample tools/perf/util/event.h
@@ -56,11 +56,25 @@ struct read_event {
 	u64 id;
 };
 
-struct sample_event{
+struct sample_event {
 	struct perf_event_header        header;
 	u64 array[];
 };
 
+struct sample_data {
+	u64 ip;
+	u32 pid, tid;
+	u64 time;
+	u64 addr;
+	u64 id;
+	u64 stream_id;
+	u32 cpu;
+	u64 period;
+	struct ip_callchain *callchain;
+	u32 raw_size;
+	void *raw_data;
+};
+
 #define BUILD_ID_SIZE 20
 
 struct build_id_event {
@@ -155,5 +169,6 @@ int event__process_task(event_t *self);
 struct addr_location;
 int event__preprocess_sample(const event_t *self, struct addr_location *al,
 			     symbol_filter_t filter);
+int event__parse_sample(event_t *event, u64 type, struct sample_data *data);
 
 #endif /* __PERF_RECORD_H */
tools/perf/builtin-report.c renamed from tools/perf/builtin-report.c~perf-make-common-sample +18 -21
diff -puN tools/perf/builtin-report.c~perf-make-common-sample tools/perf/builtin-report.c
@@ -605,44 +605,41 @@ static int validate_chain(struct ip_call
 
 static int process_sample_event(event_t *event)
 {
-	u64 ip = event->ip.ip;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
-	struct ip_callchain *chain = NULL;
+	struct sample_data data;
 	int cpumode;
 	struct addr_location al;
-	struct thread *thread = threads__findnew(event->ip.pid);
+	struct thread *thread;
 
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	memset(&data, 0, sizeof(data));
+	data.period = 1;
+
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
 		unsigned int i;
 
-		chain = (void *)more_data;
-
-		dump_printf("... chain: nr:%Lu\n", chain->nr);
+		dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
 
-		if (validate_chain(chain, event) < 0) {
+		if (validate_chain(data.callchain, event) < 0) {
 			pr_debug("call-chain problem with event, "
 				 "skipping it.\n");
 			return 0;
 		}
 
 		if (dump_trace) {
-			for (i = 0; i < chain->nr; i++)
-				dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]);
+			for (i = 0; i < data.callchain->nr; i++)
+				dump_printf("..... %2d: %016Lx\n",
+					    i, data.callchain->ips[i]);
 		}
 	}
 
+	thread = threads__findnew(data.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			event->header.type);
@@ -657,7 +654,7 @@ static int process_sample_event(event_t 
 	cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
 	thread__find_addr_location(thread, cpumode,
-				   MAP__FUNCTION, ip, &al, NULL);
+				   MAP__FUNCTION, data.ip, &al, NULL);
 	/*
 	 * We have to do this here as we may have a dso with no symbol hit that
 	 * has a name longer than the ones with symbols sampled.
@@ -675,12 +672,12 @@ static int process_sample_event(event_t 
 	if (sym_list && al.sym && !strlist__has_entry(sym_list, al.sym->name))
 		return 0;
 
-	if (hist_entry__add(&al, chain, period)) {
+	if (hist_entry__add(&al, data.callchain, data.period)) {
 		pr_debug("problem incrementing symbol count, skipping event\n");
 		return -1;
 	}
 
-	event__stats.total += period;
+	event__stats.total += data.period;
 
 	return 0;
 }
tools/perf/util/event.c renamed from tools/perf/util/event.c~perf-make-common-sample +67 -0

70 lines not on this page · raw message

diff -puN tools/perf/builtin-annotate.c~perf-make-common-sample tools/perf/builtin-annotate.c

tools/perf/builtin-kmem.c renamed from tools/perf/builtin-kmem.c~perf-make-common-sample +12 -24
diff -puN tools/perf/builtin-kmem.c~perf-make-common-sample tools/perf/builtin-kmem.c
@@ -320,35 +320,23 @@ process_raw_event(event_t *raw_event __u
 
 static int process_sample_event(event_t *event)
 {
-	u64 ip = event->ip.ip;
-	u64 timestamp = -1;
-	u32 cpu = -1;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
-	struct thread *thread = threads__findnew(event->ip.pid);
-
-	if (sample_type & PERF_SAMPLE_TIME) {
-		timestamp = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	struct sample_data data;
+	struct thread *thread;
 
-	if (sample_type & PERF_SAMPLE_CPU) {
-		cpu = *(u32 *)more_data;
-		more_data += sizeof(u32);
-		more_data += sizeof(u32); /* reserved */
-	}
+	memset(&data, 0, sizeof(data));
+	data.time = -1;
+	data.cpu = -1;
+	data.period = 1;
 
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
+	thread = threads__findnew(event->ip.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -357,7 +345,7 @@ static int process_sample_event(event_t 
 
 	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
 
-	process_raw_event(event, more_data, cpu, timestamp, thread);
+	process_raw_event(event, data.raw_data, data.cpu, data.time, thread);
 
 	return 0;
 }
tools/perf/builtin-sched.c renamed from tools/perf/builtin-sched.c~perf-make-common-sample +12 -26
diff -puN tools/perf/builtin-sched.c~perf-make-common-sample tools/perf/builtin-sched.c
@@ -1598,40 +1598,26 @@ process_raw_event(event_t *raw_event __u
 
 static int process_sample_event(event_t *event)
 {
+	struct sample_data data;
 	struct thread *thread;
-	u64 ip = event->ip.ip;
-	u64 timestamp = -1;
-	u32 cpu = -1;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
 
 	if (!(sample_type & PERF_SAMPLE_RAW))
 		return 0;
 
-	thread = threads__findnew(event->ip.pid);
+	memset(&data, 0, sizeof(data));
+	data.time = -1;
+	data.cpu = -1;
+	data.period = -1;
 
-	if (sample_type & PERF_SAMPLE_TIME) {
-		timestamp = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
-
-	if (sample_type & PERF_SAMPLE_CPU) {
-		cpu = *(u32 *)more_data;
-		more_data += sizeof(u32);
-		more_data += sizeof(u32); /* reserved */
-	}
-
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
+	thread = threads__findnew(data.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -1640,10 +1626,10 @@ static int process_sample_event(event_t 
 
 	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
 
-	if (profile_cpu != -1 && profile_cpu != (int) cpu)
+	if (profile_cpu != -1 && profile_cpu != (int)data.cpu)
 		return 0;
 
-	process_raw_event(event, more_data, cpu, timestamp, thread);
+	process_raw_event(event, data.raw_data, data.cpu, data.time, thread);
 
 	return 0;
 }
tools/perf/builtin-timechart.c renamed from tools/perf/builtin-timechart.c~perf-make-common-sample +15 -41

82 lines not on this page · raw message

tools/perf/builtin-trace.c renamed from tools/perf/builtin-trace.c~perf-make-common-sample +15 -33

73 lines not on this page · raw message

_

#2 lore raw

PATCH 3/3 perf: misc small fixes

[Those was checked by valgrind, but not fixed all errors by lazyness. Sorry]

- util/parse-event.c
"path" is pointer. It should be sizeof(*path)

- util/header.c
"len" is aligned to 64. So, it tries to write the out of long_name buffer.

So, this use "zero_buf" to write aligned area.

- util/trace-event-read.c
"size" is not including nul byte. So, this allocates it, and set '\0'.

- util/trace-event-parse.c
It needs parens to calc correct size.

---

 tools/perf/util/header.c            |    9 +++++++--
 tools/perf/util/parse-events.c      |    2 +-
 tools/perf/util/trace-event-parse.c |    2 +-
 tools/perf/util/trace-event-read.c  |    3 ++-
 4 files changed, 11 insertions(+), 5 deletions(-)
tools/perf/util/parse-events.c renamed from tools/perf/util/parse-events.c~perf-fix-misc +1 -1
diff -puN tools/perf/util/parse-events.c~perf-fix-misc tools/perf/util/parse-events.c
@@ -197,7 +197,7 @@ struct tracepoint_path *tracepoint_id_to
 			if (id == config) {
 				closedir(evt_dir);
 				closedir(sys_dir);
-				path = zalloc(sizeof(path));
+				path = zalloc(sizeof(*path));
 				path->system = malloc(MAX_EVENT_LENGTH);
 				if (!path->system) {
 					free(path);

diff -puN tools/perf/util/symbol.c~perf-fix-misc tools/perf/util/symbol.c

tools/perf/util/header.c renamed from tools/perf/util/header.c~perf-fix-misc +7 -2
diff -puN tools/perf/util/header.c~perf-fix-misc tools/perf/util/header.c
@@ -187,7 +187,9 @@ static int do_write(int fd, const void *
 
 static int __dsos__write_buildid_table(struct list_head *head, int fd)
 {
+#define NAME_ALIGN	64
 	struct dso *pos;
+	static const char zero_buf[NAME_ALIGN];
 
 	list_for_each_entry(pos, head, node) {
 		int err;
@@ -197,14 +199,17 @@ static int __dsos__write_buildid_table(s
 		if (!pos->has_build_id)
 			continue;
 		len = pos->long_name_len + 1;
-		len = ALIGN(len, 64);
+		len = ALIGN(len, NAME_ALIGN);
 		memset(&b, 0, sizeof(b));
 		memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
 		b.header.size = sizeof(b) + len;
 		err = do_write(fd, &b, sizeof(b));
 		if (err < 0)
 			return err;
-		err = do_write(fd, pos->long_name, len);
+		err = do_write(fd, pos->long_name, pos->long_name_len + 1);
+		if (err < 0)
+			return err;
+		err = do_write(fd, zero_buf, len - pos->long_name_len + 1);
 		if (err < 0)
 			return err;
 	}
tools/perf/util/trace-event-read.c renamed from tools/perf/util/trace-event-read.c~perf-fix-misc +2 -1
diff -puN tools/perf/util/trace-event-read.c~perf-fix-misc tools/perf/util/trace-event-read.c
@@ -145,8 +145,9 @@ static void read_proc_kallsyms(void)
 	if (!size)
 		return;
 
-	buf = malloc_or_die(size);
+	buf = malloc_or_die(size + 1);
 	read_or_die(buf, size);
+	buf[size] = '\0';
 
 	parse_proc_kallsyms(buf, size);
 
tools/perf/util/trace-event-parse.c renamed from tools/perf/util/trace-event-parse.c~perf-fix-misc +1 -1
diff -puN tools/perf/util/trace-event-parse.c~perf-fix-misc tools/perf/util/trace-event-parse.c
@@ -177,7 +177,7 @@ void parse_proc_kallsyms(char *file, uns
 		func_count++;
 	}
 
-	func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
+	func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
 
 	i = 0;
 	while (list) {

_

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#3 lore raw

[tip:perf/urgent] perf tools: Misc small fixes

Commit-ID:  7691b1ec2e4a8d4bd88dcf88b29792399ebe1c91
Gitweb:     http://git.kernel.org/tip/7691b1ec2e4a8d4bd88dcf88b29792399ebe1c91
Author:     OGAWA Hirofumi <[email protected]>
AuthorDate: Sun, 6 Dec 2009 20:10:49 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 6 Dec 2009 18:15:02 +0100

perf tools: Misc small fixes

- util/header.c
"len" is aligned to 64. So, it tries to write the out of long_name buffer.

So, this use "zero_buf" to write aligned area.

- util/trace-event-read.c
"size" is not including nul byte. So, this allocates it, and set '\0'.

- util/trace-event-parse.c
It needs parens to calc correct size.

Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Frederic Weisbecker <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/header.c            |    9 +++++++--
 tools/perf/util/trace-event-parse.c |    2 +-
 tools/perf/util/trace-event-read.c  |    3 ++-
 3 files changed, 10 insertions(+), 4 deletions(-)
tools/perf/util/header.c +7 -2
index 4805e6d..08b6759 100644
@@ -187,7 +187,9 @@ static int do_write(int fd, const void *buf, size_t size)
 
 static int __dsos__write_buildid_table(struct list_head *head, int fd)
 {
+#define NAME_ALIGN	64
 	struct dso *pos;
+	static const char zero_buf[NAME_ALIGN];
 
 	list_for_each_entry(pos, head, node) {
 		int err;
@@ -197,14 +199,17 @@ static int __dsos__write_buildid_table(struct list_head *head, int fd)
 		if (!pos->has_build_id)
 			continue;
 		len = pos->long_name_len + 1;
-		len = ALIGN(len, 64);
+		len = ALIGN(len, NAME_ALIGN);
 		memset(&b, 0, sizeof(b));
 		memcpy(&b.build_id, pos->build_id, sizeof(pos->build_id));
 		b.header.size = sizeof(b) + len;
 		err = do_write(fd, &b, sizeof(b));
 		if (err < 0)
 			return err;
-		err = do_write(fd, pos->long_name, len);
+		err = do_write(fd, pos->long_name, pos->long_name_len + 1);
+		if (err < 0)
+			return err;
+		err = do_write(fd, zero_buf, len - pos->long_name_len + 1);
 		if (err < 0)
 			return err;
 	}
tools/perf/util/trace-event-parse.c +1 -1
index 0302405..6ffe9d6 100644
@@ -177,7 +177,7 @@ void parse_proc_kallsyms(char *file, unsigned int size __unused)
 		func_count++;
 	}
 
-	func_list = malloc_or_die(sizeof(*func_list) * func_count + 1);
+	func_list = malloc_or_die(sizeof(*func_list) * (func_count + 1));
 
 	i = 0;
 	while (list) {
tools/perf/util/trace-event-read.c +2 -1
index 342dfdd..1744422 100644
@@ -145,8 +145,9 @@ static void read_proc_kallsyms(void)
 	if (!size)
 		return;
 
-	buf = malloc_or_die(size);
+	buf = malloc_or_die(size + 1);
 	read_or_die(buf, size);
+	buf[size] = '\0';
 
 	parse_proc_kallsyms(buf, size);
 
#4 lore raw

[tip:perf/urgent] perf: Make common SAMPLE_EVENT parser

In reply to OGAWA Hirofumi
Commit-ID:  180f95e29aa8782c019caa64ede2a28d8ab62564
Gitweb:     http://git.kernel.org/tip/180f95e29aa8782c019caa64ede2a28d8ab62564
Author:     OGAWA Hirofumi <[email protected]>
AuthorDate: Sun, 6 Dec 2009 20:08:24 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 6 Dec 2009 18:15:01 +0100

perf: Make common SAMPLE_EVENT parser

Currently, sample event data is parsed for each commands, and it is assuming that the data is not including other data. (E.g. timechart, trace, etc. can't parse the event if it has PERF_SAMPLE_CALLCHAIN)

So, even if we record the superset data for multiple commands at a time, commands can't parse. etc.

To fix it, this makes common sample event parser, and use it to parse sample event correctly. (PERF_SAMPLE_READ is unsupported for now though, it seems to be not using.)

Cc Peter Zijlstra <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Frederic Weisbecker <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-kmem.c      |   36 +++++++--------------
 tools/perf/builtin-report.c    |   39 +++++++++++------------
 tools/perf/builtin-sched.c     |   38 +++++++---------------
 tools/perf/builtin-timechart.c |   58 +++++++++-------------------------
 tools/perf/builtin-trace.c     |   48 +++++++++-------------------
 tools/perf/util/event.c        |   67 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/event.h        |   17 +++++++++-
 7 files changed, 156 insertions(+), 147 deletions(-)
tools/perf/builtin-kmem.c +12 -24
index 047fef7..f218990 100644
@@ -320,35 +320,23 @@ process_raw_event(event_t *raw_event __used, void *more_data,
 
 static int process_sample_event(event_t *event)
 {
-	u64 ip = event->ip.ip;
-	u64 timestamp = -1;
-	u32 cpu = -1;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
-	struct thread *thread = threads__findnew(event->ip.pid);
-
-	if (sample_type & PERF_SAMPLE_TIME) {
-		timestamp = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	struct sample_data data;
+	struct thread *thread;
 
-	if (sample_type & PERF_SAMPLE_CPU) {
-		cpu = *(u32 *)more_data;
-		more_data += sizeof(u32);
-		more_data += sizeof(u32); /* reserved */
-	}
+	memset(&data, 0, sizeof(data));
+	data.time = -1;
+	data.cpu = -1;
+	data.period = 1;
 
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
+	thread = threads__findnew(event->ip.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -357,7 +345,7 @@ static int process_sample_event(event_t *event)
 
 	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
 
-	process_raw_event(event, more_data, cpu, timestamp, thread);
+	process_raw_event(event, data.raw_data, data.cpu, data.time, thread);
 
 	return 0;
 }
tools/perf/builtin-report.c +18 -21
index 383c4ab..2b9eb3a 100644
@@ -605,44 +605,41 @@ static int validate_chain(struct ip_callchain *chain, event_t *event)
 
 static int process_sample_event(event_t *event)
 {
-	u64 ip = event->ip.ip;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
-	struct ip_callchain *chain = NULL;
+	struct sample_data data;
 	int cpumode;
 	struct addr_location al;
-	struct thread *thread = threads__findnew(event->ip.pid);
+	struct thread *thread;
 
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	memset(&data, 0, sizeof(data));
+	data.period = 1;
+
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
 	if (sample_type & PERF_SAMPLE_CALLCHAIN) {
 		unsigned int i;
 
-		chain = (void *)more_data;
-
-		dump_printf("... chain: nr:%Lu\n", chain->nr);
+		dump_printf("... chain: nr:%Lu\n", data.callchain->nr);
 
-		if (validate_chain(chain, event) < 0) {
+		if (validate_chain(data.callchain, event) < 0) {
 			pr_debug("call-chain problem with event, "
 				 "skipping it.\n");
 			return 0;
 		}
 
 		if (dump_trace) {
-			for (i = 0; i < chain->nr; i++)
-				dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]);
+			for (i = 0; i < data.callchain->nr; i++)
+				dump_printf("..... %2d: %016Lx\n",
+					    i, data.callchain->ips[i]);
 		}
 	}
 
+	thread = threads__findnew(data.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			event->header.type);
@@ -657,7 +654,7 @@ static int process_sample_event(event_t *event)
 	cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
 
 	thread__find_addr_location(thread, cpumode,
-				   MAP__FUNCTION, ip, &al, NULL);
+				   MAP__FUNCTION, data.ip, &al, NULL);
 	/*
 	 * We have to do this here as we may have a dso with no symbol hit that
 	 * has a name longer than the ones with symbols sampled.
@@ -675,12 +672,12 @@ static int process_sample_event(event_t *event)
 	if (sym_list && al.sym && !strlist__has_entry(sym_list, al.sym->name))
 		return 0;
 
-	if (hist_entry__add(&al, chain, period)) {
+	if (hist_entry__add(&al, data.callchain, data.period)) {
 		pr_debug("problem incrementing symbol count, skipping event\n");
 		return -1;
 	}
 
-	event__stats.total += period;
+	event__stats.total += data.period;
 
 	return 0;
 }
tools/perf/builtin-sched.c +12 -26
index 26b782f..45c46c7 100644
@@ -1598,40 +1598,26 @@ process_raw_event(event_t *raw_event __used, void *more_data,
 
 static int process_sample_event(event_t *event)
 {
+	struct sample_data data;
 	struct thread *thread;
-	u64 ip = event->ip.ip;
-	u64 timestamp = -1;
-	u32 cpu = -1;
-	u64 period = 1;
-	void *more_data = event->ip.__more_data;
 
 	if (!(sample_type & PERF_SAMPLE_RAW))
 		return 0;
 
-	thread = threads__findnew(event->ip.pid);
+	memset(&data, 0, sizeof(data));
+	data.time = -1;
+	data.cpu = -1;
+	data.period = -1;
 
-	if (sample_type & PERF_SAMPLE_TIME) {
-		timestamp = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
-
-	if (sample_type & PERF_SAMPLE_CPU) {
-		cpu = *(u32 *)more_data;
-		more_data += sizeof(u32);
-		more_data += sizeof(u32); /* reserved */
-	}
-
-	if (sample_type & PERF_SAMPLE_PERIOD) {
-		period = *(u64 *)more_data;
-		more_data += sizeof(u64);
-	}
+	event__parse_sample(event, sample_type, &data);
 
 	dump_printf("(IP, %d): %d/%d: %p period: %Ld\n",
 		event->header.misc,
-		event->ip.pid, event->ip.tid,
-		(void *)(long)ip,
-		(long long)period);
+		data.pid, data.tid,
+		(void *)(long)data.ip,
+		(long long)data.period);
 
+	thread = threads__findnew(data.pid);
 	if (thread == NULL) {
 		pr_debug("problem processing %d event, skipping it.\n",
 			 event->header.type);
@@ -1640,10 +1626,10 @@ static int process_sample_event(event_t *event)
 
 	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
 
-	if (profile_cpu != -1 && profile_cpu != (int) cpu)
+	if (profile_cpu != -1 && profile_cpu != (int)data.cpu)
 		return 0;
 
-	process_raw_event(event, more_data, cpu, timestamp, thread);
+	process_raw_event(event, data.raw_data, data.cpu, data.time, thread);
 
 	return 0;
 }
tools/perf/builtin-timechart.c +15 -41

82 lines not on this page · raw message

tools/perf/builtin-trace.c +15 -33

73 lines not on this page · raw message

tools/perf/util/event.c +67 -0

70 lines not on this page · raw message

tools/perf/util/event.h +16 -1
index a4cc810..c7a78ee 100644
@@ -56,11 +56,25 @@ struct read_event {
 	u64 id;
 };
 
-struct sample_event{
+struct sample_event {
 	struct perf_event_header        header;
 	u64 array[];
 };
 
+struct sample_data {
+	u64 ip;
+	u32 pid, tid;
+	u64 time;
+	u64 addr;
+	u64 id;
+	u64 stream_id;
+	u32 cpu;
+	u64 period;
+	struct ip_callchain *callchain;
+	u32 raw_size;
+	void *raw_data;
+};
+
 #define BUILD_ID_SIZE 20
 
 struct build_id_event {
@@ -155,5 +169,6 @@ int event__process_task(event_t *self);
 struct addr_location;
 int event__preprocess_sample(const event_t *self, struct addr_location *al,
 			     symbol_filter_t filter);
+int event__parse_sample(event_t *event, u64 type, struct sample_data *data);
 
 #endif /* __PERF_RECORD_H */
#5 lore raw
In reply to OGAWA Hirofumi
Quoted 5 lines · OGAWA Hirofumi

Hi,

Update "struct trace_entry" to match with current one. And remove "size" field from it.

Quoted 8 lines

If it has "size", it become cause of alignment mismatch of structure with kernel.

---

 tools/perf/builtin-timechart.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Just curious, have you tested timechart functionality after having done this change - does it still work fine for you?

Thanks,

Ingo

#6 lore raw
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · OGAWA Hirofumi

Hi,

Update "struct trace_entry" to match with current one. And remove "size" field from it.

If it has "size", it become cause of alignment mismatch of structure with kernel.

Quoted 8 lines
Quoted 5 lines

---

 tools/perf/builtin-timechart.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Just curious, have you tested timechart functionality after having done this change - does it still work fine for you?

Yes. Rather, it doesn't work without this. (Without patch, it provide svg output, but it doesn't provide correct sched state. And this issue is only 64bit arch.)

E.g. The following has difference (perf timechart doesn't has hole).

In kernel,

struct ftrace_raw_sched_switch {

	struct trace_entry         ent;                  /*     0    12 */
	char                       prev_comm[16];        /*    12    16 */
	pid_t                      prev_pid;             /*    28     4 */
	int                        prev_prio;            /*    32     4 */
	/* XXX 4 bytes hole, try to pack */

	long int                   prev_state;           /*    40     8 */
	char                       next_comm[16];        /*    48    16 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	pid_t                      next_pid;             /*    64     4 */
	int                        next_prio;            /*    68     4 */
	char                       __data[0];            /*    72     0 */

	/* size: 72, cachelines: 2, members: 9 */
	/* sum members: 68, holes: 1, sum holes: 4 */
	/* last cacheline: 8 bytes */
};

In perl timechart, [Note, struct trace_entry is including "u32 size"]

struct sched_switch {

	struct trace_entry         te;                   /*     0    16 */
	char                       prev_comm[16];        /*    16    16 */
	int                        prev_pid;             /*    32     4 */
	int                        prev_prio;            /*    36     4 */
	long int                   prev_state;           /*    40     8 */
	char                       next_comm[16];        /*    48    16 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	int                        next_pid;             /*    64     4 */
	int                        next_prio;            /*    68     4 */

	/* size: 72, cachelines: 2, members: 8 */
	/* last cacheline: 8 bytes */
};

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#7 lore raw
Quoted 52 lines · OGAWA Hirofumi
Quoted 10 lines · Ingo Molnar
Quoted 8 lines · OGAWA Hirofumi

Hi,

Update "struct trace_entry" to match with current one. And remove "size" field from it.

If it has "size", it become cause of alignment mismatch of structure with kernel.

Quoted 8 lines
Quoted 5 lines

---

 tools/perf/builtin-timechart.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Just curious, have you tested timechart functionality after having done this change - does it still work fine for you?

Yes. Rather, it doesn't work without this. (Without patch, it provide svg output, but it doesn't provide correct sched state. And this issue is only 64bit arch.)

E.g. The following has difference (perf timechart doesn't has hole).

In kernel,

struct ftrace_raw_sched_switch {

	struct trace_entry         ent;                  /*     0    12 */
	char                       prev_comm[16];        /*    12    16 */
	pid_t                      prev_pid;             /*    28     4 */
	int                        prev_prio;            /*    32     4 */
	/* XXX 4 bytes hole, try to pack */

	long int                   prev_state;           /*    40     8 */
	char                       next_comm[16];        /*    48    16 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	pid_t                      next_pid;             /*    64     4 */
	int                        next_prio;            /*    68     4 */
	char                       __data[0];            /*    72     0 */

	/* size: 72, cachelines: 2, members: 9 */
	/* sum members: 68, holes: 1, sum holes: 4 */
	/* last cacheline: 8 bytes */
};

In perl timechart, [Note, struct trace_entry is including "u32 size"]

struct sched_switch {

Quoted 14 lines
	struct trace_entry         te;                   /*     0    16 */
	char                       prev_comm[16];        /*    16    16 */
	int                        prev_pid;             /*    32     4 */
	int                        prev_prio;            /*    36     4 */
	long int                   prev_state;           /*    40     8 */
	char                       next_comm[16];        /*    48    16 */
	/* --- cacheline 1 boundary (64 bytes) --- */
	int                        next_pid;             /*    64     4 */
	int                        next_prio;            /*    68     4 */

	/* size: 72, cachelines: 2, members: 8 */
	/* last cacheline: 8 bytes */
};

ok - thanks for the confirmation!

Ingo

#8 lore raw
Quoted 3 lines · Ingo Molnar
Quoted 3 lines

Yes. Rather, it doesn't work without this. (Without patch, it provide svg output, but it doesn't provide correct sched state. And this issue is only 64bit arch.)

[...]

Quoted 1 line

ok - thanks for the confirmation!

BTW, more correct fix would be using raw_filed_value() or something, so it would become more robust. But, sorry, I didn't.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#9 lore raw

[tip:perf/urgent] perf timechart: Fix header handling

In reply to OGAWA Hirofumi
Commit-ID:  028c515253761084c6594bf9ac9b194b51d87065
Gitweb:     http://git.kernel.org/tip/028c515253761084c6594bf9ac9b194b51d87065
Author:     OGAWA Hirofumi <[email protected]>
AuthorDate: Sun, 6 Dec 2009 20:07:29 +0900
Committer:  Ingo Molnar <[email protected]>
CommitDate: Sun, 6 Dec 2009 18:15:01 +0100

perf timechart: Fix header handling

Update "struct trace_entry" to match with current one. And remove "size" field from it.

If it has "size", it become cause of alignment mismatch of structure with kernel.

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-timechart.c |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
tools/perf/builtin-timechart.c +8 -4
index cb58b66..c0f29ed 100644
@@ -302,12 +302,11 @@ process_exit_event(event_t *event)
 }
 
 struct trace_entry {
-	u32			size;
 	unsigned short		type;
 	unsigned char		flags;
 	unsigned char		preempt_count;
 	int			pid;
-	int			tgid;
+	int			lock_depth;
 };
 
 struct power_entry {
@@ -489,6 +488,7 @@ process_sample_event(event_t *event)
 	u64 stamp = 0;
 	u32 cpu = 0;
 	u32 pid = 0;
+	u32 size, *size_ptr;
 	struct trace_entry *te;
 
 	if (sample_type & PERF_SAMPLE_IP)
@@ -518,9 +518,13 @@ process_sample_event(event_t *event)
 	if (sample_type & PERF_SAMPLE_PERIOD)
 		cursor++;
 
-	te = (void *)&event->sample.array[cursor];
+	size_ptr = (void *)&event->sample.array[cursor];
 
-	if (sample_type & PERF_SAMPLE_RAW && te->size > 0) {
+	size = *size_ptr;
+	size_ptr++;
+
+	te = (void *)size_ptr;
+	if (sample_type & PERF_SAMPLE_RAW && size > 0) {
 		char *event_str;
 		struct power_entry *pe;