/*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
+ * Reserved.
*
- * @APPLE_LICENSE_HEADER_START@
- *
- * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
- * This file contains Original Code and/or Modifications of Original Code
- * as defined in and that are subject to the Apple Public Source License
- * Version 2.0 (the 'License'). You may not use this file except in
- * compliance with the License. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this
+ * file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
- * @APPLE_LICENSE_HEADER_END@
- */
+*/
/*
cc -Wall -Wno-long-double -I. -I ../sadc.tproj -O -o sar sar.c
#if 0
int efd;
#endif
+ int fdlimit = getdtablesize();
/* This is the child */
/* Close all file descriptors except the one we need */
- for (i=0; i <= KERN_MAXFILESPERPROC; i++) {
+ for (i=0; i < fdlimit; i++) {
if ((i != fd[0]) && (i != fd[1]))
(void)close(i);
}
+= cur_cpuload.cpu_ticks[CPU_STATE_USER];
time += cur_cpuload.cpu_ticks[CPU_STATE_USER];
+
+ cur_cpuload.cpu_ticks[CPU_STATE_NICE]
+ -= prev_cpuload.cpu_ticks[CPU_STATE_NICE];
+
+ prev_cpuload.cpu_ticks[CPU_STATE_NICE]
+ += cur_cpuload.cpu_ticks[CPU_STATE_NICE];
+
+ time += cur_cpuload.cpu_ticks[CPU_STATE_NICE];
cur_cpuload.cpu_ticks[CPU_STATE_SYSTEM]
-= prev_cpuload.cpu_ticks[CPU_STATE_SYSTEM];
avg_cpuload.cpu_ticks[CPU_STATE_USER] += rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_USER]
/ (time ? time : 1));
+ avg_cpuload.cpu_ticks[CPU_STATE_NICE] += rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_NICE]
+ / (time ? time : 1));
+
avg_cpuload.cpu_ticks[CPU_STATE_SYSTEM] += rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_SYSTEM]
/ (time ? time : 1));
rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_USER]
/ (time ? time : 1)));
+ fprintf(stdout, "%4.0f ",
+ rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_NICE]
+ / (time ? time : 1)));
+
fprintf(stdout, "%4.0f ",
rint(100. * cur_cpuload.cpu_ticks[CPU_STATE_SYSTEM]
/ (time ? time : 1)));
(int)avg_cpuload.cpu_ticks[CPU_STATE_USER]
/ (avg_counter ? avg_counter : 1));
+ fprintf(stdout, "%4d ",
+ (int)avg_cpuload.cpu_ticks[CPU_STATE_NICE]
+ / (avg_counter ? avg_counter : 1));
+
fprintf(stdout, "%4d ",
(int)avg_cpuload.cpu_ticks[CPU_STATE_SYSTEM]
/ (avg_counter ? avg_counter : 1));
switch (type)
{
case SAR_CPU:
- fprintf (stdout, "\n%s %%usr %%sys %%idle\n", p);
+ fprintf (stdout, "\n%s %%usr %%nice %%sys %%idle\n", p);
break;
case SAR_VMSTAT: