Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933678AbZLFK7H (ORCPT ); Sun, 6 Dec 2009 05:59:07 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S933659AbZLFK7G (ORCPT ); Sun, 6 Dec 2009 05:59:06 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:64134 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S933658AbZLFK7F (ORCPT ); Sun, 6 Dec 2009 05:59:05 -0500 Message-ID: <4B1B8E0E.3040007@cn.fujitsu.com> Date: Sun, 06 Dec 2009 18:57:18 +0800 From: Xiao Guangrong User-Agent: Thunderbird 2.0.0.6 (Windows/20070728) MIME-Version: 1.0 To: Ingo Molnar CC: Peter Zijlstra , Frederic Weisbecker , Paul Mackerras , LKML Subject: [PATCH] perf/sched: fix for getting task's execute time Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1633 Lines: 55 In current code, we get task's execute time by reading "/proc//sched" file, it's wrong if the task is created by pthread_create(), because every thread task has same pid. So, the correct way is reading "/proc//task//sched" file. This patch also remove redundant include files since is included in "perf.h" Signed-off-by: Xiao Guangrong --- tools/perf/builtin-sched.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 26b782f..b2e910e 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -13,7 +13,6 @@ #include "util/debug.h" #include "util/data_map.h" -#include #include #include @@ -416,7 +415,7 @@ static u64 get_cpu_usage_nsec_parent(void) static u64 get_cpu_usage_nsec_self(void) { - char filename [] = "/proc/1234567890/sched"; + char filename [] = "/proc/1234567890/task/1234567890/sched"; unsigned long msecs, nsecs; char *line = NULL; u64 total = 0; @@ -425,7 +424,9 @@ static u64 get_cpu_usage_nsec_self(void) FILE *file; int ret; - sprintf(filename, "/proc/%d/sched", getpid()); + sprintf(filename, "/proc/%d/task/%d/sched", getpid(), + (pid_t)syscall(SYS_gettid)); + file = fopen(filename, "r"); BUG_ON(!file); -- 1.6.1.2 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/