]> git.saurik.com Git - apple/system_cmds.git/blame - hostinfo.tproj/hostinfo.c
system_cmds-279.6.1.tar.gz
[apple/system_cmds.git] / hostinfo.tproj / hostinfo.c
CommitLineData
1815bff5
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d904471c
A
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
1815bff5
A
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d904471c
A
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
1815bff5
A
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Mach Operating System
26 * Copyright (c) 1990 Carnegie-Mellon University
27 * All rights reserved. The CMU software License Agreement specifies
28 * the terms and conditions for use and redistribution.
29 */
30/*
31 * File: hostinfo.c
32 * Author: Avadis Tevanian, Jr.
33 *
34 * Copyright (C) 1987, Avadis Tevanian, Jr.
35 *
36 * Display information about the host this program is
37 * execting on.
38 */
39
40#include <mach/mach.h>
41#include <mach/mach_error.h>
42#include <mach/bootstrap.h>
43#include <stdio.h>
44#include <stdlib.h>
45
46struct host_basic_info hi;
47kernel_version_t version;
48int slots[1024];
49
50int main(int argc, char *argv[])
51{
52 kern_return_t ret;
53 int size;
54 char *cpu_name, *cpu_subname;
55 int i, count;
56 processor_set_name_port_t default_pset;
57 host_name_port_t host;
58 struct processor_set_basic_info basic_info;
59 struct processor_set_load_info load_info;
60
61 host = mach_host_self();
62 ret = host_kernel_version(host, version);
63 if (ret != KERN_SUCCESS) {
64 mach_error(argv[0], ret);
65 exit(EXIT_FAILURE);
66 }
67 printf("Mach kernel version:\n\t %s\n", version);
68 size = sizeof(hi)/sizeof(int);
69 ret = host_info(host, HOST_BASIC_INFO, (host_info_t)&hi, &size);
70 if (ret != KERN_SUCCESS) {
71 mach_error(argv[0], ret);
72 exit(EXIT_FAILURE);
73 }
74
75 ret = processor_set_default(host, &default_pset);
76 if (ret != KERN_SUCCESS) {
77 mach_error(argv[0], ret);
78 exit(EXIT_FAILURE);
79 }
80
81 count = PROCESSOR_SET_BASIC_INFO_COUNT;
82 ret = processor_set_info(default_pset, PROCESSOR_SET_BASIC_INFO,
83 &host, (processor_set_info_t)&basic_info, &count);
84 if (ret != KERN_SUCCESS) {
85 mach_error(argv[0], ret);
86 exit(EXIT_FAILURE);
87 }
88
89 count = PROCESSOR_SET_LOAD_INFO_COUNT;
90 ret = processor_set_statistics(default_pset, PROCESSOR_SET_LOAD_INFO,
91 (processor_set_info_t)&load_info, &count);
92 if (ret != KERN_SUCCESS) {
93 mach_error(argv[0], ret);
94 exit(EXIT_FAILURE);
95 }
96 if (hi.max_cpus > 1)
97 printf("Kernel configured for up to %d processors.\n",
98 hi.max_cpus);
99 else
100 printf("Kernel configured for a single processor only.\n");
101 printf("%d processor%s physically available.\n", hi.avail_cpus,
102 (hi.avail_cpus > 1) ? "s are" : " is");
103
104 printf("Processor type:");
105 slot_name(hi.cpu_type, hi.cpu_subtype, &cpu_name, &cpu_subname);
106 printf(" %s (%s)\n", cpu_name, cpu_subname);
107
108 printf("Processor%s active:", (hi.avail_cpus > 1) ? "s" : "");
109 for (i = 0; i < hi.avail_cpus; i++)
110 printf(" %d", i);
111 printf("\n");
112
113 printf("Primary memory available: %.2f megabytes.\n",
114 (float)hi.memory_size/(1024.0*1024.0));
115 printf("Default processor set: %d tasks, %d threads, %d processors\n",
116 load_info.task_count, load_info.thread_count, basic_info.processor_count);
117 printf("Load average: %d.%02d, Mach factor: %d.%02d\n",
118 load_info.load_average/LOAD_SCALE,
119 (load_info.load_average%LOAD_SCALE)/10,
120 load_info.mach_factor/LOAD_SCALE,
121 (load_info.mach_factor%LOAD_SCALE)/10);
122}
123