From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 22 00:20:25 2010 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 7B7321065675 for ; Sun, 22 Aug 2010 00:20:25 +0000 (UTC) (envelope-from jessefrgsmith@yahoo.ca) Received: from n20.bullet.mail.mud.yahoo.com (n20.bullet.mail.mud.yahoo.com [68.142.206.147]) by mx1.freebsd.org (Postfix) with SMTP id 2D5A08FC19 for ; Sun, 22 Aug 2010 00:20:25 +0000 (UTC) Received: from [68.142.200.226] by n20.bullet.mail.mud.yahoo.com with NNFMP; 22 Aug 2010 00:20:21 -0000 Received: from [68.142.201.72] by t7.bullet.mud.yahoo.com with NNFMP; 22 Aug 2010 00:20:24 -0000 Received: from [127.0.0.1] by omp424.mail.mud.yahoo.com with NNFMP; 22 Aug 2010 00:19:29 -0000 X-Yahoo-Newman-Id: 637275.80342.bm@omp424.mail.mud.yahoo.com Received: (qmail 46595 invoked from network); 22 Aug 2010 00:19:29 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.ca; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:From:To:Cc:In-Reply-To:References:Content-Type:Date:Message-ID:Mime-Version:X-Mailer:Content-Transfer-Encoding; b=IYJ111eQ9oZxUbXCrgw5I6/jUSWgYxVSdcdn9ma9xuVHT7g0nSyUY+FAzq/qUx4Syyt27ak2HllTtvdwkltBYn7sTXR+vbsPPcH+Kt0v+p8dE7c2IqGmfFUzxJ/+pHSdDbBG1CEftroVELScvLtpr6y4myC3dADfTo6yUB4Hv1Q= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.ca; s=s1024; t=1282436369; bh=ZHI2buMf/iGxnkUixkZSIGm+XT6z0KDXxKIn4M0cI1g=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:From:To:Cc:In-Reply-To:References:Content-Type:Date:Message-ID:Mime-Version:X-Mailer:Content-Transfer-Encoding; b=Zm/qRUxencdwXpbIXDU774GSu8TgkhKxag4hxPJ7jcWUjpe/Vy+k0cFreFS71DBk3gOTtZnbUsFZYyCkCSMtElcFfnh7NemPKi1nmR06f4BUHi8FNpabB85EDqoY5MCiRHEVnBW25kyFhhnrUDc5zdPkc8IveNK0zjZhEOqZXN0= Received: from [192.168.0.104] (jessefrgsmith@71.7.176.238 with plain) by smtp136.mail.mud.yahoo.com with SMTP; 21 Aug 2010 17:19:29 -0700 PDT X-Yahoo-SMTP: NPm1JouswBClX_uJxHJINmnKUpROdMKvLL0- X-YMail-OSG: J.FsHOQVM1kAo1lIJK.dVr1iMq0HE5eofhwmwN521FP8Lsa 8vNbfd1f_svF53E.vqO2cJnQAQD7QqwoCfiiTck59UBHNtkyI7uycEVIVVlq DjfvRXtI5U4bNE4.PkvoWBe3IzLciXavBoKejCGQr20N79QSabg8z9.wMQSA Dmcs83TzUk1y1JOgy1z5j.fW36Gg0bv79IJRWA1gUOMKsJT6SREafFrs6KgF EPNDKfLYW4bztZs0yiQHl80WotRcmbt8XKFKrc0GyW4Bcu1om2MgeKLfUDIG SGAX1nR3E8ONBNxFcxiGlcdMFdHQsMj9_uc0AhRbc0e.2gIXtLKx2TsTKug- - X-Yahoo-Newman-Property: ymail-3 From: Jesse Smith To: Boris Kochergin In-Reply-To: <4C6E8732.8090304@acm.poly.edu> References: <1282310063.2601.9.camel@hp-laptop> <4C6E8732.8090304@acm.poly.edu> Content-Type: text/plain; charset="UTF-8" Date: Sat, 21 Aug 2010 21:19:20 -0300 Message-ID: <1282436360.31072.0.camel@hp-laptop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.1 Content-Transfer-Encoding: 7bit Cc: freebsd-hackers@freebsd.org Subject: Re: Converting from jiffies to ticks 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: Sun, 22 Aug 2010 00:20:25 -0000 -----Original Message----- From: Boris Kochergin To: Jesse Smith Cc: freebsd-hackers@freebsd.org Subject: Re: Converting from jiffies to ticks Date: Fri, 20 Aug 2010 09:46:26 -0400 Jesse Smith wrote: > I am currently trying to port a program from Linux to FreeBSD which > detects how much processor time a process is using. The native Linux > code does this (in part) by reading the number of "jiffies" a given > process uses. This info is pulled from the /proc/PID/stat file. > > One function is failing on FreeBSD and it's obviously because FreeBSD > does not have all the same files/data in the /proc directory. > > I've looked around and, as I understand it, FreeBSD uses "ticks" instead > of "jiffies" to measure process usage. However, how to gather that data > is a bit lost on me. > > This raises a question for me: > Where can I find the equivalent information on FreeBSD? I assume > there's a function call. Maybe in the kvm_* family? I need to be able to > get the number of ticks a given PID is using, both in the kernel and > userspace. > > > The rest of the program measures everything in "jiffies", so it would be > ideal for me to get the ticks used on FreeBSD (based on PID), convert it > to "jiffies" and pass it back to the main program. > > Thanks for any advice, > Jesse > > As someone pointed out on -hackers, the jiffies situation in Linux is messy because it depends on the architecture, what version of the kernel is in use, etc. If, in the end, you're just interested in things like the real and CPU time used, however, check out kvm_getprocs(3). The information available with that call is documented in the kinfo_proc structure in /usr/include/sys/user.h. -Boris ======================================= Thank you, this seems to do the trick. - Jesse