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
[-- Attachment #1 --]
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
>
> Hi Oliver, thanks for the reply. I noticed the same after some digging through
> 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 isn'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:
...
status The process status. This file is read-only and returns a single
line containing multiple space-separated fields as follows:
o command name
o process id
...
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 separated.
o the wait channel message
....
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]
So above-listed items would be:
* firefox-bin
* 1735
...
* 1236526247,367664
* 3289,390208
* 477,843140
* -kse-
* -kse-
....
Granted, not every machine will necessarily have PROCFS in the
kernel configuration, but it is in GENERIC.
> ...
Peace,
david
--
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.
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (FreeBSD)
iEYEARECAAYFAkm0eOIACgkQmprOCmdXAD2eWACcCdNwXWnI5mbQJlYrn9BTNjI2
c9MAn3/DBD1gU5+SzZizc4RGPDoLLsdn
=hYcW
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090309020315.GW4315>
