Baconian 1.1.0

Baconian 1.1.0

Daisuke T 维护。




Baconian 1.1.0

  • 作者
  • daisuke-t-jp

Baconian

Platform Language Swift%205.0 Build Status Cocoapods Carthage compatible

简介

Baconian 是 Swift 中的系统信息报告框架。
报告器(Reporter)提供以下信息。

  • OS 内存压力
  • OS CPU 负载
  • OS 处理器负载
  • App 内存压力
  • App CPU 负载
  • App 线程信息

您还可以通过视图(ReporterCompactView)图形化地查看负载。

视图的符号意义表。

符号 意义
🍎 OS 负载线
🍏 处理(App)负载线
🐏 内存使用🐏是 RAM (U+1F40F)
🤖 CPU 使用率(0 - 100%)

要求

  • 平台
    • iOS 10.0+
    • macOS 10.12+
  • Swift 5.0

安装

Carthage

github "daisuke-t-jp/Baconian"

CocoaPods

use_frameworks!

target 'target' do
pod 'Baconian'
end

使用方法

导入框架

import Baconian

报告类

1. 确认 ReporterDelegate 协议

class ViewController: ReporterDelegate {

2. 配置并启动报告器

let reporter = Reporter()
reporter.delegate = self
reporter.start()

3. 实现委托

func reporter(_ manager: Reporter, didUpdate data: Reporter.Data) {
    print("# Report")
  
    print("## OS")
    print("### Memory")
    print("- physicalSize: \(data.osMemory.physicalSize.memoryByteFormatString)")
    print("- freeSize: \(data.osMemory.freeSize.memoryByteFormatString)")
    print("- inactiveSize: \(data.osMemory.inactiveSize.memoryByteFormatString)")
    print("- wireSize: \(data.osMemory.wireSize.memoryByteFormatString)")
    print("- usedSize: \(data.osMemory.usedSize.memoryByteFormatString)")
    print("- unusedSize: \(data.osMemory.unusedSize.memoryByteFormatString)")
    print("")
  
  
    print("### CPU")
    print(String.init(format: "- userUsage: %.2f", data.osCPU.userUsage))
    print(String.init(format: "- systemUsage: %.2f", data.osCPU.systemUsage))
    print(String.init(format: "- idleUsage: %.2f", data.osCPU.idleUsage))
    print(String.init(format: "- niceUsage: %.2f", data.osCPU.niceUsage))
    print(String.init(format: "- usage: %.2f", data.osCPU.usage))
    print("")
  
  
    print("### Processors")
    for i in 0..<data.osProcessors.count {
        print("- Core No.\(i)")
        print(String.init(format: "    - userUsage: %.2f", data.osCPU.userUsage))
        print(String.init(format: "    - systemUsage: %.2f", data.osCPU.systemUsage))
        print(String.init(format: "    - idleUsage: %.2f", data.osCPU.idleUsage))
        print(String.init(format: "    - niceUsage: %.2f", data.osCPU.niceUsage))
        print(String.init(format: "    - usage: %.2f", data.osCPU.usage))
        print("")
    }
  
  
    print("## Process")
    print("### Memory")
    print("- residentSize: \(data.processMemory.residentSize.memoryByteFormatString)")
    print("")
  
    print("### CPU")
    print(String.init(format: "- usage: %.2f", data.processCPU.usage))
    print(String.init(format: "- time: %.2f", data.processCPU.time))
    print("")
  
    print("### Thread")
    print("- totalNum: \(data.processThread.totalNum)")
    print("- busyNum: \(data.processThread.busyNum)")
    print("- idleNum: \(data.processThread.idleNum)")
    print("")
}

4. 停止报告器

reporter.stop()

ReporterCompactView类

通过编程方式添加ReporterCompactView

let reporterView = ReporterCompactView(frame: CrossPlatformRect(x: 0, 
                                                                y: 0, 
                                                            width: ReporterCompactView.xibWidth,
                                                            height: ReporterCompactView.xibHeight))

self.view.addSubview(reporterView)

通过Interface Builder添加ReporterCompactView

1. 设置UIView的自定义类为ReporterCompactView

2. 设置ReporterCompactView边框

宽度为260,高度为50。

示例

有示例。