Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 08 Mar 2009 20:33:27 -0400
From:      Jay Loden <freebsd@jayloden.com>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: CPU user/kernel time given the PID
Message-ID:  <49B463D7.9010401@jayloden.com>
In-Reply-To: <200903082156.n28Lup7e085565@lurza.secnetix.de>
References:  <200903082156.n28Lup7e085565@lurza.secnetix.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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.

> As far as I know, there is no distinction between user-
> mode and kernel-mode CPU time per process.  It should
> also be noted that the kernel's time cannot always be
> attributed to a certain userland process.  I would even
> guess is that the majority of the CPU time spent in the
> kernel is not on behalf of a specific userland process.

I would suspect the same, but I did notice that times() does return separate
values for user/system time on FreeBSD, so that implies that the system is able
to differentiate between the two somehow. If you can get it from within the
current running process the data must be there but I've no idea what interface
(if any) exists to read that information for other processes.

-Jay



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