-
Notifications
You must be signed in to change notification settings - Fork 65
/
main.swift
107 lines (86 loc) · 4.02 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// main.swift
// SystemKit
//
// The MIT License
//
// Copyright (C) 2014-2017 beltex <https://github.com/beltex>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import SystemKit
print("// MACHINE STATUS")
print("\n-- CPU --")
print("\tPHYSICAL CORES: \(System.physicalCores())")
print("\tLOGICAL CORES: \(System.logicalCores())")
var sys = System()
let cpuUsage = sys.usageCPU()
print("\tSYSTEM: \(Int(cpuUsage.system))%")
print("\tUSER: \(Int(cpuUsage.user))%")
print("\tIDLE: \(Int(cpuUsage.idle))%")
print("\tNICE: \(Int(cpuUsage.nice))%")
print("\n-- MEMORY --")
print("\tPHYSICAL SIZE: \(System.physicalMemory())GB")
let memoryUsage = System.memoryUsage()
func memoryUnit(_ value: Double) -> String {
if value < 1.0 { return String(Int(value * 1000.0)) + "MB" }
else { return NSString(format:"%.2f", value) as String + "GB" }
}
print("\tFREE: \(memoryUnit(memoryUsage.free))")
print("\tWIRED: \(memoryUnit(memoryUsage.wired))")
print("\tACTIVE: \(memoryUnit(memoryUsage.active))")
print("\tINACTIVE: \(memoryUnit(memoryUsage.inactive))")
print("\tCOMPRESSED: \(memoryUnit(memoryUsage.compressed))")
print("\n-- SYSTEM --")
print("\tMODEL: \(System.modelName())")
//let names = System.uname()
//print("\tSYSNAME: \(names.sysname)")
//print("\tNODENAME: \(names.nodename)")
//print("\tRELEASE: \(names.release)")
//print("\tVERSION: \(names.version)")
//print("\tMACHINE: \(names.machine)")
let uptime = System.uptime()
print("\tUPTIME: \(uptime.days)d \(uptime.hrs)h \(uptime.mins)m " +
"\(uptime.secs)s")
let counts = System.processCounts()
print("\tPROCESSES: \(counts.processCount)")
print("\tTHREADS: \(counts.threadCount)")
let loadAverage = System.loadAverage().map { NSString(format:"%.2f", $0) }
print("\tLOAD AVERAGE: \(loadAverage)")
print("\tMACH FACTOR: \(System.machFactor())")
print("\n-- POWER --")
let cpuThermalStatus = System.CPUPowerLimit()
print("\tCPU SPEED LIMIT: \(cpuThermalStatus.processorSpeed)%")
print("\tCPUs AVAILABLE: \(cpuThermalStatus.processorCount)")
print("\tSCHEDULER LIMIT: \(cpuThermalStatus.schedulerTime)%")
print("\tTHERMAL LEVEL: \(System.thermalLevel().rawValue)")
var battery = Battery()
if battery.open() != kIOReturnSuccess { exit(0) }
print("\n-- BATTERY --")
print("\tAC POWERED: \(battery.isACPowered())")
print("\tCHARGED: \(battery.isCharged())")
print("\tCHARGING: \(battery.isCharging())")
print("\tCHARGE: \(battery.charge())%")
print("\tCAPACITY: \(battery.currentCapacity()) mAh")
print("\tMAX CAPACITY: \(battery.maxCapactiy()) mAh")
print("\tDESGIN CAPACITY: \(battery.designCapacity()) mAh")
print("\tCYCLES: \(battery.cycleCount())")
print("\tMAX CYCLES: \(battery.designCycleCount())")
print("\tTEMPERATURE: \(battery.temperature())°C")
print("\tTIME REMAINING: \(battery.timeRemainingFormatted())")
_ = battery.close()