#! /usr/bin/env stap # Copyright (C) 2010 Red Hat, Inc. # Write by William Cohen # # cycle_theif provide the following information for a specified pid: # Number of times the task is migrated to another cpu # How long the task is scheduled on and off a processor. # task pid that run with the task is scheduled off the processor # # # Run the script with: # stap cycle_thief.stp -x pid # # control-c to exit data collection global last_cpu = -1 global pid_on, pid_off, migrated global time_on, time_off global cycle_thief probe kernel.trace("sched_switch") { t = gettimeofday_us(); c = cpu(); if ($prev->pid == target() && $next->pid != target()) { /* being switched out */ pid_off = t; last_cpu = c; if (pid_on) time_on <<< pid_off - pid_on; } else if ($prev->pid != target() && $next->pid == target()) { /* being switched in */ pid_on = t; if (pid_off) time_off <<< pid_on - pid_off; if (c != last_cpu) ++migrated; } /* watch what other processes scheduled while pid off */ if (pid_off > pid_on && c == last_cpu) { cycle_thief[$next->pid] <<< 1; } } probe end { printf("\n") printf("task %d migrated: %d\n", target(), migrated) if (@count(time_on)) { printf("\n") printf("task %d on processor (us):\n", target()) print(@hist_log(time_on)); } if (@count(time_off)) { printf("\n") printf("task %d off processor (us)\n", target()) print(@hist_log(time_off)); } printf("other pids taking processor from task %d\n", target()) foreach (p in cycle_thief-) printf("%6d %10d\n", p, @count(cycle_thief[p])) }