Skip to content

Commit 85fedae

Browse files
committed
Refactoring and fix rendering bug
1 parent c4ace28 commit 85fedae

File tree

16 files changed

+666
-849
lines changed

16 files changed

+666
-849
lines changed

IOReportDump/main.swift

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,48 +25,76 @@ extension kIORep {
2525
}
2626
}
2727

28+
var cpu = ""
29+
var size = 0
30+
let getcpu = "machdep.cpu.brand_string"
31+
sysctlbyname(getcpu, nil, &size, nil, 0)
32+
var cpubrand = [CChar](repeating: 0, count: size)
33+
sysctlbyname(getcpu, &cpubrand, &size, nil, 0)
34+
var clusters = 2
35+
36+
if strcmp(cpubrand, "") != 0 {
37+
cpubrand.withUnsafeBufferPointer {
38+
ptr in cpu += String(cString: ptr.baseAddress!)
39+
}
40+
}
41+
cpu = cpu.lowercased()
42+
43+
if cpu.contains("pro") || cpu.contains("max") {
44+
clusters = 3
45+
} else if cpu.contains("ultra") {
46+
clusters = 6
47+
}
48+
2849
var subchn: Unmanaged<CFMutableDictionary>? = nil
2950
var chn = IOReportCopyAllChannels(0, 0)
3051
var sub = IOReportCreateSubscription(nil, chn?.takeRetainedValue(), &subchn, 0, nil)
3152

3253
let interval: Double = 175
3354

34-
var samples_a = IOReportCreateSamples(sub, subchn?.takeUnretainedValue(), nil).takeRetainedValue()
55+
var samples_a = IOReportCreateSamples(sub, subchn?.takeUnretainedValue(), nil)
3556

3657
Thread.sleep(forTimeInterval: interval*1e-3)
3758

38-
var samples_b = IOReportCreateSamples(sub, subchn?.takeUnretainedValue(), nil).takeRetainedValue()
59+
var samples_b = IOReportCreateSamples(sub, subchn?.takeUnretainedValue(), nil)
3960

40-
let samp_delta = Array((IOReportCreateSamplesDelta(
41-
samples_a, samples_b, nil
42-
).takeRetainedValue() as Dictionary).values)[0] as! Array<CFDictionary>
61+
let samp_delta = IOReportCreateSamplesDelta(samples_a?.takeUnretainedValue(), samples_b?.takeUnretainedValue(), nil)
4362

44-
for sample in samp_delta {
45-
let group = IOReportChannelGetGroup(sample)
46-
var subgroup = IOReportChannelGetSubGroup(sample)
47-
let chann_name = IOReportChannelGetChannelName(sample)
48-
let names = ["CPU Stats", "GPU Stats", "AMC Stats", "CLPC Stats", "PMP", "Energy Model"]
49-
if names.contains(group!) {
50-
switch IOReportChannelGetFormat(sample) {
51-
case kIORep.kIOReportFormatSimple.rawValue:
52-
if subgroup == nil {
53-
subgroup = ""
54-
}
55-
print("Grp: \(group!) Subgrp: \(subgroup!) Chn: \(chann_name!) "+String(format: "Value: %ld\n", IOReportSimpleGetIntegerValue(sample, 0)))
56-
break
57-
case kIORep.kIOReportFormatState.rawValue:
58-
for i in 0..<IOReportStateGetCount(sample) {
59-
let tmp = IOReportStateGetResidency(sample, i)
60-
print("Grp: \(group!) Subgrp: \(subgroup!) Chn: \(chann_name!) "+String(format: "State: \(IOReportStateGetNameForIndex(sample, i)!) Res: %lld\n", tmp))
61-
}
62-
break
63-
case kIORep.kIOReportFormatSimpleArray.rawValue:
64-
for i in stride(from: 2, to: -1, by: -1) {
65-
print("Grp: \(group!) Subgrp: \(subgroup!) Chn: \(chann_name!) "+String(format: "Arr: %llu\n", IOReportArrayGetValueAtIndex(sample, Int32(2-i))))
63+
samples_a?.release()
64+
samples_b?.release()
65+
66+
let names = ["CPU Stats", "GPU Stats", "AMC Stats", "CLPC Stats", "PMP", "Energy Model"]
67+
IOReportIterate(samp_delta?.takeUnretainedValue(), { sample in
68+
autoreleasepool {
69+
var group = IOReportChannelGetGroup(sample)
70+
var subgroup = IOReportChannelGetSubGroup(sample)
71+
var chann_name = IOReportChannelGetChannelName(sample)
72+
if names.contains(group!) {
73+
switch IOReportChannelGetFormat(sample) {
74+
case kIORep.kIOReportFormatSimple.rawValue:
75+
var tmp: Int? = IOReportSimpleGetIntegerValue(sample, 0)
76+
print("Grp: \(group!) Subgrp: \(subgroup ?? "") Chn: \(chann_name!) "+String(format: "Value: %ld\n", tmp!))
77+
tmp = nil
78+
case kIORep.kIOReportFormatState.rawValue:
79+
for i in 0..<IOReportStateGetCount(sample) {
80+
var tmp: UInt64? = IOReportStateGetResidency(sample, i)
81+
var idx = IOReportStateGetNameForIndex(sample, i)
82+
print("Grp: \(group!) Subgrp: \(subgroup!) Chn: \(chann_name!) "+String(format: "State: \(idx!) Res: %lld\n", tmp!))
83+
tmp = nil
84+
idx = nil
85+
}
86+
case kIORep.kIOReportFormatSimpleArray.rawValue:
87+
for i in 0..<clusters {
88+
var idx: UInt64? = IOReportArrayGetValueAtIndex(sample, Int32(2-i))
89+
print("Grp: \(group!) Subgrp: \(subgroup!) Chn: \(chann_name!) "+String(format: "Arr: %llu\n", idx!))
90+
idx = nil
91+
}
92+
default: break
6693
}
67-
break
68-
default:break
6994
}
95+
group = nil
96+
subgroup = nil
97+
chann_name = nil
7098
}
71-
}
72-
99+
return Int32(kIOReportIterOk)
100+
})

socpowerbuddy_swift.xcodeproj/project.pbxproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 56;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -26,6 +26,7 @@
2626
3A8A035528E3F0800027B16E /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A8A035428E3F0800027B16E /* main.swift */; };
2727
3A8A035A28E3F6EE0027B16E /* libIOReport.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF36E0B28D21A4C00DA3EB3 /* libIOReport.tbd */; };
2828
3A9A723328D15F5C0021E6F1 /* static.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A9A723228D15F5C0021E6F1 /* static.swift */; };
29+
3AC974B5298184EF00DA67A8 /* readers.m in Sources */ = {isa = PBXBuildFile; fileRef = 3AC974B4298184EF00DA67A8 /* readers.m */; };
2930
3AC9F1EA28F02E7B008C5D5C /* libncurses.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AC9F1E928F02E6F008C5D5C /* libncurses.tbd */; };
3031
3AECE96B297AEB4000D45A12 /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 3AECE96A297AEB4000D45A12 /* Alamofire */; };
3132
3AECE971297AFCF500D45A12 /* neoasitop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AECE970297AFCF500D45A12 /* neoasitop.swift */; };
@@ -75,6 +76,7 @@
7576
3A8A035428E3F0800027B16E /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
7677
3A9A722828D15EBB0021E6F1 /* socpowerbuddy_swift */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = socpowerbuddy_swift; sourceTree = BUILT_PRODUCTS_DIR; };
7778
3A9A723228D15F5C0021E6F1 /* static.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = static.swift; sourceTree = "<group>"; };
79+
3AC974B4298184EF00DA67A8 /* readers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = readers.m; sourceTree = "<group>"; };
7880
3AC9F1E928F02E6F008C5D5C /* libncurses.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libncurses.tbd; path = usr/lib/libncurses.tbd; sourceTree = SDKROOT; };
7981
3AECE970297AFCF500D45A12 /* neoasitop.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = neoasitop.swift; sourceTree = "<group>"; };
8082
3AF36E0728D216A800DA3EB3 /* socpwrbud.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = socpwrbud.h; sourceTree = "<group>"; };
@@ -157,6 +159,7 @@
157159
3A238F0028D5CCEF0033A580 /* Repeater.swift */,
158160
3A3DA87D28DC91C000BFEFAC /* render.swift */,
159161
3A3DA88528DEDC5B00BFEFAC /* util.swift */,
162+
3AC974B4298184EF00DA67A8 /* readers.m */,
160163
);
161164
path = socpowerbuddy_swift;
162165
sourceTree = "<group>";
@@ -230,7 +233,7 @@
230233
};
231234
};
232235
buildConfigurationList = 3A9A722328D15EBB0021E6F1 /* Build configuration list for PBXProject "socpowerbuddy_swift" */;
233-
compatibilityVersion = "Xcode 14.0";
236+
compatibilityVersion = "Xcode 12.0";
234237
developmentRegion = en;
235238
hasScannedForEncodings = 0;
236239
knownRegions = (
@@ -272,6 +275,7 @@
272275
3A3DA88628DEDC5B00BFEFAC /* util.swift in Sources */,
273276
3A238EEB28D5BFC10033A580 /* helper.swift in Sources */,
274277
3A238EF528D5C6710033A580 /* readers.swift in Sources */,
278+
3AC974B5298184EF00DA67A8 /* readers.m in Sources */,
275279
3A3DA87E28DC91C000BFEFAC /* render.swift in Sources */,
276280
3A238EF328D5C64D0033A580 /* smc.swift in Sources */,
277281
3A238EEF28D5C1F20033A580 /* Types.swift in Sources */,

0 commit comments

Comments
 (0)