From ae3072f460693e85962556bf0529a729c7d97bf6 Mon Sep 17 00:00:00 2001 From: Kiran Prakesh Date: Thu, 1 Oct 2009 22:39:32 +0530 Subject: Scheduler Tapset based on kernel tracepoints This patch adds kernel tracepoints based probes to the scheduler tapset along with the testcase, scheduler-test-tracepoints.stp and an example script, sched_switch.stp. Signed-off-by: Kiran Prakash Signed-off-by: Josh Stone --- .../systemtap.examples/profiling/sched_switch.meta | 14 +++++ .../systemtap.examples/profiling/sched_switch.stp | 62 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 testsuite/systemtap.examples/profiling/sched_switch.meta create mode 100644 testsuite/systemtap.examples/profiling/sched_switch.stp (limited to 'testsuite/systemtap.examples') diff --git a/testsuite/systemtap.examples/profiling/sched_switch.meta b/testsuite/systemtap.examples/profiling/sched_switch.meta new file mode 100644 index 00000000..8f1a2858 --- /dev/null +++ b/testsuite/systemtap.examples/profiling/sched_switch.meta @@ -0,0 +1,14 @@ +title: Display the task switches happeningt the scheduler +name: sched_switch.stp +version: 1.0 +author: kiran +keywords: profiling functions +subsystem: kernel +status: production +exit: user-controlled +output: sorted-list on-exit +scope: system-wide +description: The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks scheduler the current process being traced, out and when it gets scheduled in again. +test_check: stap -p4 sched_switch.stp +test_installcheck: stap sched_switch.stp -c "sleep 1" + diff --git a/testsuite/systemtap.examples/profiling/sched_switch.stp b/testsuite/systemtap.examples/profiling/sched_switch.stp new file mode 100644 index 00000000..24973526 --- /dev/null +++ b/testsuite/systemtap.examples/profiling/sched_switch.stp @@ -0,0 +1,62 @@ +/* This script works similar to ftrace's sched_switch. It displays a list of + * processes which get switched in and out of the scheduler. The format of display + * is PROCESS_NAME PROCESS_PID CPU TIMESTAMP PID: PRIORITY: PROCESS STATE ->/+ + * NEXT_PID : NEXT_PRIORITY: NEXT_STATE NEXT_PROCESS_NAME + * -> indicates that prev process is scheduled out and the next process is + * scheduled in. + * + indicates that prev process has woken up the next process. + * The usage is sched_switch.stp <"pid"/"name"> pid/name + */ + +function state_calc(state) { + if(state == 0) + status = "R" + if(state == 1) + status = "S" + if(state == 2) + status = "D" + if(state == 4) + status = "T" + if(state == 8) + status = "T" + if(state == 16) + status = "Z" + if(state == 32) + status = "EXIT_DEAD" + return status +} +probe scheduler.wakeup +{ + %( $# == 2 %? + + if(@1 == "pid") + if (task_pid != $2 && pid() != $2) + next + if(@1 == "name") + if (task_execname(task) != @2 && execname() != @2) + next + + %) + + printf("%-16s%5d%5d%d:%d:%s + %d:%d:%s %16s\n", + execname(), task_cpu(task), gettimeofday_ns(), + pid(), task_prio(task_current()), state_calc(task_state(task_current())), + task_pid(task), task_prio(task), state_calc(task_state(task)), + task_execname(task)) +} +probe scheduler.ctxswitch +{ + %( $# == 2 %? + + if(@1 == "pid") + if (next_pid != $2 && prev_pid != $2) + next + if(@1 == "name") + if (prev_task_name != @2 && next_task_name != @2) + next + %) + + printf("%-16s%5d%5d%d:%d:%s ==> %d:%d:%s %16s\n",prev_task_name, + task_cpu(prev_task),gettimeofday_ns(),prev_pid,prev_priority,state_calc(prevtsk_state),next_pid, + next_priority,state_calc(nexttsk_state),next_task_name) +} -- cgit From 0449af0365f19c246f6ce09dd93118a597f78949 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 2 Oct 2009 16:42:44 -0700 Subject: Updates samples index for sched_switch --- testsuite/systemtap.examples/index.html | 3 +++ testsuite/systemtap.examples/index.txt | 12 +++++++++++ testsuite/systemtap.examples/keyword-index.html | 6 ++++++ testsuite/systemtap.examples/keyword-index.txt | 24 ++++++++++++++++++++++ .../systemtap.examples/profiling/sched_switch.meta | 6 +++--- .../systemtap.examples/profiling/sched_switch.stp | 1 + 6 files changed, 49 insertions(+), 3 deletions(-) mode change 100644 => 100755 testsuite/systemtap.examples/profiling/sched_switch.stp (limited to 'testsuite/systemtap.examples') diff --git a/testsuite/systemtap.examples/index.html b/testsuite/systemtap.examples/index.html index ba0d0fd7..66118bfc 100644 --- a/testsuite/systemtap.examples/index.html +++ b/testsuite/systemtap.examples/index.html @@ -196,6 +196,9 @@ keywords: SYSCALL profiling/functioncallcount.stp - Count Times Functions Called
keywords: PROFILING FUNCTIONS

The functioncallcount.stp script takes one argument, a list of functions to probe. The script will run and count the number of times that each of the functions on the list is called. On exit the script will print a sorted list from most frequently to least frequently called function.

+
  • profiling/sched_switch.stp - Display the task switches happening in the scheduler
    +keywords: PROFILING FUNCTIONS
    +

    The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks schedule out the current process being traced, and when it gets scheduled in again.

  • profiling/thread-times.stp - Profile kernel functions
    keywords: PROFILING

    The thread-times.stp script sets up time-based sampling. Every five seconds it prints out a sorted list with the top twenty processes with samples broken down into percentage total time spent in user-space and kernel-space.

  • diff --git a/testsuite/systemtap.examples/index.txt b/testsuite/systemtap.examples/index.txt index 3d0495f5..cb2b10d3 100644 --- a/testsuite/systemtap.examples/index.txt +++ b/testsuite/systemtap.examples/index.txt @@ -488,6 +488,18 @@ keywords: profiling functions called function. +profiling/sched_switch.stp - Display the task switches happening in the scheduler +keywords: profiling functions + + The sched_switch.stp script takes two arguments, first argument can + be "pid" or "name" to indicate what is being passed as second + argument. The script will trace the process based on pid/name and + print the scheduler switches happening with the process. If no + arguments are passed, it displays all the scheduler switches. This + can be used to understand which tasks schedule out the current + process being traced, and when it gets scheduled in again. + + profiling/thread-times.stp - Profile kernel functions keywords: profiling diff --git a/testsuite/systemtap.examples/keyword-index.html b/testsuite/systemtap.examples/keyword-index.html index 1a68a9f0..2aad9adf 100644 --- a/testsuite/systemtap.examples/keyword-index.html +++ b/testsuite/systemtap.examples/keyword-index.html @@ -120,6 +120,9 @@ keywords: NETWORK profiling/functioncallcount.stp - Count Times Functions Called
    keywords: PROFILING FUNCTIONS

    The functioncallcount.stp script takes one argument, a list of functions to probe. The script will run and count the number of times that each of the functions on the list is called. On exit the script will print a sorted list from most frequently to least frequently called function.

    +
  • profiling/sched_switch.stp - Display the task switches happening in the scheduler
    +keywords: PROFILING FUNCTIONS
    +

    The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks schedule out the current process being traced, and when it gets scheduled in again.

  • FUTEX

      @@ -300,6 +303,9 @@ keywords: PROFILING
    • profiling/functioncallcount.stp - Count Times Functions Called
      keywords: PROFILING FUNCTIONS

      The functioncallcount.stp script takes one argument, a list of functions to probe. The script will run and count the number of times that each of the functions on the list is called. On exit the script will print a sorted list from most frequently to least frequently called function.

    • +
    • profiling/sched_switch.stp - Display the task switches happening in the scheduler
      +keywords: PROFILING FUNCTIONS
      +

      The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks schedule out the current process being traced, and when it gets scheduled in again.

    • profiling/thread-times.stp - Profile kernel functions
      keywords: PROFILING

      The thread-times.stp script sets up time-based sampling. Every five seconds it prints out a sorted list with the top twenty processes with samples broken down into percentage total time spent in user-space and kernel-space.

    • diff --git a/testsuite/systemtap.examples/keyword-index.txt b/testsuite/systemtap.examples/keyword-index.txt index 056b553a..01661cf1 100644 --- a/testsuite/systemtap.examples/keyword-index.txt +++ b/testsuite/systemtap.examples/keyword-index.txt @@ -154,6 +154,18 @@ keywords: profiling functions called function. +profiling/sched_switch.stp - Display the task switches happening in the scheduler +keywords: profiling functions + + The sched_switch.stp script takes two arguments, first argument can + be "pid" or "name" to indicate what is being passed as second + argument. The script will trace the process based on pid/name and + print the scheduler switches happening with the process. If no + arguments are passed, it displays all the scheduler switches. This + can be used to understand which tasks schedule out the current + process being traced, and when it gets scheduled in again. + + = FUTEX = process/futexes.stp - System-Wide Futex Contention @@ -618,6 +630,18 @@ keywords: profiling functions called function. +profiling/sched_switch.stp - Display the task switches happening in the scheduler +keywords: profiling functions + + The sched_switch.stp script takes two arguments, first argument can + be "pid" or "name" to indicate what is being passed as second + argument. The script will trace the process based on pid/name and + print the scheduler switches happening with the process. If no + arguments are passed, it displays all the scheduler switches. This + can be used to understand which tasks schedule out the current + process being traced, and when it gets scheduled in again. + + profiling/thread-times.stp - Profile kernel functions keywords: profiling diff --git a/testsuite/systemtap.examples/profiling/sched_switch.meta b/testsuite/systemtap.examples/profiling/sched_switch.meta index 8f1a2858..b202a74c 100644 --- a/testsuite/systemtap.examples/profiling/sched_switch.meta +++ b/testsuite/systemtap.examples/profiling/sched_switch.meta @@ -1,4 +1,4 @@ -title: Display the task switches happeningt the scheduler +title: Display the task switches happening in the scheduler name: sched_switch.stp version: 1.0 author: kiran @@ -6,9 +6,9 @@ keywords: profiling functions subsystem: kernel status: production exit: user-controlled -output: sorted-list on-exit +output: trace scope: system-wide -description: The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks scheduler the current process being traced, out and when it gets scheduled in again. +description: The sched_switch.stp script takes two arguments, first argument can be "pid" or "name" to indicate what is being passed as second argument. The script will trace the process based on pid/name and print the scheduler switches happening with the process. If no arguments are passed, it displays all the scheduler switches. This can be used to understand which tasks schedule out the current process being traced, and when it gets scheduled in again. test_check: stap -p4 sched_switch.stp test_installcheck: stap sched_switch.stp -c "sleep 1" diff --git a/testsuite/systemtap.examples/profiling/sched_switch.stp b/testsuite/systemtap.examples/profiling/sched_switch.stp old mode 100644 new mode 100755 index 24973526..1c1b18b7 --- a/testsuite/systemtap.examples/profiling/sched_switch.stp +++ b/testsuite/systemtap.examples/profiling/sched_switch.stp @@ -1,3 +1,4 @@ +#! /usr/bin/env stap /* This script works similar to ftrace's sched_switch. It displays a list of * processes which get switched in and out of the scheduler. The format of display * is PROCESS_NAME PROCESS_PID CPU TIMESTAMP PID: PRIORITY: PROCESS STATE ->/+ -- cgit