Эх сурвалжийг харах

perf record: Allocate area for sample_id_hdr in a synthesized comm event

A previous patch added a synthesized comm event for forked child process
but it missed that the event should contain area for sample_id_hdr at
the end.  It worked by accident since the perf_event union contains
bigger event structs like mmap_events.

This patch fixes it by dynamically allocating event struct including
those area like in perf_event__synthesize_thread_map().

Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1443577526-3240-1-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Namhyung Kim 10 жил өмнө
parent
commit
e5bed56448

+ 10 - 2
tools/perf/builtin-record.c

@@ -637,17 +637,25 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 	 * Let the child rip
 	 * Let the child rip
 	 */
 	 */
 	if (forks) {
 	if (forks) {
-		union perf_event event;
+		union perf_event *event;
+
+		event = malloc(sizeof(event->comm) + machine->id_hdr_size);
+		if (event == NULL) {
+			err = -ENOMEM;
+			goto out_child;
+		}
+
 		/*
 		/*
 		 * Some H/W events are generated before COMM event
 		 * Some H/W events are generated before COMM event
 		 * which is emitted during exec(), so perf script
 		 * which is emitted during exec(), so perf script
 		 * cannot see a correct process name for those events.
 		 * cannot see a correct process name for those events.
 		 * Synthesize COMM event to prevent it.
 		 * Synthesize COMM event to prevent it.
 		 */
 		 */
-		perf_event__synthesize_comm(tool, &event,
+		perf_event__synthesize_comm(tool, event,
 					    rec->evlist->workload.pid,
 					    rec->evlist->workload.pid,
 					    process_synthesized_event,
 					    process_synthesized_event,
 					    machine);
 					    machine);
+		free(event);
 
 
 		perf_evlist__start_workload(rec->evlist);
 		perf_evlist__start_workload(rec->evlist);
 	}
 	}