From owner-freebsd-hackers Sat Mar 11 20:59:20 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from dorifer.heim3.tu-clausthal.de (dorifer.heim3.tu-clausthal.de [139.174.243.252]) by hub.freebsd.org (Postfix) with ESMTP id 5F48B37BC23 for ; Sat, 11 Mar 2000 20:59:17 -0800 (PST) (envelope-from olli@dorifer.heim3.tu-clausthal.de) Received: (from olli@localhost) by dorifer.heim3.tu-clausthal.de (8.9.3/8.9.3) id FAA54518; Sun, 12 Mar 2000 05:59:16 +0100 (CET) (envelope-from olli) Date: Sun, 12 Mar 2000 05:59:16 +0100 (CET) Message-Id: <200003120459.FAA54518@dorifer.heim3.tu-clausthal.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG Reply-To: freebsd-hackers@FreeBSD.ORG Subject: Re: Getting CPU usage in FreeBSD X-Newsgroups: list.freebsd-hackers In-Reply-To: <8advq0$a1h$1@atlantis.rz.tu-clausthal.de> User-Agent: tin/1.4.1-19991201 ("Polish") (UNIX) (FreeBSD/3.4-19991219-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Felipe Paulo Guazzi Bergo wrote in list.freebsd-hackers: > I am the author of gPS (http://gps.seul.org) and I'm trying to finish the > FreeBSD native poller. All I need now is a routine to get the CPU usage. > [...] > I've already looked at the source of top but couldn't get much from there. I'd recommend that you look at the vmstat source, located at /usr/src/usr.bin/vmstat.c. In particular, look at the line kread(X_CPTIME, cur.cp_time, sizeof(cur.cp_time)); Then look up the definition of kread() in the same file, and how the contents of cur.cp_time are used in the cpustats() function. Note that "cur" is a "struct statinfo", which is defined in /usr/include/devstat.h. The CPU states are defined in /usr/include/sys/dkstat.h. That should get you going. :-) Regards Oliver -- Oliver Fromme, Leibnizstr. 18/61, 38678 Clausthal, Germany (Info: finger userinfo:olli@dorifer.heim3.tu-clausthal.de) "In jedem Stück Kohle wartet ein Diamant auf seine Geburt" (Terry Pratchett) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message