]>
Commit | Line | Data |
---|---|---|
1815bff5 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
c3a08f59 A |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
7 | * | |
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 | |
13 | * file. | |
1815bff5 A |
14 | * |
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, | |
c3a08f59 A |
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. | |
1815bff5 A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
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. | |
30 | */ | |
31 | /* | |
32 | * File: hostinfo.c | |
33 | * Author: Avadis Tevanian, Jr. | |
34 | * | |
35 | * Copyright (C) 1987, Avadis Tevanian, Jr. | |
36 | * | |
37 | * Display information about the host this program is | |
38 | * execting on. | |
39 | */ | |
40 | ||
41 | #include <mach/mach.h> | |
42 | #include <mach/mach_error.h> | |
43 | #include <mach/bootstrap.h> | |
44 | #include <stdio.h> | |
45 | #include <stdlib.h> | |
46 | ||
47 | struct host_basic_info hi; | |
48 | kernel_version_t version; | |
49 | int slots[1024]; | |
50 | ||
51 | int main(int argc, char *argv[]) | |
52 | { | |
53 | kern_return_t ret; | |
54 | int size; | |
55 | char *cpu_name, *cpu_subname; | |
56 | int i, count; | |
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; | |
61 | ||
62 | host = mach_host_self(); | |
63 | ret = host_kernel_version(host, version); | |
64 | if (ret != KERN_SUCCESS) { | |
65 | mach_error(argv[0], ret); | |
66 | exit(EXIT_FAILURE); | |
67 | } | |
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); | |
73 | exit(EXIT_FAILURE); | |
74 | } | |
75 | ||
76 | ret = processor_set_default(host, &default_pset); | |
77 | if (ret != KERN_SUCCESS) { | |
78 | mach_error(argv[0], ret); | |
79 | exit(EXIT_FAILURE); | |
80 | } | |
81 | ||
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); | |
87 | exit(EXIT_FAILURE); | |
88 | } | |
89 | ||
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); | |
95 | exit(EXIT_FAILURE); | |
96 | } | |
97 | if (hi.max_cpus > 1) | |
98 | printf("Kernel configured for up to %d processors.\n", | |
99 | hi.max_cpus); | |
100 | else | |
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"); | |
104 | ||
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); | |
108 | ||
109 | printf("Processor%s active:", (hi.avail_cpus > 1) ? "s" : ""); | |
110 | for (i = 0; i < hi.avail_cpus; i++) | |
111 | printf(" %d", i); | |
112 | printf("\n"); | |
113 | ||
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); | |
123 | } | |
124 |