X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/c3a08f5910a028cdace032ed79beb406c750d530..a8daac8f698fa38f1ca3aaa2a3ed6ac20e5128e2:/sar.tproj/sar.c diff --git a/sar.tproj/sar.c b/sar.tproj/sar.c index c3bb33f..1f046c0 100644 --- a/sar.tproj/sar.c +++ b/sar.tproj/sar.c @@ -1,16 +1,13 @@ /* - * 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 @@ -19,9 +16,7 @@ * 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 @@ -466,11 +461,12 @@ main(argc, argv) #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); } @@ -1125,6 +1121,14 @@ print_cpu_sample(timebufptr) += 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]; @@ -1145,6 +1149,9 @@ print_cpu_sample(timebufptr) 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)); @@ -1158,6 +1165,10 @@ print_cpu_sample(timebufptr) 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))); @@ -1571,6 +1582,10 @@ exit_average() (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)); @@ -2294,7 +2309,7 @@ print_column_heading(int type, char *timebufptr, int mode) 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: