From owner-freebsd-hackers@FreeBSD.ORG Fri Jul 4 03:28:03 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B8DD1065675 for ; Fri, 4 Jul 2008 03:28:03 +0000 (UTC) (envelope-from stephen@math.missouri.edu) Received: from cauchy.math.missouri.edu (cauchy.math.missouri.edu [128.206.184.213]) by mx1.freebsd.org (Postfix) with ESMTP id 3A5828FC1C for ; Fri, 4 Jul 2008 03:28:03 +0000 (UTC) (envelope-from stephen@math.missouri.edu) Received: from laptop3.gateway.2wire.net (cauchy.math.missouri.edu [128.206.184.213]) by cauchy.math.missouri.edu (8.14.2/8.14.2) with ESMTP id m643R9xq070605; Thu, 3 Jul 2008 22:27:10 -0500 (CDT) (envelope-from stephen@math.missouri.edu) Message-ID: <486D98C1.9060401@math.missouri.edu> Date: Thu, 03 Jul 2008 22:28:01 -0500 From: Stephen Montgomery-Smith User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.8.1.13) Gecko/20080702 SeaMonkey/1.1.9 MIME-Version: 1.0 To: Sergey Babkin References: <26495768.1230901215121011453.JavaMail.root@vms126.mailsrvcs.net> In-Reply-To: <26495768.1230901215121011453.JavaMail.root@vms126.mailsrvcs.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: time used by a thread X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Jul 2008 03:28:03 -0000 Sergey Babkin wrote: >> I want to use getrusage to see how much time a program is using. But >> this is a multithreaded program, and I just want the time taken by that >> particular thread! >> >> I know this info must be available somewhere, because top -H seems to >> provide it. But getrusage seems to give the total rusage for the whole >> program, not just the thread. >> >> Any ideas? I would especially appreciate a portable solution that works >> for OS other than FreeBSD (e.g. linux, etc as well). > > On Linux and Solaris it can be done by reading the /proc filesystem. > Probably on FreeBSD too, haven't tried. But it's different on each OS. Thanks. I developed a non-portable solution using kvm_getprocs.