{"id":18795089,"url":"https://github.com/daisuke-t-jp/mach-swift","last_synced_at":"2025-04-13T15:34:10.071Z","repository":{"id":45367920,"uuid":"180345516","full_name":"daisuke-t-jp/Mach-Swift","owner":"daisuke-t-jp","description":"The framework wrapped Mach functions in Swift.","archived":false,"fork":false,"pushed_at":"2021-12-17T11:44:52.000Z","size":118,"stargazers_count":17,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-09T14:50:35.111Z","etag":null,"topics":["cpu","ios","mach","macos","memory","swift","thread"],"latest_commit_sha":null,"homepage":"https://cocoapods.org/pods/Mach-Swift","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daisuke-t-jp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-09T10:46:19.000Z","updated_at":"2023-09-28T07:21:38.000Z","dependencies_parsed_at":"2022-08-04T14:15:10.127Z","dependency_job_id":null,"html_url":"https://github.com/daisuke-t-jp/Mach-Swift","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daisuke-t-jp%2FMach-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daisuke-t-jp%2FMach-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daisuke-t-jp%2FMach-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daisuke-t-jp%2FMach-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daisuke-t-jp","download_url":"https://codeload.github.com/daisuke-t-jp/Mach-Swift/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248736527,"owners_count":21153607,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpu","ios","mach","macos","memory","swift","thread"],"created_at":"2024-11-07T21:32:33.049Z","updated_at":"2025-04-13T15:34:09.475Z","avatar_url":"https://github.com/daisuke-t-jp.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://raw.githubusercontent.com/daisuke-t-jp/Mach-Swift/master/images/Mach-Swift.png\" width=\"300\"\u003e\u003c/br\u003e\n# Mach-Swift\n![Platform](https://img.shields.io/badge/Platform-iOS%20%7C%20macOS%20-blue.svg)\n[![Language Swift%205.0](https://img.shields.io/badge/Language-Swift%205.0-orange.svg)](https://developer.apple.com/swift)\n![Build Status](https://github.com/daisuke-t-jp/Mach-Swift/actions/workflows/ci.yml/badge.svg)\n[![Cocoapods](https://img.shields.io/cocoapods/v/Mach-Swift.svg)](https://cocoapods.org/pods/Mach-Swift)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-green.svg)](https://github.com/Carthage/Carthage)\n\n\n## Introduction\n\nYou can easily get information from [Mach](https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/KernelProgramming/Mach/Mach.html).  \n  \nThe framework wrapped Mach functions in Swift.  \nIt provides the following information.  \n\n- Host\n    - Statistics\n        - [x] Virtual Memory Statistics / Wrapped [host_statistics(HOST_VM_INFO)](https://developer.apple.com/documentation/kernel/1502546-host_statistics?language=objc)\n        - [x] CPU Load Info / Wrapped [host_statistics(HOST_CPU_LOAD_INFO)](https://developer.apple.com/documentation/kernel/1502546-host_statistics?language=objc)\n    - Info\n        - [x] Basic Info / Wrapped [host_info(HOST_BASIC_INFO)](https://developer.apple.com/documentation/kernel/1502514-host_info?language=objc)\n    - Processor\n        - [x] CPU Load Info / Wrapped [host_processor_info()](https://developer.apple.com/documentation/kernel/1502854-host_processor_info?language=objc)\n- Task\n    - Info\n        - [x] Basic Info / Wrapped [task_info()](https://developer.apple.com/documentation/kernel/1537934-task_info?language=objc)\n    - Thread\n        - [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)\n\n## Requirements\n- Platforms\n  - iOS 10.0+\n  - macOS 10.12+\n- Swift 5.0\n\n\n## Installation\n### Carthage\n```\ngithub \"daisuke-t-jp/Mach-Swift\"\n```\n\n### CocoaPods\n```\nuse_frameworks!\n\ntarget 'target' do\npod 'Mach-Swift'\nend\n```\n\n\n## Usage\n### Import framework\n```swift\nimport Mach_Swift\n```\n\n### Getting Information\n#### Code\n```swift\ndo {\n    print(\"# Mach\")\n    \n    print(\"## Host\")\n    print(\"### Statistics\")\n    print(\"#### VMInfo\")\n    let vm = Mach.Host.Statistics.vmInfo()\n    print(\"- freeSize: \\(vm.freeSize)\")  // byte size of free\n    print(\"- activeSize: \\(vm.activeSize)\")  // byte size of active\n    print(\"- inactiveSize: \\(vm.inactiveSize)\")  // byte size of inactive\n    print(\"- wireSize: \\(vm.wireSize)\")  // byte size of wire\n    print(\"\")\n\n    print(\"#### CPULoadInfo\")\n    let cpuLoadInfo = Mach.Host.Statistics.cpuLoadInfo()\n    print(\"- userTick: \\(cpuLoadInfo.userTick)\")\n    print(\"- systemTick: \\(cpuLoadInfo.systemTick)\")\n    print(\"- idleTick: \\(cpuLoadInfo.idleTick)\")\n    print(\"- niceTick: \\(cpuLoadInfo.niceTick)\")\n    print(\"\")\n    \n    print(\"### Info\")\n    print(\"#### BasicInfo\")\n    let basicInfo = Mach.Host.Info.basicInfo()\n    print(\"- maxCPUs: \\(basicInfo.maxCPUs)\")\n    print(\"- availCPUs: \\(basicInfo.availCPUs)\")\n    print(\"- memorySize: \\(basicInfo.memorySize)\")  // byte size\n    print(\"- cpuType: \\(basicInfo.cpuType)\")\n    print(\"- cpuSubType: \\(basicInfo.cpuSubType)\")\n    print(\"- cpuThreadType: \\(basicInfo.cpuThreadType)\")\n    print(\"- physicalCPU: \\(basicInfo.physicalCPU)\")\n    print(\"- physicalCPUMax: \\(basicInfo.physicalCPUMax)\")\n    print(\"- logicalCPU: \\(basicInfo.logicalCPU)\")\n    print(\"- logicalCPUMax: \\(basicInfo.logicalCPUMax)\")\n    print(\"- maxMem: \\(basicInfo.maxMem)\")  // byte size\n    print(\"\")\n  \n    print(\"### Processor\")\n    print(\"#### CPULoadInfo\")\n    let array = Mach.Host.Processor.cpuLoadInfoArray()\n    for i in 0..\u003carray.count {\n        let cpu = array[i]\n        print(\"- Core No.\\(i)\")\n        print(\"    - userTick: \\(cpu.userTick)\")\n        print(\"    - systemTick: \\(cpu.systemTick)\")\n        print(\"    - idleTick: \\(cpu.idleTick)\")\n        print(\"    - niceTick: \\(cpu.niceTick)\")\n        print(\"\")\n    }\n}\n\nprint(\"\")\n\n\ndo {\n    print(\"## Task\")\n    print(\"### Info\")\n    print(\"#### BasicInfo\")\n    let basicInfo = Mach.Task.Info.basicInfo()\n    print(\"- virtualSize: \\(basicInfo.virtualSize)\")\n    print(\"- residentSize: \\(basicInfo.residentSize)\")\n    print(\"- residentSizeMax: \\(basicInfo.residentSizeMax)\")\n    print(\"- userTime: \\(basicInfo.userTime)\")\n    print(\"- systemTime: \\(basicInfo.systemTime)\")\n    print(\"- policy: \\(basicInfo.policy)\")\n    print(\"- suspendCount: \\(basicInfo.suspendCount)\")\n    print(\"\")\n  \n    print(\"#### ThreadBasicInfo\")\n    let array = Mach.Task.Thread.basicInfoArray()\n    for i in 0..\u003carray.count {\n        let thread = array[i]\n        print(\"- Thread No.\\(i)\")\n        print(String.init(format:\"    - userTime: %.2f\", thread.userTime))\n        print(String.init(format:\"    - systemTime: %.2f\", thread.systemTime))\n        print(\"    - cpuUsage: \\(thread.cpuUsage)\")\n        print(\"    - policy: \\(thread.policy)\")\n        print(\"    - runState: \\(thread.runState)\")\n        print(\"    - flags: \\(thread.flags)\")\n        print(\"    - suspendCount: \\(thread.suspendCount)\")\n        print(\"    - sleepTime: \\(thread.sleepTime)\")\n        print(String.init(format:\"    - sleepTime: %.2f\", thread.sleepTime))\n        print(\"\")\n    }\n}\n```\n\n#### Outout\n```\n# Mach\n## Host\n### Statistics\n#### VMInfo\n- freeSize: 130482176\n- activeSize: 1765789696\n- inactiveSize: 1649594368\n- wireSize: 2495418368\n\n#### CPULoadInfo\n- userTick: 785470\n- systemTick: 503253\n- idleTick: 4632473\n- niceTick: 0\n\n### Info\n#### BasicInfo\n- maxCPUs: 4\n- availCPUs: 4\n- memorySize: 2147483648\n- cpuType: 7\n- cpuSubType: 8\n- cpuThreadType: 1\n- physicalCPU: 2\n- physicalCPUMax: 2\n- logicalCPU: 4\n- logicalCPUMax: 4\n- maxMem: 8589934592\n\n### Processor\n#### CPULoadInfo\n- Core No.0\n    - userTick: 257206\n    - systemTick: 186605\n    - idleTick: 1036690\n    - niceTick: 0\n\n- Core No.1\n    - userTick: 144763\n    - systemTick: 87848\n    - idleTick: 1247622\n    - niceTick: 0\n\n- Core No.2\n    - userTick: 251769\n    - systemTick: 155100\n    - idleTick: 1073364\n    - niceTick: 0\n\n- Core No.3\n    - userTick: 131732\n    - systemTick: 73700\n    - idleTick: 1274800\n    - niceTick: 0\n\n\n## Task\n### Info\n#### BasicInfo\n- virtualSize: 5425922048\n- residentSize: 78155776\n- residentSizeMax: 78155776\n- userTime: 0.000426\n- systemTime: 0.003031\n- policy: 1\n- suspendCount: 0\n\n#### ThreadBasicInfo\n- Thread No.0\n    - userTime: 0.24\n    - systemTime: 0.93\n    - cpuUsage: 626\n    - policy: 1\n    - runState: 1\n    - flags: Flag(rawValue: 0)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n- Thread No.1\n    - userTime: 0.01\n    - systemTime: 0.01\n    - cpuUsage: 23\n    - policy: 1\n    - runState: 3\n    - flags: Flag(rawValue: 1)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n- Thread No.2\n    - userTime: 0.00\n    - systemTime: 0.00\n    - cpuUsage: 6\n    - policy: 1\n    - runState: 3\n    - flags: Flag(rawValue: 1)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n- Thread No.3\n    - userTime: 0.00\n    - systemTime: 0.00\n    - cpuUsage: 0\n    - policy: 1\n    - runState: 3\n    - flags: Flag(rawValue: 1)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n- Thread No.4\n    - userTime: 0.00\n    - systemTime: 0.00\n    - cpuUsage: 4\n    - policy: 1\n    - runState: 3\n    - flags: Flag(rawValue: 1)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n- Thread No.5\n    - userTime: 0.00\n    - systemTime: 0.01\n    - cpuUsage: 12\n    - policy: 1\n    - runState: 3\n    - flags: Flag(rawValue: 1)\n    - suspendCount: 0\n    - sleepTime: 0.0\n    - sleepTime: 0.00\n\n```\n\n\n## Demo\nThere are demos.\n- [iOS](https://github.com/daisuke-t-jp/Mach-Swift/tree/master/demo/Mach-SwiftDemo-iOS) \n- [macOS](https://github.com/daisuke-t-jp/Mach-Swift/tree/master/demo/Mach-SwiftDemo-macOS) \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaisuke-t-jp%2Fmach-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaisuke-t-jp%2Fmach-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaisuke-t-jp%2Fmach-swift/lists"}