An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          


# Mach-Swift
![Platform](https://img.shields.io/badge/Platform-iOS%20%7C%20macOS%20-blue.svg)
[![Language Swift%205.0](https://img.shields.io/badge/Language-Swift%205.0-orange.svg)](https://developer.apple.com/swift)
![Build Status](https://github.com/daisuke-t-jp/Mach-Swift/actions/workflows/ci.yml/badge.svg)
[![Cocoapods](https://img.shields.io/cocoapods/v/Mach-Swift.svg)](https://cocoapods.org/pods/Mach-Swift)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-green.svg)](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..