2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1990 Carnegie-Mellon University
28 * All rights reserved. The CMU software License Agreement specifies
29 * the terms and conditions for use and redistribution.
33 * Author: Avadis Tevanian, Jr.
35 * Copyright (C) 1987, Avadis Tevanian, Jr.
37 * Display information about the host this program is
41 #include <mach/mach.h>
42 #include <mach/mach_error.h>
43 #include <mach/bootstrap.h>
47 struct host_basic_info hi
;
48 kernel_version_t version
;
51 int main(int argc
, char *argv
[])
55 char *cpu_name
, *cpu_subname
;
57 processor_set_name_port_t default_pset
;
58 host_name_port_t host
;
59 struct processor_set_basic_info basic_info
;
60 struct processor_set_load_info load_info
;
62 host
= mach_host_self();
63 ret
= host_kernel_version(host
, version
);
64 if (ret
!= KERN_SUCCESS
) {
65 mach_error(argv
[0], ret
);
68 printf("Mach kernel version:\n\t %s\n", version
);
69 size
= sizeof(hi
)/sizeof(int);
70 ret
= host_info(host
, HOST_BASIC_INFO
, (host_info_t
)&hi
, &size
);
71 if (ret
!= KERN_SUCCESS
) {
72 mach_error(argv
[0], ret
);
76 ret
= processor_set_default(host
, &default_pset
);
77 if (ret
!= KERN_SUCCESS
) {
78 mach_error(argv
[0], ret
);
82 count
= PROCESSOR_SET_BASIC_INFO_COUNT
;
83 ret
= processor_set_info(default_pset
, PROCESSOR_SET_BASIC_INFO
,
84 &host
, (processor_set_info_t
)&basic_info
, &count
);
85 if (ret
!= KERN_SUCCESS
) {
86 mach_error(argv
[0], ret
);
90 count
= PROCESSOR_SET_LOAD_INFO_COUNT
;
91 ret
= processor_set_statistics(default_pset
, PROCESSOR_SET_LOAD_INFO
,
92 (processor_set_info_t
)&load_info
, &count
);
93 if (ret
!= KERN_SUCCESS
) {
94 mach_error(argv
[0], ret
);
98 printf("Kernel configured for up to %d processors.\n",
101 printf("Kernel configured for a single processor only.\n");
102 printf("%d processor%s physically available.\n", hi
.avail_cpus
,
103 (hi
.avail_cpus
> 1) ? "s are" : " is");
105 printf("Processor type:");
106 slot_name(hi
.cpu_type
, hi
.cpu_subtype
, &cpu_name
, &cpu_subname
);
107 printf(" %s (%s)\n", cpu_name
, cpu_subname
);
109 printf("Processor%s active:", (hi
.avail_cpus
> 1) ? "s" : "");
110 for (i
= 0; i
< hi
.avail_cpus
; i
++)
114 printf("Primary memory available: %.2f megabytes.\n",
115 (float)hi
.memory_size
/(1024.0*1024.0));
116 printf("Default processor set: %d tasks, %d threads, %d processors\n",
117 load_info
.task_count
, load_info
.thread_count
, basic_info
.processor_count
);
118 printf("Load average: %d.%02d, Mach factor: %d.%02d\n",
119 load_info
.load_average
/LOAD_SCALE
,
120 (load_info
.load_average%LOAD_SCALE
)/10,
121 load_info
.mach_factor
/LOAD_SCALE
,
122 (load_info
.mach_factor%LOAD_SCALE
)/10);