diff mbox series

[08/12] trace-cmd analyze: Track migration

Message ID 20220324025726.1727204-9-rostedt@goodmis.org (mailing list archive)
State New, archived
Headers show
Series trace-cmd: Add trace-cmd analyze command | expand

Commit Message

Steven Rostedt March 24, 2022, 2:57 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Keep track of which CPU event task is at for every event, and if the CPU
changes, then mark it as a migration. Print out the number of times the
task migrated if it had migrated.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 tracecmd/trace-analyze.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-analyze.c b/tracecmd/trace-analyze.c
index de776b76c343..4db93367727b 100644
--- a/tracecmd/trace-analyze.c
+++ b/tracecmd/trace-analyze.c
@@ -55,6 +55,7 @@  struct sched_timings {
 struct task_item {
 	unsigned long long	runtime;
 	unsigned long long	start_ts;
+	unsigned long long	migrated;
 	struct sched_timings	preempt;
 	struct sched_timings	sleep;
 	struct sched_timings	blocked;
@@ -62,6 +63,7 @@  struct task_item {
 	char			*comm;
 	struct trace_hash_item	hash;
 	int			pid;
+	int			last_cpu;
 	int			last_state;
 };
 
@@ -149,6 +151,7 @@  static struct task_item *get_task(struct cpu_data *cpu_data, int pid)
 		hash->key = find_pid;
 		cpu_data->data->nr_tasks++;
 		trace_hash_add(&cpu_data->data->tasks, hash);
+		task->last_cpu = cpu_data->cpu;
 		task->last_state = -1;
 	}
 
@@ -256,6 +259,10 @@  static void update_pid(struct cpu_data *cpu_data,
 
 	cpu_task = get_cpu_task(cpu_data, pid);
 	task = cpu_task->task;
+	if (task->last_cpu != cpu_data->cpu) {
+		task->last_cpu = cpu_data->cpu;
+		task->migrated++;
+	}
 
 	update_idle_task(cpu_data, task, record->ts);
 
@@ -383,6 +390,11 @@  static void process_switch(struct analysis_data *data,
 		task->start_ts = record->ts;
 		cpu_data->current_pid = pid;
 
+		if (task->last_cpu != cpu_data->cpu) {
+			task->last_cpu = cpu_data->cpu;
+			task->migrated++;
+		}
+
 		update_idle_task(cpu_data, task, record->ts);
 
 		switch (task->last_state) {
@@ -619,9 +631,11 @@  static void print_task(struct tep_handle *tep, struct task_item *task)
 {
 	printf("\nTask: %d : %s:\n",
 	       task->pid , task->comm ? : tep_data_comm_from_pid(tep, task->pid));
-	printf("Runtime: ");
+	printf("Runtime:    ");
 	print_time(task->runtime, '_');
 	printf("\n");
+	if (task->migrated)
+		printf("Migrated:\t%llu\n", task->migrated);
 	print_timings_title("Type");
 	print_sched_timings("Preempted", &task->preempt);
 	print_sched_timings("Blocked", &task->blocked);