https://github.com/daisuke-t-jp/mach-swift
The framework wrapped Mach functions in Swift.
https://github.com/daisuke-t-jp/mach-swift
cpu ios mach macos memory swift thread
Last synced: about 1 year ago
JSON representation
The framework wrapped Mach functions in Swift.
- Host: GitHub
- URL: https://github.com/daisuke-t-jp/mach-swift
- Owner: daisuke-t-jp
- License: mit
- Created: 2019-04-09T10:46:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-17T11:44:52.000Z (over 4 years ago)
- Last Synced: 2025-04-09T14:50:35.111Z (about 1 year ago)
- Topics: cpu, ios, mach, macos, memory, swift, thread
- Language: Swift
- Homepage: https://cocoapods.org/pods/Mach-Swift
- Size: 115 KB
- Stars: 17
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mach-Swift

[](https://developer.apple.com/swift)

[](https://cocoapods.org/pods/Mach-Swift)
[](https://github.com/Carthage/Carthage)
## Introduction
You can easily get information from [Mach](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html).
The framework wrapped Mach functions in Swift.
It provides the following information.
- Host
- Statistics
- [x] Virtual Memory Statistics / Wrapped [host_statistics(HOST_VM_INFO)](https://developer.apple.com/documentation/kernel/1502546-host_statistics?language=objc)
- [x] CPU Load Info / Wrapped [host_statistics(HOST_CPU_LOAD_INFO)](https://developer.apple.com/documentation/kernel/1502546-host_statistics?language=objc)
- Info
- [x] Basic Info / Wrapped [host_info(HOST_BASIC_INFO)](https://developer.apple.com/documentation/kernel/1502514-host_info?language=objc)
- Processor
- [x] CPU Load Info / Wrapped [host_processor_info()](https://developer.apple.com/documentation/kernel/1502854-host_processor_info?language=objc)
- Task
- Info
- [x] Basic Info / Wrapped [task_info()](https://developer.apple.com/documentation/kernel/1537934-task_info?language=objc)
- Thread
- [x] Basic Info / Wrapped [task_threads()](https://developer.apple.com/documentation/kernel/1537751-task_threads?language=objc), [thread_info()](https://developer.apple.com/documentation/kernel/1418630-thread_info?language=objc)
## Requirements
- Platforms
- iOS 10.0+
- macOS 10.12+
- Swift 5.0
## Installation
### Carthage
```
github "daisuke-t-jp/Mach-Swift"
```
### CocoaPods
```
use_frameworks!
target 'target' do
pod 'Mach-Swift'
end
```
## Usage
### Import framework
```swift
import Mach_Swift
```
### Getting Information
#### Code
```swift
do {
print("# Mach")
print("## Host")
print("### Statistics")
print("#### VMInfo")
let vm = Mach.Host.Statistics.vmInfo()
print("- freeSize: \(vm.freeSize)") // byte size of free
print("- activeSize: \(vm.activeSize)") // byte size of active
print("- inactiveSize: \(vm.inactiveSize)") // byte size of inactive
print("- wireSize: \(vm.wireSize)") // byte size of wire
print("")
print("#### CPULoadInfo")
let cpuLoadInfo = Mach.Host.Statistics.cpuLoadInfo()
print("- userTick: \(cpuLoadInfo.userTick)")
print("- systemTick: \(cpuLoadInfo.systemTick)")
print("- idleTick: \(cpuLoadInfo.idleTick)")
print("- niceTick: \(cpuLoadInfo.niceTick)")
print("")
print("### Info")
print("#### BasicInfo")
let basicInfo = Mach.Host.Info.basicInfo()
print("- maxCPUs: \(basicInfo.maxCPUs)")
print("- availCPUs: \(basicInfo.availCPUs)")
print("- memorySize: \(basicInfo.memorySize)") // byte size
print("- cpuType: \(basicInfo.cpuType)")
print("- cpuSubType: \(basicInfo.cpuSubType)")
print("- cpuThreadType: \(basicInfo.cpuThreadType)")
print("- physicalCPU: \(basicInfo.physicalCPU)")
print("- physicalCPUMax: \(basicInfo.physicalCPUMax)")
print("- logicalCPU: \(basicInfo.logicalCPU)")
print("- logicalCPUMax: \(basicInfo.logicalCPUMax)")
print("- maxMem: \(basicInfo.maxMem)") // byte size
print("")
print("### Processor")
print("#### CPULoadInfo")
let array = Mach.Host.Processor.cpuLoadInfoArray()
for i in 0..