From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14748 invoked by alias); 19 Jun 2009 11:42:08 -0000 Received: (qmail 14736 invoked by uid 22791); 19 Jun 2009 11:42:06 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,J_CHICKENPOX_73,SPF_PASS X-Spam-Check-By: sourceware.org Received: from e28smtp01.in.ibm.com (HELO e28smtp01.in.ibm.com) (59.145.155.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 19 Jun 2009 11:41:59 +0000 Received: from d28relay02.in.ibm.com (d28relay02.in.ibm.com [9.184.220.59]) by e28smtp01.in.ibm.com (8.13.1/8.13.1) with ESMTP id n5JBfpce015602 for ; Fri, 19 Jun 2009 17:11:51 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay02.in.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n5JBfpdZ286826 for ; Fri, 19 Jun 2009 17:11:51 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.13.1/8.13.3) with ESMTP id n5JBfpQD028191 for ; Fri, 19 Jun 2009 17:11:51 +0530 Received: from rollercoaster.localdomain (rollercoaster.in.ibm.com [9.124.31.21]) by d28av01.in.ibm.com (8.13.1/8.12.11) with ESMTP id n5JBfp6J028181; Fri, 19 Jun 2009 17:11:51 +0530 Received: by rollercoaster.localdomain (Postfix, from userid 1000) id 1A05F31C7A; Fri, 19 Jun 2009 17:11:51 +0530 (IST) Date: Fri, 19 Jun 2009 11:42:00 -0000 From: Ankita Garg To: systemtap@sources.redhat.com Cc: prerna@linux.vnet.ibm.com Subject: Stap scripts to track task cpu changes Message-ID: <20090619114151.GA13999@in.ibm.com> Reply-To: Ankita Garg Mail-Followup-To: Ankita Garg , systemtap@sources.redhat.com, prerna@linux.vnet.ibm.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact systemtap-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: systemtap-owner@sourceware.org X-SW-Source: 2009-q2/txt/msg00968.txt.bz2 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Content-length: 2766 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 * 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 * 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 --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="migrate.stp" Content-Transfer-Encoding: 8bit Content-length: 909 /* Filename: migrate.stp * Author: Ankita Garg * 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); } } --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="chng_cpu.stp" Content-Transfer-Encoding: 8bit Content-length: 1119 /* Filename: chng_cpu.stp * Author: Ankita Garg * 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(); } --TB36FDmn/VVEgNH/--