This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: Stap scripts to track task cpu changes
- From: William Cohen <wcohen at redhat dot com>
- To: Ankita Garg <ankita at in dot ibm dot com>, systemtap at sources dot redhat dot com, prerna at linux dot vnet dot ibm dot com
- Date: Thu, 09 Jul 2009 10:26:26 -0400
- Subject: Re: Stap scripts to track task cpu changes
- References: <20090619114151.GA13999@in.ibm.com>
Ankita Garg wrote:
> Hello folks,
>
> Quite sometime back, I was faced with a situation where I needed to
> track instances when a particular task was being migrated away from a
> cpu. I used the following trivial script. The tid needs to be passed as
> parameter. Sharing it, hoping it might be useful for some folks.
I would like to add these example to the systemtap examples. I have looked
through them and made some tweaks. For both of them I formatted them not to use
tabs so they can used in documentation.
For chng_cpu.stp use the appropriate probe point, scheduler.cpu_on. Why the
check for "tid() != 0"?
For migrate.stp The check "$1 != 0" seemed to be unneeded. Was there a reason
for using $p->pid and kernel_string($p->comm) rather tid() and execname()? The
test is using "tid() == $1"
-Will
/* Filename: chng_cpu.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the number of times an executable
* switches cpu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Copyright (C) IBM Corp. 2009. All Rights Reserved.
*
*/
global threads
probe scheduler.cpu_on
{
if ((threads[tid()] != cpu()) && (tid() != 0) && (execname() == @1)) {
printf("thread %d (%s) context switched on %d \n",
tid(), execname(), cpu());
printf("state: %d\n", task_state(task_current()))
print_stack(backtrace())
}
threads[tid()] = cpu();
}
/* Filename: migrate.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the migration of a thread
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Copyright (C) IBM Corp. 2009. All Rights Reserved.
*
*/
probe kernel.function("__migrate_task")
{
if(tid() == $1) {
printf ("thread %d (%s) is migrating from %d to %d \n",
$p->pid, kernel_string($p->comm), $src_cpu, $dest_cpu);
}
}