Skip to content

Commit 587c60a

Browse files
committed
Add verbose option
1 parent 4d97685 commit 587c60a

File tree

8 files changed

+545
-66
lines changed

8 files changed

+545
-66
lines changed

socpowerbuddy_swift.xcodeproj/xcuserdata/eomsehwan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 388 additions & 36 deletions
Large diffs are not rendered by default.

socpowerbuddy_swift.xcodeproj/xcuserdata/eomsehwan.xcuserdatad/xcschemes/socpowerbuddy_swift.xcscheme

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
argument = "-v"
6060
isEnabled = "NO">
6161
</CommandLineArgument>
62+
<CommandLineArgument
63+
argument = "--verbose"
64+
isEnabled = "YES">
65+
</CommandLineArgument>
6266
</CommandLineArguments>
6367
<AdditionalOptions>
6468
<AdditionalOption

socpowerbuddy_swift/head.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct iorep_data {
3333

3434
struct static_data {
3535
var gpu_core_count = 0
36+
var gpu_arch_name: String = ""
3637
var dvfm_states_holder: Array<Array<Double>> = []
3738
var dvfm_states: Array<Array<Double>> = []
3839
var cluster_core_counts: Array<UInt8> = []
@@ -49,6 +50,9 @@ struct static_data {
4950
var fan_mode = 0
5051
var fan_limit: [[Double]] = [[0, 0], [0, 0]]
5152
var os_ver: String = "macOS"
53+
var marketing_name: String = "mac"
54+
var os_code_name: String = ""
55+
var verbosed = false
5256
}
5357

5458
struct variating_data {

socpowerbuddy_swift/neoasitop.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ var sd = static_data()
1515
var cmd = cmd_data()
1616
let sens = SensorsReader()
1717

18-
let cur_ver = "v2.9"
18+
let cur_ver = "v2.10"
1919
var newVersion = false
20+
var beta = false
2021

2122
struct Neoasitop: ParsableCommand {
2223
@Flag(name: .shortAndLong, help: "Print version information")
2324
var version = false
2425

25-
@Option(name: .shortAndLong, help: "Display interval and sampling interval for info gathering (seconds)")
26+
@Flag(name: .long, help: "Show detail information of this system like OS codename, CPU architecture name, etc.")
27+
var verbose = false
28+
29+
@Option(name: .shortAndLong, help: "Display interval and sampling interval for info gathering (seconds) [0.01~]")
2630
var interval: Double = 1
2731

2832
@Option(name: .shortAndLong, help: "Choose display color (0~7)")
@@ -56,6 +60,8 @@ struct Neoasitop: ParsableCommand {
5660
while cmd.interval/1000 >= interval {
5761
cmd.interval /= 2
5862
}
63+
64+
sd.verbosed = verbose
5965

6066
let procInfo = ProcessInfo()
6167
let systemVersion = procInfo.operatingSystemVersion
@@ -65,6 +71,7 @@ struct Neoasitop: ParsableCommand {
6571
//print("dvfm table gen finish")
6672
generateProcessorName(sd: &sd)
6773
//print("process name gen finish")
74+
getOSCode(sd: &sd)
6875

6976
let tmp = sd.extra[0].lowercased()
7077
//tmp = "m1 ultra"
@@ -262,7 +269,7 @@ struct Neoasitop: ParsableCommand {
262269
}
263270
}
264271
del_tbox(tbx: &scr)
265-
print("\nGood Bye")
272+
print("\nGood Bye\(beta ? " Beta User!" : "")")
266273
return
267274
default:
268275
autoreleasepool {
@@ -298,6 +305,8 @@ enum Executable {
298305
if let version = object.value(forKey: "tag_name") as? String {
299306
if version.compare(cur_ver, options: .numeric) == .orderedDescending {
300307
newVersion = true
308+
} else if version.compare(cur_ver, options: .numeric) == .orderedAscending {
309+
beta = true
301310
}
302311
}
303312
}

socpowerbuddy_swift/render.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,9 @@ struct dispInfo {
130130
cpu_title += "[Rosetta 2] (cores: \(sd.core_ep_counts.reduce(0,+))C+"
131131
}
132132
cpu_title += "\(sd.gpu_core_count)GPU+\(sd.ram_capacity))"
133+
cpu_title = "\(sd.verbosed ? sd.marketing_name + " " : "")\(cpu_title)"
133134
}
134-
cpu_title += " \(sd.os_ver)"
135+
cpu_title += " \(sd.os_ver)\(sd.verbosed ? " " + sd.os_code_name : "")"
135136

136137
proc_grp = cpu_title
137138
}
@@ -473,9 +474,9 @@ func display(_ disp: dispInfo, _ gn: Bool = false, _ scrin: tbox? = nil, _ xy: [
473474

474475
var scrn = scrin ?? screen_init(dark: dark)
475476

476-
if lines < 34 || cols < 63 {
477+
if lines < 34 || cols < 63 + (sd.verbosed ? 22 : 0) {
477478
endwin()
478-
print("Terminal size is too small!\nThis tool needs 63 cols and 34 lines at least!")
479+
print("Terminal size is too small!\nThis tool needs \(sd.verbosed ? 85 : 63) cols and 34 lines at least!")
479480
exit(1)
480481
}
481482

socpowerbuddy_swift/sampler.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,11 +638,11 @@ func summary(sd: static_data, vd: variating_data, rd: inout render_data, rvd: in
638638
var space0 = 0 // 추가 내용 뺀 부분의 여분길이
639639
var space1 = 0
640640
// CPU & GPU 온도
641-
if w.ws_col >= 73 {
641+
if w.ws_col >= 73 + (sd.verbosed ? 17 : 0) {
642642
rvd.gpu_usg.title += String(
643643
format:" (%.1f°C)", rd.gpu.temp
644644
)
645-
if w.ws_col >= 80 {
645+
if w.ws_col >= 80 + (sd.verbosed ? 24 : 0) {
646646
rvd.ecpu_usg.title += String(
647647
format:" (%.1f°C)", rd.ecpu.temp
648648
)
@@ -651,6 +651,9 @@ func summary(sd: static_data, vd: variating_data, rd: inout render_data, rvd: in
651651
)
652652
}
653653
}
654+
rvd.ecpu_usg.title = "\(rvd.ecpu_usg.title)\(sd.verbosed ? " [\(sd.extra[2])]" : "")"
655+
rvd.pcpu_usg.title = "\(rvd.pcpu_usg.title)\(sd.verbosed ? " [\(sd.extra[3])]" : "")"
656+
rvd.gpu_usg.title = "\(rvd.gpu_usg.title)\(sd.verbosed ? " [\(sd.gpu_arch_name)]" : "")"
654657
// Memory Bandwidth
655658
space = 0
656659
var tmp_val = 200.0

socpowerbuddy_swift/static.swift

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,14 @@ func generateCoreCounts(sd: inout static_data) {
158158
}
159159
}
160160
}
161-
162-
if model_name != "" {
163-
if model_name.lowercased().contains("air") {
161+
162+
if let count = SMC.shared.getValue("FNum") {
163+
switch count {
164+
case 0.0:
164165
sd.fan_exist = false
165-
} else if model_name.lowercased().contains("mini") {
166+
case 1.0:
166167
sd.fan_mode = 1
167-
} else {
168+
default:
168169
sd.fan_mode = 2
169170
}
170171
} else {
@@ -179,27 +180,57 @@ func generateCoreCounts(sd: inout static_data) {
179180
port = kIOMasterPortDefault
180181
}
181182

182-
if let service = IOServiceMatching("AppleARMIODevice") {
183+
func regAccessFailed(_ name: String) {
184+
print("Failed to access \(name) service in IORegistry")
185+
exit(1)
186+
}
187+
188+
let option_bits = IOOptionBits(kIORegistryIterateRecursively + kIORegistryIterateParents)
189+
190+
var name = "product"
191+
if let service = IOServiceNameMatching(name) {
183192
if IOServiceGetMatchingServices(port, service, &iter) != kIOReturnSuccess {
184-
print("Failed to access AppleARMIODevice service in IORegistry")
193+
regAccessFailed(name)
194+
}
195+
} else {
196+
regAccessFailed(name)
197+
}
198+
199+
while case let entry = IOIteratorNext(iter), entry != IO_OBJECT_NULL {
200+
if let productname = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, "product-name" as CFString, kCFAllocatorDefault, option_bits) {
201+
sd.marketing_name = ""
202+
let prodname = productname.bytes?.assumingMemoryBound(to: CChar.self)
203+
for ii in 0...productname.length {
204+
sd.marketing_name += String(format: "%c", prodname![ii])
205+
}
206+
} else {
207+
print("Failed to read \"product-name\" from \(name) service in IORegistry")
185208
exit(1)
186209
}
210+
IOObjectRelease(entry)
211+
}
212+
213+
name = "AppleARMIODevice"
214+
if let service = IOServiceMatching(name) {
215+
if IOServiceGetMatchingServices(port, service, &iter) != kIOReturnSuccess {
216+
regAccessFailed(name)
217+
}
187218
} else {
188-
print("Failed to find AppleARMIODevice service in IORegistry")
189-
exit(1)
219+
regAccessFailed(name)
190220
}
191221

192222
while case let entry = IOIteratorNext(iter), entry != IO_OBJECT_NULL {
193223
if IORegistryEntryCreateCFProperties(entry, &servicedict, kCFAllocatorDefault, 0) != kIOReturnSuccess {
194-
print("Failed to create CFProperties for AppleARMIODevice service in IORegistry")
224+
print("Failed to create CFProperties for \(name) service in IORegistry")
195225
exit(1)
196226
}
197227

198228
guard let serviceDict = servicedict?.takeRetainedValue() as? [String : AnyObject] else { continue }
199229

200-
if case let data = serviceDict["clusters"], data != nil {
201-
let databytes = data?.bytes?.assumingMemoryBound(to: UInt8.self)
202-
for ii in stride(from:0, to:data!.length, by:4) {
230+
//if case let data = serviceDict["clusters"], data != nil {
231+
if let data = serviceDict["clusters"] {
232+
let databytes = data.bytes?.assumingMemoryBound(to: UInt8.self)
233+
for ii in stride(from:0, to:data.length, by:4) {
203234
let cores = UInt8(atoi(String(format: "%02x", databytes![ii])))
204235
sd.cluster_core_counts.append(cores)
205236
var die_num = 1
@@ -219,29 +250,57 @@ func generateCoreCounts(sd: inout static_data) {
219250
}
220251
}
221252

222-
if let service = IOServiceMatching("AGXAccelerator") {
253+
name = "AGXAccelerator"
254+
if let service = IOServiceMatching(name) {
223255
if IOServiceGetMatchingServices(port, service, &iter) != kIOReturnSuccess {
224-
print("Failed to access AGXAccelerator service in IORegistry")
225-
exit(1)
256+
regAccessFailed(name)
226257
}
227258
} else {
228-
print("Failed to find AGXAccelerator service in IORegistry")
229-
exit(1)
259+
regAccessFailed(name)
230260
}
231261

232262
while case let entry = IOIteratorNext(iter), entry != IO_OBJECT_NULL {
233-
if let gpucorecnt = IORegistryEntrySearchCFProperty(entry, kIOServicePlane, "gpu-core-count" as CFString, kCFAllocatorDefault, IOOptionBits(kIORegistryIterateRecursively + kIORegistryIterateParents)) {
263+
if IORegistryEntryCreateCFProperties(entry, &servicedict, kCFAllocatorDefault, 0) != kIOReturnSuccess {
264+
print("Failed to create CFProperties for \(name) service in IORegistry")
265+
exit(1)
266+
}
267+
268+
guard let serviceDict = servicedict?.takeRetainedValue() as? [String : AnyObject] else { continue }
269+
270+
if let gpucorecnt = serviceDict["gpu-core-count"] {
234271
sd.gpu_core_count = gpucorecnt as? Int ?? 0
235272
IOObjectRelease(entry)
236273
} else {
237-
print("Failed to read \"gpu-core-count\" from AGXAccelerator service in IORegistry")
274+
print("Failed to read \"gpu-core-count\" from \(name) service in IORegistry")
275+
exit(1)
276+
}
277+
278+
if let gpuname = serviceDict["IOClass"] {
279+
sd.gpu_arch_name = gpuname as? String ?? ""
280+
if let range = sd.gpu_arch_name.range(of: name) {
281+
sd.gpu_arch_name.removeSubrange(range)
282+
}
283+
} else {
284+
print("Failed to read \"gpu-arch-name\" from \(name) service in IORegistry")
238285
exit(1)
239286
}
287+
IOObjectRelease(entry)
240288
}
241289
IOObjectRelease(iter)
242290
}
243291
}
244292

293+
func getOSCode(sd: inout static_data) {
294+
autoreleasepool {
295+
let code_file = File("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf")
296+
while let code_line = code_file?.getLine() {
297+
if code_line.contains("SOFTWARE LICENSE AGREEMENT FOR macOS") {
298+
sd.os_code_name = String(code_line.split(separator: " ").last ?? "").replacingOccurrences(of: "\\\n", with: "")
299+
}
300+
}
301+
}
302+
}
303+
245304
func generateProcessorName(sd: inout static_data) {
246305
autoreleasepool {
247306
var size = 0
@@ -360,7 +419,7 @@ func generateMicroArchs(sd: inout static_data) {
360419
sd.extra.append(String(
361420
format: "%s",
362421
(data?.takeRetainedValue().bytes?.assumingMemoryBound(to: UInt8.self))!
363-
))
422+
).replacingOccurrences(of: "apple,", with: "").capitalized)
364423
} else {
365424
archError(sd: &sd)
366425
}
@@ -370,7 +429,7 @@ func generateMicroArchs(sd: inout static_data) {
370429
sd.extra.append(String(
371430
format: "%s",
372431
(data?.takeRetainedValue().bytes?.assumingMemoryBound(to: UInt8.self))!
373-
))
432+
).replacingOccurrences(of: "apple,", with: "").capitalized)
374433
} else {
375434
archError(sd: &sd)
376435
}

socpowerbuddy_swift/util.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,53 @@
77

88
import Foundation
99

10+
class File {
11+
init? (_ path: String) {
12+
errno = 0
13+
file = fopen(path, "r")
14+
if file == nil {
15+
perror(nil)
16+
return nil
17+
}
18+
}
19+
20+
deinit {
21+
fclose(file)
22+
}
23+
24+
func testIndex(line: String) -> Bool {
25+
guard line.lastIndex(of: "\r") == nil else {
26+
return false
27+
}
28+
guard line.lastIndex(of: "\n") == nil else {
29+
return false
30+
}
31+
guard line.lastIndex(of: "\r\n") == nil else {
32+
return false
33+
}
34+
return true
35+
}
36+
37+
func getLine() -> String? {
38+
var line = ""
39+
repeat {
40+
var buf = [CChar](repeating: 0, count: 1024)
41+
errno = 0
42+
if fgets(&buf, Int32(buf.count), file) == nil {
43+
if feof(file) != 0 {
44+
return nil
45+
} else {
46+
perror(nil)
47+
return nil
48+
}
49+
}
50+
line += String(cString: buf)
51+
} while testIndex(line: line)
52+
return line
53+
}
54+
private var file: UnsafeMutablePointer<FILE>? = nil
55+
}
56+
1057
func convertToGB(_ num: Double) -> [Double] {
1158
var res = [num, 0]
1259
while res[0] > 1024 {

0 commit comments

Comments
 (0)