From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 9 02:03:16 2009 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 773E7106566B for ; Mon, 9 Mar 2009 02:03:16 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from albert.catwhisker.org (adsl-63-193-123-122.dsl.snfc21.pacbell.net [63.193.123.122]) by mx1.freebsd.org (Postfix) with ESMTP id 2671B8FC1A for ; Mon, 9 Mar 2009 02:03:15 +0000 (UTC) (envelope-from david@catwhisker.org) Received: from albert.catwhisker.org (localhost [127.0.0.1]) by albert.catwhisker.org (8.14.3/8.14.3) with ESMTP id n2923FGF055354; Sun, 8 Mar 2009 19:03:15 -0700 (PDT) (envelope-from david@albert.catwhisker.org) Received: (from david@localhost) by albert.catwhisker.org (8.14.3/8.14.3/Submit) id n2923FTG055353; Sun, 8 Mar 2009 19:03:15 -0700 (PDT) (envelope-from david) Date: Sun, 8 Mar 2009 19:03:15 -0700 From: David Wolfskill To: Jay Loden Message-ID: <20090309020315.GW4315@albert.catwhisker.org> Mail-Followup-To: David Wolfskill , Jay Loden , freebsd-hackers@freebsd.org References: <200903082156.n28Lup7e085565@lurza.secnetix.de> <49B463D7.9010401@jayloden.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="SvF6CGw9fzJC4Rcx" Content-Disposition: inline In-Reply-To: <49B463D7.9010401@jayloden.com> User-Agent: Mutt/1.4.2.3i Cc: freebsd-hackers@freebsd.org Subject: Re: CPU user/kernel time given the PID 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: Mon, 09 Mar 2009 02:03:16 -0000 --SvF6CGw9fzJC4Rcx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 08, 2009 at 08:33:27PM -0400, Jay Loden wrote: > Oliver Fromme wrote: > > ps(1) and top(1) both use ki_pctcpu, see the getpcpu() > > function in src/bin/ps/print.c and format_next_process() > > in src/usr.bin/top/machine.c >=20 > Hi Oliver, thanks for the reply. I noticed the same after some digging th= rough > the source code for ps and top. While CPU usage % is a useful number also= , I was > hoping to be able to get CPU time(s). Possibly that information simply is= n't > available on FreeBSD like it is for other OSes. Have you checked to see if you can make use of the information provided by procfs(5)? In particular, I note: =2E.. status The process status. This file is read-only and returns a sing= le line containing multiple space-separated fields as follows: o command name o process id =2E.. o the process start time in seconds and microseconds, comma separated. o the user time in seconds and microseconds, comma separated. o the system time in seconds and microseconds, comma separat= ed. o the wait channel message =2E... Thus, on my laptop, I see: g1-35(6.4-S)[1] cat /proc/`pgrep firefox-bin`/status firefox-bin 1735 1730 1549 1454 - noflags 1236526247,367664 3289,390208 477= ,843140 -kse- 1001 1001 1001,1001,1001,0,20,68,69,1004 - g1-35(6.4-S)[2]=20 So above-listed items would be: * firefox-bin * 1735 =2E.. * 1236526247,367664 * 3289,390208 * 477,843140 * -kse- * -kse- =2E... Granted, not every machine will necessarily have PROCFS in the kernel configuration, but it is in GENERIC. > ... Peace, david --=20 David H. Wolfskill david@catwhisker.org Depriving a girl or boy of an opportunity for education is evil. See http://www.catwhisker.org/~david/publickey.gpg for my public key. --SvF6CGw9fzJC4Rcx Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkm0eOIACgkQmprOCmdXAD2eWACcCdNwXWnI5mbQJlYrn9BTNjI2 c9MAn3/DBD1gU5+SzZizc4RGPDoLLsdn =hYcW -----END PGP SIGNATURE----- --SvF6CGw9fzJC4Rcx--