#!/usr/bin/env stap # # Continuously list the top context switchers # global processes probe begin { printf("Collecting data...\n") } function print_top () { printf("Process\t\t\t\tCount\n") printf("--------------------------------------\n") foreach (name in processes- limit 20) printf("%-20s\t\t%5d\n",name, processes[name]) printf("--------------------------------------\n\n") delete processes } probe scheduler.cpu_on { processes[execname()]++ } # print top context switchers every 10 seconds probe timer.s(10) { print_top () }