Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Mar 2009 19:03:15 -0700
From:      David Wolfskill <david@catwhisker.org>
To:        Jay Loden <freebsd@jayloden.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: CPU user/kernel time given the PID
Message-ID:  <20090309020315.GW4315@albert.catwhisker.org>
In-Reply-To: <49B463D7.9010401@jayloden.com>
References:  <200903082156.n28Lup7e085565@lurza.secnetix.de> <49B463D7.9010401@jayloden.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090309020315.GW4315>