Skip to contentSkip to conversation

perf: add a timestamp to exit and fork events

PATCH Arjan van de Ven 1 participant 1 message Aug 9, 2009 perf events

lore
Share & tools
lore
#0 lore raw

In order to make use of the fork and exit perf events, it's essential that they tell the user about when these event happened. This patch adds a time field to the end of the structure (and thus is abi compatible).

I did not make this field conditional on any flag since that both is unpleasant to use, and I cannot imagine a scenario where you want the event but not the time.

include/linux/perf_counter.h +2 -0
index 0a6f320..5e0769a 100644
@@ -315,6 +315,7 @@ enum perf_event_type {
 	 *	struct perf_event_header	header;
 	 *	u32				pid, ppid;
 	 *	u32				tid, ptid;
+	 *	u64				time;
 	 * };
 	 */
 	PERF_EVENT_EXIT			= 4,
@@ -335,6 +336,7 @@ enum perf_event_type {
 	 *	struct perf_event_header	header;
 	 *	u32				pid, ppid;
 	 *	u32				tid, ptid;
+	 *	u64				time;
 	 * };
 	 */
 	PERF_EVENT_FORK			= 7,
kernel/perf_counter.c +2 -0
index bf8110b..9382cd0 100644
@@ -2861,6 +2861,7 @@ struct perf_task_event {
 		u32				ppid;
 		u32				tid;
 		u32				ptid;
+		u64				time;
 	} event;
 };
 
@@ -2881,6 +2885,7 @@ static void perf_counter_task_output(struct perf_counter *counter,
 	task_event->event.tid = perf_counter_tid(counter, task);
 	task_event->event.ptid = perf_counter_tid(counter, task->real_parent);
 
+	task_event->event.time = sched_clock();
 	perf_output_put(&handle, task_event->event);
 	perf_output_end(&handle);
 }
tools/perf/builtin-annotate.c +2 -0
index 1dba568..c28e2b3 100644
@@ -72,6 +72,8 @@ struct comm_event {
 struct fork_event {
 	struct perf_event_header header;
 	u32 pid, ppid;
+	u32 tid, ptid;
+	u64 time;
 };
 
 typedef union event_union {
tools/perf/builtin-report.c +1 -0
index 4163918..1cb2183 100644
@@ -104,6 +104,7 @@ struct fork_event {
 	struct perf_event_header header;
 	u32 pid, ppid;
 	u32 tid, ptid;
+	u64 time;
 };
 
 struct lost_event {