aboutsummaryrefslogtreecommitdiffstats
path: root/system_cmds/hostinfo.tproj
diff options
context:
space:
mode:
authorCameron Katri <me@cameronkatri.com>2021-05-09 14:20:58 -0400
committerCameron Katri <me@cameronkatri.com>2021-05-09 14:20:58 -0400
commit5fd83771641d15c418f747bd343ba6738d3875f7 (patch)
tree5abf0f78f680d9837dbd93d4d4c3933bb7509599 /system_cmds/hostinfo.tproj
downloadapple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.gz
apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.tar.zst
apple_cmds-5fd83771641d15c418f747bd343ba6738d3875f7.zip
Import macOS userland
adv_cmds-176 basic_cmds-55 bootstrap_cmds-116.100.1 developer_cmds-66 diskdev_cmds-667.40.1 doc_cmds-53.60.1 file_cmds-321.40.3 mail_cmds-35 misc_cmds-34 network_cmds-606.40.1 patch_cmds-17 remote_cmds-63 shell_cmds-216.60.1 system_cmds-880.60.2 text_cmds-106
Diffstat (limited to 'system_cmds/hostinfo.tproj')
-rw-r--r--system_cmds/hostinfo.tproj/hostinfo.889
-rw-r--r--system_cmds/hostinfo.tproj/hostinfo.c163
2 files changed, 252 insertions, 0 deletions
diff --git a/system_cmds/hostinfo.tproj/hostinfo.8 b/system_cmds/hostinfo.tproj/hostinfo.8
new file mode 100644
index 0000000..c24e7ab
--- /dev/null
+++ b/system_cmds/hostinfo.tproj/hostinfo.8
@@ -0,0 +1,89 @@
+.\" Copyright (c) 2003-2009 Apple Inc. All rights reserved.
+.\"
+.\" The contents of this file constitute Original Code as defined in and
+.\" are subject to the Apple Public Source License Version 1.1 (the
+.\" "License"). You may not use this file except in compliance with the
+.\" License. Please obtain a copy of the License at
+.\" http://www.apple.com/publicsource and read it before using this file.
+.\"
+.\" This Original Code and all software distributed under the License are
+.\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+.\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+.\" License for the specific language governing rights and limitations
+.\" under the License.
+.\"
+.\" @(#)hostinfo.1
+.Dd October 30, 2003 \" DATE
+.Dt hostinfo 8 \" Program name and manual section number
+.Os "Mac OS X"
+.Sh NAME \" Section Header - required - don't modify
+.Nm hostinfo
+.\" The following lines are read in generating the apropos(man -k) database. Use only key
+.\" words here as the database is built based on the words here and in the .ND line.
+.\" Use .Nm macro to designate other names for the documented program.
+.Nd host information
+.Sh SYNOPSIS \" Section Header - required - don't modify
+.Nm
+.Sh DESCRIPTION \" Section Header - required - don't modify
+The
+.Nm
+command displays information about the host system on which the command is executing.
+The output includes
+a kernel version description,
+processor configuration data,
+available physical memory,
+and various scheduling statistics.
+.Pp
+.Sh OPTIONS
+There are no options.
+.Sh DISPLAY
+.Pp
+.Bl -ohang -width Primary_memory_available_ -offset indent
+.It Mach kernel version:
+The version string compiled into the kernel executing on the host system.
+.Pp
+.It Processor Configuration:
+The maximum possible processors for which the kernel is configured,
+followed by the number of physical and logical processors available.
+.Pp
+Note: on Intel architectures, physical processors are referred to as cores, and
+logical processors are referred to as hardware threads; there may be multiple
+logical processors per core and multiple cores per processor package.
+This command does not report the number of processor packages.
+.Pp
+.It Processor type:
+The host's processor type and subtype.
+.Pp
+.It Processor active:
+A list of active processors on the host system.
+Active processors are members of a processor set and are ready to
+dispatch threads.
+On a single processor system, the active processor, is processor 0.
+.Pp
+.It Primary memory available:
+The amount of physical memory that is configured for use on the host system.
+.Pp
+.It Default processor set:
+Displays the number of tasks currently assigned to the host processor set,
+the number of threads currently assigned to the host processor set,
+and the number of processors included in the host processor set.
+.Pp
+.It Load average:
+Measures the average number of threads in the run queue.
+.Pp
+.It Mach factor:
+A variant of the load average which measures
+the processing resources available to a new thread.
+Mach factor is based on the number of CPUs divided by (1 + the number of runnablethreads)
+or
+the number of CPUs minus the number of runnable threads when the number of runnable threads
+is less than the number of CPUs.
+The closer the Mach factor value is to zero, the higher the load.
+On an idle system with a fixed number of active processors, the mach factor will be equal to the number of CPUs.
+.El
+.Sh SEE ALSO
+.\" List links in ascending order by section, alphabetically within a section.
+.Xr sysctl 8
+.\" .Sh BUGS \" Document known, unremedied bugs
diff --git a/system_cmds/hostinfo.tproj/hostinfo.c b/system_cmds/hostinfo.tproj/hostinfo.c
new file mode 100644
index 0000000..1828583
--- /dev/null
+++ b/system_cmds/hostinfo.tproj/hostinfo.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
+ *
+ * @APPLE_LICENSE_HEADER_START@
+ *
+ * "Portions Copyright (c) 1999 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 1.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.apple.com/publicsource 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
+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
+ * License for the specific language governing rights and limitations
+ * under the License."
+ *
+ * @APPLE_LICENSE_HEADER_END@
+ */
+/*
+ * Mach Operating System
+ * Copyright (c) 1990 Carnegie-Mellon University
+ * All rights reserved. The CMU software License Agreement specifies
+ * the terms and conditions for use and redistribution.
+ */
+/*
+ * File: hostinfo.c
+ * Author: Avadis Tevanian, Jr.
+ *
+ * Copyright (C) 1987, Avadis Tevanian, Jr.
+ *
+ * Display information about the host this program is
+ * execting on.
+ */
+
+#include <mach/mach.h>
+#include <mach/mach_error.h>
+#include <sys/sysctl.h>
+#include <sys/errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+struct host_basic_info hi;
+kernel_version_t version;
+int slots[1024];
+
+int
+main(int argc, char *argv[])
+{
+ kern_return_t ret;
+ unsigned int size, count;
+ char *cpu_name, *cpu_subname;
+ int mib[2];
+ size_t len;
+ uint64_t memsize;
+ processor_set_name_port_t default_pset;
+ host_name_port_t host;
+ struct processor_set_basic_info basic_info;
+ struct processor_set_load_info load_info;
+
+ host = mach_host_self();
+ ret = host_kernel_version(host, version);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+ printf("Mach kernel version:\n\t %s\n", version);
+ size = sizeof(hi)/sizeof(int);
+ ret = host_info(host, HOST_BASIC_INFO, (host_info_t)&hi, &size);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+
+ ret = processor_set_default(host, &default_pset);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+
+ count = PROCESSOR_SET_BASIC_INFO_COUNT;
+ ret = processor_set_info(default_pset, PROCESSOR_SET_BASIC_INFO,
+ &host, (processor_set_info_t)&basic_info, &count);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+
+ count = PROCESSOR_SET_LOAD_INFO_COUNT;
+ ret = processor_set_statistics(default_pset, PROCESSOR_SET_LOAD_INFO,
+ (processor_set_info_t)&load_info, &count);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+
+ unsigned int cpu_count = 0;
+ unsigned int data_count = 0;
+ struct processor_basic_info *processor_basic_infop = NULL;
+ ret = host_processor_info(host,
+ PROCESSOR_BASIC_INFO,
+ &cpu_count,
+ (processor_info_array_t *)&processor_basic_infop,
+ &data_count);
+ if (ret != KERN_SUCCESS) {
+ mach_error(argv[0], ret);
+ exit(EXIT_FAILURE);
+ }
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_MEMSIZE;
+ len = sizeof(memsize);
+ memsize = 0L;
+ if(sysctl(mib, 2, &memsize, &len, NULL, 0 ) == -1)
+ {
+ perror("sysctl");
+ exit(EXIT_FAILURE);
+ }
+
+ if (hi.max_cpus > 1)
+ printf("Kernel configured for up to %d processors.\n",
+ hi.max_cpus);
+ else
+ printf("Kernel configured for a single processor only.\n");
+ printf("%d processor%s physically available.\n", hi.physical_cpu,
+ (hi.physical_cpu > 1) ? "s are" : " is");
+
+ printf("%d processor%s logically available.\n", hi.logical_cpu,
+ (hi.logical_cpu > 1) ? "s are" : " is");
+
+ printf("Processor type:");
+ slot_name(hi.cpu_type, hi.cpu_subtype, &cpu_name, &cpu_subname);
+ printf(" %s (%s)\n", cpu_name, cpu_subname);
+
+ printf("Processor%s active:", (hi.avail_cpus > 1) ? "s" : "");
+ for (int i = 0; i < cpu_count; i++) {
+ if (processor_basic_infop[i].running) {
+ printf(" %d", i);
+ }
+ }
+ printf("\n");
+
+ if (((float)memsize / (1024.0 * 1024.0)) >= 1024.0)
+ printf("Primary memory available: %.2f gigabytes\n",
+ (float)memsize/(1024.0*1024.0*1024.0));
+ else
+ printf("Primary memory available: %.2f megabytes\n",
+ (float)memsize/(1024.0*1024.0));
+
+ printf("Default processor set: %d tasks, %d threads, %d processors\n",
+ load_info.task_count, load_info.thread_count, basic_info.processor_count);
+ printf("Load average: %d.%02d, Mach factor: %d.%02d\n",
+ load_info.load_average/LOAD_SCALE,
+ (load_info.load_average%LOAD_SCALE)/10,
+ load_info.mach_factor/LOAD_SCALE,
+ (load_info.mach_factor%LOAD_SCALE)/10);
+
+ exit(0);
+}