* Re: Stap scripts to track task cpu changes
[not found] <200907130937.32782.varunc@linux.vnet.ibm.com>
@ 2009-07-13 4:18 ` Ankita Garg
2009-07-13 20:07 ` William Cohen
0 siblings, 1 reply; 4+ messages in thread
From: Ankita Garg @ 2009-07-13 4:18 UTC (permalink / raw)
To: William Cohen; +Cc: prerna, systemtap
Hello William,
> Subject: Re: Stap scripts to track task cpu changes
> Date: Thursday 09 Jul 2009
> From: William Cohen <wcohen@redhat.com>
> To: Ankita Garg <ankita@in.ibm.com>, systemtap@sources.redhat.com,
> prerna@linux.vnet.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.
>
Thanks for making the required formatting changes.
> 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"
>
True, the checks for tid() !=0 seem unneccesary. In migrate.stp (ie in
function __migrate_task), the task being migrated need not be the
current task. Hence, using $p->pid and $p->comm, where $p is the task being
migrated.
> -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);
> }
> }
--
Regards,
Ankita Garg (ankita@in.ibm.com)
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Stap scripts to track task cpu changes
2009-07-13 4:18 ` Stap scripts to track task cpu changes Ankita Garg
@ 2009-07-13 20:07 ` William Cohen
0 siblings, 0 replies; 4+ messages in thread
From: William Cohen @ 2009-07-13 20:07 UTC (permalink / raw)
To: Ankita Garg, William Cohen, prerna, systemtap
[-- Attachment #1: Type: text/plain, Size: 1860 bytes --]
Ankita Garg wrote:
> Hello William,
>
>> Subject: Re: Stap scripts to track task cpu changes
>> Date: Thursday 09 Jul 2009
>> From: William Cohen <wcohen@redhat.com>
>> To: Ankita Garg <ankita@in.ibm.com>, systemtap@sources.redhat.com,
>> prerna@linux.vnet.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.
>>
>
> Thanks for making the required formatting changes.
>
>> 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"
>>
>
> True, the checks for tid() !=0 seem unneccesary. In migrate.stp (ie in
> function __migrate_task), the task being migrated need not be the
> current task. Hence, using $p->pid and $p->comm, where $p is the task being
> migrated.
>
>> -Will
Hi Ankita,
A bit more tweaking on the examples. For the chng_cpu2.stp I moved the
assignment to threads associative array inside the if statement to avoid
overflowing the array. For migrate3.stp I made it take the executable name, so
that it works in a manner similar to chng_cpu2.stp. Was there multiple instances
of the same execname running one the machine or would using the execname be
sufficent for migrate.stp?
-Will
[-- Attachment #2: chng_cpu2.stp --]
[-- Type: text/plain, Size: 1034 bytes --]
/* 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() && (execname() == @1))) {
printf("\nthread %d (%s) context switched on cpu%d state: %d\n",
tid(), execname(), cpu(), task_state(task_current()));
print_stack(backtrace());
threads[tid()] = cpu();
}
}
[-- Attachment #3: migrate3.stp --]
[-- Type: text/plain, Size: 922 bytes --]
/* 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")
{
comm = kernel_string($p->comm);
if (comm == @1) {
printf ("thread %d (%s) is migrating from %d to %d \n",
$p->pid, comm, $src_cpu, $dest_cpu);
}
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Stap scripts to track task cpu changes
2009-06-19 11:42 Ankita Garg
@ 2009-07-09 14:26 ` William Cohen
0 siblings, 0 replies; 4+ messages in thread
From: William Cohen @ 2009-07-09 14:26 UTC (permalink / raw)
To: Ankita Garg, systemtap, prerna
[-- Attachment #1: Type: text/plain, Size: 815 bytes --]
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
[-- Attachment #2: chng_cpu2.stp --]
[-- Type: text/plain, Size: 1059 bytes --]
/* 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();
}
[-- Attachment #3: migrate2.stp --]
[-- Type: text/plain, Size: 907 bytes --]
/* 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);
}
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Stap scripts to track task cpu changes
@ 2009-06-19 11:42 Ankita Garg
2009-07-09 14:26 ` William Cohen
0 siblings, 1 reply; 4+ messages in thread
From: Ankita Garg @ 2009-06-19 11:42 UTC (permalink / raw)
To: systemtap; +Cc: prerna
[-- Attachment #1: Type: text/plain, Size: 2768 bytes --]
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.
/* Filename: migrate.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the migration of threads
*
* 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 IBM Corp. 2009. All Rights Reserved.
*
*/
probe kernel.function("__migrate_task")
{
if(($1 != 0 ) && (tid() == $1)) {
printf ("thread %d (%s) is migrating from %d to %d \n", $p->pid,
kernel_string($p->comm), $src_cpu, $dest_cpu);
}
}
Below is a script that tracks all the cpus that a particular task ran
on. Pl note it does not track the context switches.
/* Filename: chng_cpu.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the number of times java thread
* 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 IBM Corp. 2009. All Rights Reserved.
*
*/
global threads
probe kernel.function("finish_task_switch")
{
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();
}
With the new tracepoints infrastructure, the above stats could maybe be
captured in a much easier way, however, it worked well with stap as well
:-) Do let me know if you have any suggestions.
--
Regards,
Ankita Garg (ankita@in.ibm.com)
Linux Technology Center
IBM India Systems & Technology Labs,
Bangalore, India
[-- Attachment #2: migrate.stp --]
[-- Type: text/plain, Size: 910 bytes --]
/* Filename: migrate.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the migration of threads
*
* 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 IBM Corp. 2009. All Rights Reserved.
*
*/
probe kernel.function("__migrate_task")
{
if(($1 != 0 ) && (tid() == $1)) {
printf ("thread %d (%s) is migrating from %d to %d \n", $p->pid,
kernel_string($p->comm), $src_cpu, $dest_cpu);
}
}
[-- Attachment #3: chng_cpu.stp --]
[-- Type: text/plain, Size: 1120 bytes --]
/* Filename: chng_cpu.stp
* Author: Ankita Garg <ankita@in.ibm.com>
* Description: Captures information on the number of times java thread
* 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 IBM Corp. 2009. All Rights Reserved.
*
*/
global threads
probe kernel.function("finish_task_switch")
{
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();
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-07-13 20:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <200907130937.32782.varunc@linux.vnet.ibm.com>
2009-07-13 4:18 ` Stap scripts to track task cpu changes Ankita Garg
2009-07-13 20:07 ` William Cohen
2009-06-19 11:42 Ankita Garg
2009-07-09 14:26 ` William Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).