Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d24fa7de35 | ||
|
|
6a02d9993d | ||
|
|
f2dc6bc7fb | ||
|
|
d8e469ec9e | ||
|
|
91d50dcbae | ||
|
|
36c7ea2319 | ||
|
|
fda8bf9e49 | ||
|
|
feceb2412d | ||
|
|
f9093b1d99 | ||
|
|
a14f0b925e | ||
|
|
b47ffd72ca | ||
|
|
c2fa0c05ed | ||
|
|
67bfa9f681 | ||
|
|
4973a67ca9 | ||
|
|
3e8852258a | ||
|
|
b37cfb06a9 | ||
|
|
cb625964a5 | ||
|
|
5517e92eff | ||
|
|
f03477181b |
@@ -7,16 +7,30 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
0A7117B3B7CC7112F2527574 /* MMPowerTelemetryProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 02F5FDE260999C39E978D849 /* MMPowerTelemetryProvider.m */; };
|
||||||
|
160334CC765E091A7CBE21AA /* MMCPULoadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CE92B1A8D7FDBB6499448E1 /* MMCPULoadTests.swift */; };
|
||||||
1879A3DCF6E305D7F2CD472E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2345555FF9780B02A90CC7A9 /* CoreFoundation.framework */; };
|
1879A3DCF6E305D7F2CD472E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2345555FF9780B02A90CC7A9 /* CoreFoundation.framework */; };
|
||||||
|
1B15F48F6B19E9EA4556ECD5 /* MMStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78325870C7CD8312AECA2236 /* MMStorageTests.swift */; };
|
||||||
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 375AA781A2AA0A20B119C7B7 /* MMSMCParser.m */; };
|
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 375AA781A2AA0A20B119C7B7 /* MMSMCParser.m */; };
|
||||||
3C0AC14F803C813287D8A663 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007F48A5A599AB4E8D216D16 /* IOKit.framework */; };
|
3C0AC14F803C813287D8A663 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007F48A5A599AB4E8D216D16 /* IOKit.framework */; };
|
||||||
|
4419FE7554489B23976E2970 /* MMCPULoadProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = D68FC8100D08DB6202F46339 /* MMCPULoadProvider.m */; };
|
||||||
|
57BA02AE1CE24DBD02BD03A4 /* MMComponentThermalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B288C7402E2C00E75F8CD016 /* MMComponentThermalTests.swift */; };
|
||||||
|
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */; };
|
||||||
|
655366D7066478A02EDA91BB /* MMFanTelemetryProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = C9ED8F75E082D4F8AC2FF2F5 /* MMFanTelemetryProvider.m */; };
|
||||||
|
87818E46CEA5145A8215D0E3 /* MMCPUThermalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0F2BD3777A674DC4EB442890 /* MMCPUThermalTests.swift */; };
|
||||||
|
87A9E18362486D0D385BBC4A /* MMCPUThermalProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 62C377EFD025D6A6B5563E77 /* MMCPUThermalProvider.m */; };
|
||||||
88387CDAE2AC1CC74EF89B57 /* MacMonitorApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADEA6BD38BA8D887B1DB64A9 /* MacMonitorApp.swift */; };
|
88387CDAE2AC1CC74EF89B57 /* MacMonitorApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ADEA6BD38BA8D887B1DB64A9 /* MacMonitorApp.swift */; };
|
||||||
|
925245C5B5F8D8DA3C89C4BA /* MMComponentThermalProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = C65F5835516BC2A65BCE25D2 /* MMComponentThermalProvider.m */; };
|
||||||
|
9B5C651AD2AF7DE2738F0C44 /* MMPowerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D48698681374BD25B980C000 /* MMPowerTests.swift */; };
|
||||||
9BCE74C5454F81EF80492E75 /* MacMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */; };
|
9BCE74C5454F81EF80492E75 /* MacMonitorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */; };
|
||||||
A7609CE56D49EC3419987468 /* SystemTelemetryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B4E94FB2886C60D5548A2A /* SystemTelemetryStore.swift */; };
|
A7609CE56D49EC3419987468 /* SystemTelemetryStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B4E94FB2886C60D5548A2A /* SystemTelemetryStore.swift */; };
|
||||||
A9FCAEC0BF27A419DB148C4A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E142AE61F9B87757997870DD /* ContentView.swift */; };
|
A9FCAEC0BF27A419DB148C4A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E142AE61F9B87757997870DD /* ContentView.swift */; };
|
||||||
|
B9C2D6574E808B517BA34C83 /* MMMemoryTelemetryProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 991AEEAF262F3C6BE930BC77 /* MMMemoryTelemetryProvider.m */; };
|
||||||
CD91FC663B19DA1FEA3D49D7 /* MMAppleSMCClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 5555436CD3CB8A73F5D6504F /* MMAppleSMCClient.m */; };
|
CD91FC663B19DA1FEA3D49D7 /* MMAppleSMCClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 5555436CD3CB8A73F5D6504F /* MMAppleSMCClient.m */; };
|
||||||
|
E6F2F695B8D3E7045967C082 /* MMFanTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 336CEE35A745F3C7E9F70F43 /* MMFanTests.swift */; };
|
||||||
EAFAF5A10502D4ACC64F4720 /* MMTelemetryCoordinator.m in Sources */ = {isa = PBXBuildFile; fileRef = F9F9AD1268F906761032AF4D /* MMTelemetryCoordinator.m */; };
|
EAFAF5A10502D4ACC64F4720 /* MMTelemetryCoordinator.m in Sources */ = {isa = PBXBuildFile; fileRef = F9F9AD1268F906761032AF4D /* MMTelemetryCoordinator.m */; };
|
||||||
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940D608A1AF80F75584E744E /* MMSMCTests.swift */; };
|
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 940D608A1AF80F75584E744E /* MMSMCTests.swift */; };
|
||||||
|
F2F7A141F2452EC1B4FB45D8 /* MMStorageTelemetryProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6DCBCEA450103E2404761B78 /* MMStorageTelemetryProvider.m */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXContainerItemProxy section */
|
/* Begin PBXContainerItemProxy section */
|
||||||
@@ -31,19 +45,40 @@
|
|||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
007F48A5A599AB4E8D216D16 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
|
007F48A5A599AB4E8D216D16 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
|
||||||
|
0130BD1E18972DF9E2955334 /* MMMemoryTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMMemoryTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
|
02F5FDE260999C39E978D849 /* MMPowerTelemetryProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMPowerTelemetryProvider.m; sourceTree = "<group>"; };
|
||||||
|
09475741B5D0D4B89B863C3D /* MMComponentThermalProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMComponentThermalProvider.h; sourceTree = "<group>"; };
|
||||||
|
099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMMemoryTests.swift; sourceTree = "<group>"; };
|
||||||
|
0F2BD3777A674DC4EB442890 /* MMCPUThermalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMCPUThermalTests.swift; sourceTree = "<group>"; };
|
||||||
1AD9EEE571CD904BBCD1C96B /* MMSMCParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMSMCParser.h; sourceTree = "<group>"; };
|
1AD9EEE571CD904BBCD1C96B /* MMSMCParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMSMCParser.h; sourceTree = "<group>"; };
|
||||||
2345555FF9780B02A90CC7A9 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
2345555FF9780B02A90CC7A9 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
|
||||||
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacMonitorTests.swift; sourceTree = "<group>"; };
|
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacMonitorTests.swift; sourceTree = "<group>"; };
|
||||||
32340166F6100A08105308D3 /* MMTelemetryCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryCoordinator.h; sourceTree = "<group>"; };
|
32340166F6100A08105308D3 /* MMTelemetryCoordinator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryCoordinator.h; sourceTree = "<group>"; };
|
||||||
|
336CEE35A745F3C7E9F70F43 /* MMFanTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMFanTests.swift; sourceTree = "<group>"; };
|
||||||
375AA781A2AA0A20B119C7B7 /* MMSMCParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMSMCParser.m; sourceTree = "<group>"; };
|
375AA781A2AA0A20B119C7B7 /* MMSMCParser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMSMCParser.m; sourceTree = "<group>"; };
|
||||||
|
3CFC5B905E428A6B854E0AB4 /* MMFanTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMFanTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
|
46DE3AE12DAE26C4FE58034C /* MMStorageTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMStorageTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
|
4CE92B1A8D7FDBB6499448E1 /* MMCPULoadTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMCPULoadTests.swift; sourceTree = "<group>"; };
|
||||||
5555436CD3CB8A73F5D6504F /* MMAppleSMCClient.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMAppleSMCClient.m; sourceTree = "<group>"; };
|
5555436CD3CB8A73F5D6504F /* MMAppleSMCClient.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMAppleSMCClient.m; sourceTree = "<group>"; };
|
||||||
5635101F862DE680856BDE6E /* MMTelemetryDomain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryDomain.h; sourceTree = "<group>"; };
|
5635101F862DE680856BDE6E /* MMTelemetryDomain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryDomain.h; sourceTree = "<group>"; };
|
||||||
56E285A0A1746AE659981F22 /* MacMonitorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MacMonitorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
56E285A0A1746AE659981F22 /* MacMonitorTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MacMonitorTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
57845310A3D4EC67E48A3B11 /* MMCPULoadProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMCPULoadProvider.h; sourceTree = "<group>"; };
|
||||||
|
62C377EFD025D6A6B5563E77 /* MMCPUThermalProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMCPUThermalProvider.m; sourceTree = "<group>"; };
|
||||||
6D0E5CAF25DFA9A1D2A698A0 /* MMTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryProvider.h; sourceTree = "<group>"; };
|
6D0E5CAF25DFA9A1D2A698A0 /* MMTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
|
6DCBCEA450103E2404761B78 /* MMStorageTelemetryProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMStorageTelemetryProvider.m; sourceTree = "<group>"; };
|
||||||
726005CB5A6C86E7D80D3CA0 /* MMAppleSMCClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMAppleSMCClient.h; sourceTree = "<group>"; };
|
726005CB5A6C86E7D80D3CA0 /* MMAppleSMCClient.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMAppleSMCClient.h; sourceTree = "<group>"; };
|
||||||
|
78325870C7CD8312AECA2236 /* MMStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMStorageTests.swift; sourceTree = "<group>"; };
|
||||||
8FBB436F3D9472194D8C6EDD /* MMSMCDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMSMCDefines.h; sourceTree = "<group>"; };
|
8FBB436F3D9472194D8C6EDD /* MMSMCDefines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMSMCDefines.h; sourceTree = "<group>"; };
|
||||||
940D608A1AF80F75584E744E /* MMSMCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMSMCTests.swift; sourceTree = "<group>"; };
|
940D608A1AF80F75584E744E /* MMSMCTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMSMCTests.swift; sourceTree = "<group>"; };
|
||||||
|
991AEEAF262F3C6BE930BC77 /* MMMemoryTelemetryProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMMemoryTelemetryProvider.m; sourceTree = "<group>"; };
|
||||||
ADEA6BD38BA8D887B1DB64A9 /* MacMonitorApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacMonitorApp.swift; sourceTree = "<group>"; };
|
ADEA6BD38BA8D887B1DB64A9 /* MacMonitorApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MacMonitorApp.swift; sourceTree = "<group>"; };
|
||||||
|
B288C7402E2C00E75F8CD016 /* MMComponentThermalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMComponentThermalTests.swift; sourceTree = "<group>"; };
|
||||||
|
C65F5835516BC2A65BCE25D2 /* MMComponentThermalProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMComponentThermalProvider.m; sourceTree = "<group>"; };
|
||||||
|
C9ED8F75E082D4F8AC2FF2F5 /* MMFanTelemetryProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMFanTelemetryProvider.m; sourceTree = "<group>"; };
|
||||||
|
CBA91906CA8B7936CC82A36B /* MMPowerTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMPowerTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
|
D48698681374BD25B980C000 /* MMPowerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMPowerTests.swift; sourceTree = "<group>"; };
|
||||||
|
D68FC8100D08DB6202F46339 /* MMCPULoadProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMCPULoadProvider.m; sourceTree = "<group>"; };
|
||||||
|
D73CCC7B5E6BF1825EA68E2B /* MMCPUThermalProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMCPUThermalProvider.h; sourceTree = "<group>"; };
|
||||||
E142AE61F9B87757997870DD /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
E142AE61F9B87757997870DD /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||||
E4B4E94FB2886C60D5548A2A /* SystemTelemetryStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemTelemetryStore.swift; sourceTree = "<group>"; };
|
E4B4E94FB2886C60D5548A2A /* SystemTelemetryStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemTelemetryStore.swift; sourceTree = "<group>"; };
|
||||||
F5EC59DCDA5FABDA409CDBCB /* MacMonitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacMonitor.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
F5EC59DCDA5FABDA409CDBCB /* MacMonitor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MacMonitor.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
@@ -79,6 +114,7 @@
|
|||||||
4D8D8B40632C525CBC1D0E43 /* App */,
|
4D8D8B40632C525CBC1D0E43 /* App */,
|
||||||
54787E6270EA7B9A1BE11359 /* Core */,
|
54787E6270EA7B9A1BE11359 /* Core */,
|
||||||
9844EC526E3527F6A582179F /* Hardware */,
|
9844EC526E3527F6A582179F /* Hardware */,
|
||||||
|
8BF79E3BCB76E7A1669DC930 /* Telemetry */,
|
||||||
3E4A0B53C583BD0B7A68EACE /* UI */,
|
3E4A0B53C583BD0B7A68EACE /* UI */,
|
||||||
);
|
);
|
||||||
path = Sources;
|
path = Sources;
|
||||||
@@ -112,6 +148,37 @@
|
|||||||
path = Core;
|
path = Core;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
78383CED205BCA772701AE48 /* CPU */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
57845310A3D4EC67E48A3B11 /* MMCPULoadProvider.h */,
|
||||||
|
D68FC8100D08DB6202F46339 /* MMCPULoadProvider.m */,
|
||||||
|
);
|
||||||
|
path = CPU;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
8B31CE7F9319FEC373E6CDC6 /* Power */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
CBA91906CA8B7936CC82A36B /* MMPowerTelemetryProvider.h */,
|
||||||
|
02F5FDE260999C39E978D849 /* MMPowerTelemetryProvider.m */,
|
||||||
|
);
|
||||||
|
path = Power;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
8BF79E3BCB76E7A1669DC930 /* Telemetry */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
78383CED205BCA772701AE48 /* CPU */,
|
||||||
|
AD2995435E44FA3E1790A4F3 /* Fan */,
|
||||||
|
EE2F5EFC9DC33CEDA79A131F /* Memory */,
|
||||||
|
8B31CE7F9319FEC373E6CDC6 /* Power */,
|
||||||
|
B6EB3F6545276C40212C2992 /* Storage */,
|
||||||
|
DBDC37231C01F0A2D4A7FC73 /* Thermal */,
|
||||||
|
);
|
||||||
|
path = Telemetry;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
9844EC526E3527F6A582179F /* Hardware */ = {
|
9844EC526E3527F6A582179F /* Hardware */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -120,6 +187,24 @@
|
|||||||
path = Hardware;
|
path = Hardware;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
AD2995435E44FA3E1790A4F3 /* Fan */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
3CFC5B905E428A6B854E0AB4 /* MMFanTelemetryProvider.h */,
|
||||||
|
C9ED8F75E082D4F8AC2FF2F5 /* MMFanTelemetryProvider.m */,
|
||||||
|
);
|
||||||
|
path = Fan;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
B6EB3F6545276C40212C2992 /* Storage */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
46DE3AE12DAE26C4FE58034C /* MMStorageTelemetryProvider.h */,
|
||||||
|
6DCBCEA450103E2404761B78 /* MMStorageTelemetryProvider.m */,
|
||||||
|
);
|
||||||
|
path = Storage;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
C80C3EEE8F912F4B214102E3 /* Products */ = {
|
C80C3EEE8F912F4B214102E3 /* Products */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -133,11 +218,29 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */,
|
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */,
|
||||||
|
B288C7402E2C00E75F8CD016 /* MMComponentThermalTests.swift */,
|
||||||
|
4CE92B1A8D7FDBB6499448E1 /* MMCPULoadTests.swift */,
|
||||||
|
0F2BD3777A674DC4EB442890 /* MMCPUThermalTests.swift */,
|
||||||
|
336CEE35A745F3C7E9F70F43 /* MMFanTests.swift */,
|
||||||
|
099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */,
|
||||||
|
D48698681374BD25B980C000 /* MMPowerTests.swift */,
|
||||||
940D608A1AF80F75584E744E /* MMSMCTests.swift */,
|
940D608A1AF80F75584E744E /* MMSMCTests.swift */,
|
||||||
|
78325870C7CD8312AECA2236 /* MMStorageTests.swift */,
|
||||||
);
|
);
|
||||||
path = Tests;
|
path = Tests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
DBDC37231C01F0A2D4A7FC73 /* Thermal */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
09475741B5D0D4B89B863C3D /* MMComponentThermalProvider.h */,
|
||||||
|
C65F5835516BC2A65BCE25D2 /* MMComponentThermalProvider.m */,
|
||||||
|
D73CCC7B5E6BF1825EA68E2B /* MMCPUThermalProvider.h */,
|
||||||
|
62C377EFD025D6A6B5563E77 /* MMCPUThermalProvider.m */,
|
||||||
|
);
|
||||||
|
path = Thermal;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
E012FBB26EF9E35A2FAF87E2 /* AppleSMC */ = {
|
E012FBB26EF9E35A2FAF87E2 /* AppleSMC */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -159,6 +262,15 @@
|
|||||||
name = Frameworks;
|
name = Frameworks;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
EE2F5EFC9DC33CEDA79A131F /* Memory */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
0130BD1E18972DF9E2955334 /* MMMemoryTelemetryProvider.h */,
|
||||||
|
991AEEAF262F3C6BE930BC77 /* MMMemoryTelemetryProvider.m */,
|
||||||
|
);
|
||||||
|
path = Memory;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
/* Begin PBXNativeTarget section */
|
||||||
@@ -234,7 +346,14 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
160334CC765E091A7CBE21AA /* MMCPULoadTests.swift in Sources */,
|
||||||
|
87818E46CEA5145A8215D0E3 /* MMCPUThermalTests.swift in Sources */,
|
||||||
|
57BA02AE1CE24DBD02BD03A4 /* MMComponentThermalTests.swift in Sources */,
|
||||||
|
E6F2F695B8D3E7045967C082 /* MMFanTests.swift in Sources */,
|
||||||
|
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */,
|
||||||
|
9B5C651AD2AF7DE2738F0C44 /* MMPowerTests.swift in Sources */,
|
||||||
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */,
|
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */,
|
||||||
|
1B15F48F6B19E9EA4556ECD5 /* MMStorageTests.swift in Sources */,
|
||||||
9BCE74C5454F81EF80492E75 /* MacMonitorTests.swift in Sources */,
|
9BCE74C5454F81EF80492E75 /* MacMonitorTests.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@@ -245,7 +364,14 @@
|
|||||||
files = (
|
files = (
|
||||||
A9FCAEC0BF27A419DB148C4A /* ContentView.swift in Sources */,
|
A9FCAEC0BF27A419DB148C4A /* ContentView.swift in Sources */,
|
||||||
CD91FC663B19DA1FEA3D49D7 /* MMAppleSMCClient.m in Sources */,
|
CD91FC663B19DA1FEA3D49D7 /* MMAppleSMCClient.m in Sources */,
|
||||||
|
4419FE7554489B23976E2970 /* MMCPULoadProvider.m in Sources */,
|
||||||
|
87A9E18362486D0D385BBC4A /* MMCPUThermalProvider.m in Sources */,
|
||||||
|
925245C5B5F8D8DA3C89C4BA /* MMComponentThermalProvider.m in Sources */,
|
||||||
|
655366D7066478A02EDA91BB /* MMFanTelemetryProvider.m in Sources */,
|
||||||
|
B9C2D6574E808B517BA34C83 /* MMMemoryTelemetryProvider.m in Sources */,
|
||||||
|
0A7117B3B7CC7112F2527574 /* MMPowerTelemetryProvider.m in Sources */,
|
||||||
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */,
|
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */,
|
||||||
|
F2F7A141F2452EC1B4FB45D8 /* MMStorageTelemetryProvider.m in Sources */,
|
||||||
EAFAF5A10502D4ACC64F4720 /* MMTelemetryCoordinator.m in Sources */,
|
EAFAF5A10502D4ACC64F4720 /* MMTelemetryCoordinator.m in Sources */,
|
||||||
88387CDAE2AC1CC74EF89B57 /* MacMonitorApp.swift in Sources */,
|
88387CDAE2AC1CC74EF89B57 /* MacMonitorApp.swift in Sources */,
|
||||||
A7609CE56D49EC3419987468 /* SystemTelemetryStore.swift in Sources */,
|
A7609CE56D49EC3419987468 /* SystemTelemetryStore.swift in Sources */,
|
||||||
|
|||||||
@@ -2,6 +2,87 @@ import Foundation
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Observation
|
import Observation
|
||||||
|
|
||||||
|
// MARK: - Typed Telemetry Models
|
||||||
|
|
||||||
|
public struct CPULoadMetrics: Sendable {
|
||||||
|
public var systemLoad: Double = 0
|
||||||
|
public var userLoad: Double = 0
|
||||||
|
public var idleLoad: Double = 100
|
||||||
|
public var totalLoad: Double = 0
|
||||||
|
public var perCoreLoad: [Double] = []
|
||||||
|
public var cpuFrequencyMHz: Double = 0
|
||||||
|
public var isThrottled: Bool = false
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct MemoryMetrics: Sendable {
|
||||||
|
public var totalBytes: UInt64 = 0
|
||||||
|
public var usedBytes: UInt64 = 0
|
||||||
|
public var freeBytes: UInt64 = 0
|
||||||
|
public var activeBytes: UInt64 = 0
|
||||||
|
public var inactiveBytes: UInt64 = 0
|
||||||
|
public var wiredBytes: UInt64 = 0
|
||||||
|
public var compressedBytes: UInt64 = 0
|
||||||
|
public var swapTotalBytes: UInt64 = 0
|
||||||
|
public var swapUsedBytes: UInt64 = 0
|
||||||
|
public var utilizationPercentage: Double = 0
|
||||||
|
public var pressureLevel: String = "Normal"
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct StorageVolumeItem: Identifiable, Sendable {
|
||||||
|
public var id: String { mountPoint }
|
||||||
|
public let mountPoint: String
|
||||||
|
public let volumeName: String
|
||||||
|
public let fileSystem: String
|
||||||
|
public let totalBytes: UInt64
|
||||||
|
public let freeBytes: UInt64
|
||||||
|
public let usedBytes: UInt64
|
||||||
|
public let usedPercentage: Double
|
||||||
|
public let isReadOnly: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct CPUThermalMetrics: Sendable {
|
||||||
|
public var packageTemperature: Double = 0
|
||||||
|
public var averageCoreTemperature: Double = 0
|
||||||
|
public var peakCoreTemperature: Double = 0
|
||||||
|
public var coreTemperatures: [(index: Int, key: String, temperature: Double)] = []
|
||||||
|
public var thermalPressureState: String = "Nominal"
|
||||||
|
public var isThrottling: Bool = false
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct FanTelemetryItem: Identifiable, Sendable {
|
||||||
|
public var id: Int { index }
|
||||||
|
public let index: Int
|
||||||
|
public let name: String
|
||||||
|
public let currentRPM: Double
|
||||||
|
public let minRPM: Double
|
||||||
|
public let maxRPM: Double
|
||||||
|
public let targetRPM: Double
|
||||||
|
public let utilization: Double
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct ComponentThermalItem: Identifiable, Sendable {
|
||||||
|
public var id: String { key }
|
||||||
|
public let key: String
|
||||||
|
public let name: String
|
||||||
|
public let category: String
|
||||||
|
public let temperature: Double
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct PowerMetrics: Sendable {
|
||||||
|
public var systemTotalWatts: Double = 0
|
||||||
|
public var cpuWatts: Double = 0
|
||||||
|
public var gpuWatts: Double = 0
|
||||||
|
public var memoryWatts: Double = 0
|
||||||
|
public var cpuVoltage: Double = 0
|
||||||
|
public var cpuCurrent: Double = 0
|
||||||
|
public var powerSource: String = "AC Power"
|
||||||
|
public var isCharging: Bool = false
|
||||||
|
public var batteryLevel: Double = 100.0
|
||||||
|
public var sensorReadings: [(key: String, name: String, value: Double, unit: String)] = []
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - SystemTelemetryStore
|
||||||
|
|
||||||
@Observable
|
@Observable
|
||||||
@MainActor
|
@MainActor
|
||||||
public final class SystemTelemetryStore {
|
public final class SystemTelemetryStore {
|
||||||
@@ -14,6 +95,15 @@ public final class SystemTelemetryStore {
|
|||||||
/// Raw snapshots organized by provider identifier
|
/// Raw snapshots organized by provider identifier
|
||||||
public private(set) var latestSnapshot: [String: [String: Any]] = [:]
|
public private(set) var latestSnapshot: [String: [String: Any]] = [:]
|
||||||
|
|
||||||
|
/// Structured Telemetry Metrics
|
||||||
|
public private(set) var cpuLoad = CPULoadMetrics()
|
||||||
|
public private(set) var memory = MemoryMetrics()
|
||||||
|
public private(set) var storageVolumes: [StorageVolumeItem] = []
|
||||||
|
public private(set) var cpuThermal = CPUThermalMetrics()
|
||||||
|
public private(set) var fans: [FanTelemetryItem] = []
|
||||||
|
public private(set) var componentTemps: [ComponentThermalItem] = []
|
||||||
|
public private(set) var power = PowerMetrics()
|
||||||
|
|
||||||
/// System identification
|
/// System identification
|
||||||
public let hostModel: String
|
public let hostModel: String
|
||||||
public let osVersion: String
|
public let osVersion: String
|
||||||
@@ -30,15 +120,154 @@ public final class SystemTelemetryStore {
|
|||||||
self.physicalCpuCount = SystemTelemetryStore.readSysctlInt("hw.physicalcpu") ?? 1
|
self.physicalCpuCount = SystemTelemetryStore.readSysctlInt("hw.physicalcpu") ?? 1
|
||||||
self.logicalCpuCount = SystemTelemetryStore.readSysctlInt("hw.logicalcpu") ?? 1
|
self.logicalCpuCount = SystemTelemetryStore.readSysctlInt("hw.logicalcpu") ?? 1
|
||||||
|
|
||||||
|
registerDefaultProviders()
|
||||||
setupCoordinator()
|
setupCoordinator()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func registerDefaultProviders() {
|
||||||
|
// Register all Primary System & Thermal Telemetry providers (M2)
|
||||||
|
coordinator.register(MMCPULoadProvider())
|
||||||
|
coordinator.register(MMMemoryTelemetryProvider())
|
||||||
|
coordinator.register(MMStorageTelemetryProvider())
|
||||||
|
coordinator.register(MMCPUThermalProvider())
|
||||||
|
coordinator.register(MMFanTelemetryProvider())
|
||||||
|
coordinator.register(MMComponentThermalProvider())
|
||||||
|
coordinator.register(MMPowerTelemetryProvider())
|
||||||
|
}
|
||||||
|
|
||||||
private func setupCoordinator() {
|
private func setupCoordinator() {
|
||||||
coordinator.sampleInterval = self.sampleInterval
|
coordinator.sampleInterval = self.sampleInterval
|
||||||
coordinator.snapshotHandler = { [weak self] snapshot in
|
coordinator.snapshotHandler = { [weak self] snapshot in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.latestSnapshot = snapshot
|
self.latestSnapshot = snapshot
|
||||||
self.lastUpdateTimestamp = Date()
|
self.lastUpdateTimestamp = Date()
|
||||||
|
self.decodeSnapshot(snapshot)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func decodeSnapshot(_ snapshot: [String: [String: Any]]) {
|
||||||
|
// 1. CPU Load
|
||||||
|
if let cpuDict = snapshot["com.i3omb.macmonitor.telemetry.cpu"] {
|
||||||
|
var m = CPULoadMetrics()
|
||||||
|
m.systemLoad = (cpuDict["systemLoad"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.userLoad = (cpuDict["userLoad"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.idleLoad = (cpuDict["idleLoad"] as? NSNumber)?.doubleValue ?? 100
|
||||||
|
m.totalLoad = (cpuDict["totalLoad"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
if let perCore = cpuDict["perCoreLoad"] as? [NSNumber] {
|
||||||
|
m.perCoreLoad = perCore.map { $0.doubleValue }
|
||||||
|
}
|
||||||
|
m.cpuFrequencyMHz = (cpuDict["cpuFrequencyMHz"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.isThrottled = (cpuDict["isThrottled"] as? NSNumber)?.boolValue ?? false
|
||||||
|
self.cpuLoad = m
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Memory
|
||||||
|
if let memDict = snapshot["com.i3omb.macmonitor.telemetry.memory"] {
|
||||||
|
var m = MemoryMetrics()
|
||||||
|
m.totalBytes = (memDict["totalBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.usedBytes = (memDict["usedBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.freeBytes = (memDict["freeBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.activeBytes = (memDict["activeBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.inactiveBytes = (memDict["inactiveBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.wiredBytes = (memDict["wiredBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.compressedBytes = (memDict["compressedBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.swapTotalBytes = (memDict["swapTotalBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.swapUsedBytes = (memDict["swapUsedBytes"] as? NSNumber)?.uint64Value ?? 0
|
||||||
|
m.utilizationPercentage = (memDict["utilizationPercentage"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.pressureLevel = memDict["pressureLevel"] as? String ?? "Normal"
|
||||||
|
self.memory = m
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Storage
|
||||||
|
if let stgDict = snapshot["com.i3omb.macmonitor.telemetry.storage"],
|
||||||
|
let volArray = stgDict["volumes"] as? [[String: Any]] {
|
||||||
|
self.storageVolumes = volArray.compactMap { dict in
|
||||||
|
guard let mount = dict["mountPoint"] as? String else { return nil }
|
||||||
|
return StorageVolumeItem(
|
||||||
|
mountPoint: mount,
|
||||||
|
volumeName: dict["volumeName"] as? String ?? mount,
|
||||||
|
fileSystem: dict["fileSystem"] as? String ?? "APFS",
|
||||||
|
totalBytes: (dict["totalBytes"] as? NSNumber)?.uint64Value ?? 0,
|
||||||
|
freeBytes: (dict["freeBytes"] as? NSNumber)?.uint64Value ?? 0,
|
||||||
|
usedBytes: (dict["usedBytes"] as? NSNumber)?.uint64Value ?? 0,
|
||||||
|
usedPercentage: (dict["usedPercentage"] as? NSNumber)?.doubleValue ?? 0,
|
||||||
|
isReadOnly: (dict["isReadOnly"] as? NSNumber)?.boolValue ?? false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. CPU Thermal
|
||||||
|
if let thDict = snapshot["com.i3omb.macmonitor.telemetry.thermal.cpu"] {
|
||||||
|
var m = CPUThermalMetrics()
|
||||||
|
m.packageTemperature = (thDict["packageTemperature"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.averageCoreTemperature = (thDict["averageCoreTemperature"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.peakCoreTemperature = (thDict["peakCoreTemperature"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.thermalPressureState = thDict["thermalPressureState"] as? String ?? "Nominal"
|
||||||
|
m.isThrottling = (thDict["isThrottling"] as? NSNumber)?.boolValue ?? false
|
||||||
|
if let coresList = thDict["coreTemperatures"] as? [[String: Any]] {
|
||||||
|
m.coreTemperatures = coresList.compactMap { d in
|
||||||
|
let idx = (d["coreIndex"] as? NSNumber)?.intValue ?? 0
|
||||||
|
let key = d["key"] as? String ?? "TC\(idx)C"
|
||||||
|
let temp = (d["temperature"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
return (index: idx, key: key, temperature: temp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.cpuThermal = m
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Fans
|
||||||
|
if let fanDict = snapshot["com.i3omb.macmonitor.telemetry.fan"],
|
||||||
|
let fanArray = fanDict["fans"] as? [[String: Any]] {
|
||||||
|
self.fans = fanArray.compactMap { d in
|
||||||
|
let idx = (d["index"] as? NSNumber)?.intValue ?? 0
|
||||||
|
return FanTelemetryItem(
|
||||||
|
index: idx,
|
||||||
|
name: d["name"] as? String ?? "Fan \(idx + 1)",
|
||||||
|
currentRPM: (d["currentRPM"] as? NSNumber)?.doubleValue ?? 0,
|
||||||
|
minRPM: (d["minRPM"] as? NSNumber)?.doubleValue ?? 0,
|
||||||
|
maxRPM: (d["maxRPM"] as? NSNumber)?.doubleValue ?? 0,
|
||||||
|
targetRPM: (d["targetRPM"] as? NSNumber)?.doubleValue ?? 0,
|
||||||
|
utilization: (d["utilization"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. Component Thermals
|
||||||
|
if let compDict = snapshot["com.i3omb.macmonitor.telemetry.thermal.components"],
|
||||||
|
let compArray = compDict["components"] as? [[String: Any]] {
|
||||||
|
self.componentTemps = compArray.compactMap { d in
|
||||||
|
guard let key = d["key"] as? String else { return nil }
|
||||||
|
return ComponentThermalItem(
|
||||||
|
key: key,
|
||||||
|
name: d["name"] as? String ?? key,
|
||||||
|
category: d["category"] as? String ?? "Other",
|
||||||
|
temperature: (d["temperature"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. Power
|
||||||
|
if let pwrDict = snapshot["com.i3omb.macmonitor.telemetry.power"] {
|
||||||
|
var m = PowerMetrics()
|
||||||
|
m.systemTotalWatts = (pwrDict["systemTotalWatts"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.cpuWatts = (pwrDict["cpuWatts"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.gpuWatts = (pwrDict["gpuWatts"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.memoryWatts = (pwrDict["memoryWatts"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.cpuVoltage = (pwrDict["cpuVoltage"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.cpuCurrent = (pwrDict["cpuCurrent"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
m.powerSource = pwrDict["powerSource"] as? String ?? "AC Power"
|
||||||
|
m.isCharging = (pwrDict["isCharging"] as? NSNumber)?.boolValue ?? false
|
||||||
|
m.batteryLevel = (pwrDict["batteryLevel"] as? NSNumber)?.doubleValue ?? 100.0
|
||||||
|
if let sensorList = pwrDict["sensors"] as? [[String: Any]] {
|
||||||
|
m.sensorReadings = sensorList.compactMap { d in
|
||||||
|
guard let k = d["key"] as? String else { return nil }
|
||||||
|
let n = d["name"] as? String ?? k
|
||||||
|
let v = (d["value"] as? NSNumber)?.doubleValue ?? 0
|
||||||
|
let u = d["unit"] as? String ?? ""
|
||||||
|
return (key: k, name: n, value: v, unit: u)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.power = m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,14 @@
|
|||||||
#import "MMSMCParser.h"
|
#import "MMSMCParser.h"
|
||||||
#import "MMAppleSMCClient.h"
|
#import "MMAppleSMCClient.h"
|
||||||
|
|
||||||
|
// Telemetry Providers
|
||||||
|
#import "MMCPULoadProvider.h"
|
||||||
|
#import "MMMemoryTelemetryProvider.h"
|
||||||
|
#import "MMStorageTelemetryProvider.h"
|
||||||
|
#import "MMCPUThermalProvider.h"
|
||||||
|
#import "MMFanTelemetryProvider.h"
|
||||||
|
#import "MMComponentThermalProvider.h"
|
||||||
|
#import "MMPowerTelemetryProvider.h"
|
||||||
|
#import "MMKernelTelemetryProvider.h"
|
||||||
|
|
||||||
#endif /* MacMonitor_Bridging_Header_h */
|
#endif /* MacMonitor_Bridging_Header_h */
|
||||||
|
|||||||
@@ -40,6 +40,13 @@
|
|||||||
(uint32_t)bytes[3];
|
(uint32_t)bytes[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int hexDigitValue(unichar c) {
|
||||||
|
if (c >= '0' && c <= '9') return c - '0';
|
||||||
|
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||||
|
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
+ (nullable NSNumber *)decodeValueWithDataType:(NSString *)dataType bytes:(const uint8_t *)bytes size:(NSUInteger)size {
|
+ (nullable NSNumber *)decodeValueWithDataType:(NSString *)dataType bytes:(const uint8_t *)bytes size:(NSUInteger)size {
|
||||||
if (!bytes || size == 0) return nil;
|
if (!bytes || size == 0) return nil;
|
||||||
|
|
||||||
@@ -49,7 +56,7 @@
|
|||||||
if (size >= 2) return @([self decodeSP78:bytes]);
|
if (size >= 2) return @([self decodeSP78:bytes]);
|
||||||
} else if ([trimmedType isEqualToString:@"fpe2"]) {
|
} else if ([trimmedType isEqualToString:@"fpe2"]) {
|
||||||
if (size >= 2) return @([self decodeFPE2:bytes]);
|
if (size >= 2) return @([self decodeFPE2:bytes]);
|
||||||
} else if ([trimmedType isEqualToString:@"flt"]) {
|
} else if ([trimmedType isEqualToString:@"flt"] || [trimmedType isEqualToString:@"ioft"]) {
|
||||||
if (size >= 4) return @([self decodeFLT:bytes]);
|
if (size >= 4) return @([self decodeFLT:bytes]);
|
||||||
} else if ([trimmedType isEqualToString:@"ui8"]) {
|
} else if ([trimmedType isEqualToString:@"ui8"]) {
|
||||||
if (size >= 1) return @([self decodeUI8:bytes]);
|
if (size >= 1) return @([self decodeUI8:bytes]);
|
||||||
@@ -59,6 +66,18 @@
|
|||||||
if (size >= 4) return @([self decodeUI32:bytes]);
|
if (size >= 4) return @([self decodeUI32:bytes]);
|
||||||
} else if ([trimmedType isEqualToString:@"flag"]) {
|
} else if ([trimmedType isEqualToString:@"flag"]) {
|
||||||
if (size >= 1) return @(bytes[0] != 0);
|
if (size >= 1) return @(bytes[0] != 0);
|
||||||
|
} else if (trimmedType.length == 4 && [trimmedType hasPrefix:@"sp"] && size >= 2) {
|
||||||
|
int fracBits = hexDigitValue([trimmedType characterAtIndex:3]);
|
||||||
|
if (fracBits >= 0 && fracBits <= 15) {
|
||||||
|
int16_t raw = (int16_t)(((uint16_t)bytes[0] << 8) | (uint16_t)bytes[1]);
|
||||||
|
return @((float)raw / (float)(1 << fracBits));
|
||||||
|
}
|
||||||
|
} else if (trimmedType.length == 4 && [trimmedType hasPrefix:@"fp"] && size >= 2) {
|
||||||
|
int fracBits = hexDigitValue([trimmedType characterAtIndex:3]);
|
||||||
|
if (fracBits >= 0 && fracBits <= 15) {
|
||||||
|
uint16_t raw = ((uint16_t)bytes[0] << 8) | (uint16_t)bytes[1];
|
||||||
|
return @((float)raw / (float)(1 << fracBits));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef MMCPULoadProvider_h
|
||||||
|
#define MMCPULoadProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <mach/mach.h>
|
||||||
|
#import <mach/processor_info.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMCPULoadProvider
|
||||||
|
* Samples real-time Mach host processor CPU load ticks, per-core utilization percentages,
|
||||||
|
* and CPU operating frequency.
|
||||||
|
*/
|
||||||
|
@interface MMCPULoadProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, readonly) natural_t coreCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static calculator method facilitating deterministic unit testing with mock tick data.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateLoadFromPreviousTicks:(const struct processor_cpu_load_info * _Nullable)prevTicks
|
||||||
|
currentTicks:(const struct processor_cpu_load_info *)currTicks
|
||||||
|
coreCount:(natural_t)coreCount;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMCPULoadProvider_h */
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
#import "MMCPULoadProvider.h"
|
||||||
|
#import <sys/sysctl.h>
|
||||||
|
#import <os/lock.h>
|
||||||
|
|
||||||
|
@interface MMCPULoadProvider () {
|
||||||
|
os_unfair_lock _lock;
|
||||||
|
processor_cpu_load_info_t _previousCpuInfo;
|
||||||
|
mach_msg_type_number_t _previousCpuInfoCount;
|
||||||
|
natural_t _coreCount;
|
||||||
|
uint64_t _maxFrequencyHz;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMCPULoadProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_lock = OS_UNFAIR_LOCK_INIT;
|
||||||
|
_previousCpuInfo = NULL;
|
||||||
|
_previousCpuInfoCount = 0;
|
||||||
|
|
||||||
|
// Read CPU core count
|
||||||
|
natural_t cCount = 1;
|
||||||
|
size_t size = sizeof(cCount);
|
||||||
|
sysctlbyname("hw.logicalcpu", &cCount, &size, NULL, 0);
|
||||||
|
_coreCount = cCount;
|
||||||
|
|
||||||
|
// Read maximum frequency
|
||||||
|
uint64_t maxFreq = 0;
|
||||||
|
size = sizeof(maxFreq);
|
||||||
|
if (sysctlbyname("hw.cpufrequency_max", &maxFreq, &size, NULL, 0) != 0) {
|
||||||
|
sysctlbyname("hw.cpufrequency", &maxFreq, &size, NULL, 0);
|
||||||
|
}
|
||||||
|
_maxFrequencyHz = maxFreq;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)dealloc {
|
||||||
|
if (_previousCpuInfo != NULL) {
|
||||||
|
free(_previousCpuInfo);
|
||||||
|
_previousCpuInfo = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainCPU;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.cpuload";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (natural_t)coreCount {
|
||||||
|
return _coreCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateLoadFromPreviousTicks:(const struct processor_cpu_load_info * _Nullable)prevTicks
|
||||||
|
currentTicks:(const struct processor_cpu_load_info *)currTicks
|
||||||
|
coreCount:(natural_t)coreCount {
|
||||||
|
if (!currTicks || coreCount == 0) return @{};
|
||||||
|
|
||||||
|
NSMutableArray<NSDictionary<NSString *, NSNumber *> *> *coresList = [NSMutableArray arrayWithCapacity:coreCount];
|
||||||
|
double totalUserPercent = 0.0;
|
||||||
|
double totalSystemPercent = 0.0;
|
||||||
|
double totalIdlePercent = 0.0;
|
||||||
|
double totalActivePercent = 0.0;
|
||||||
|
|
||||||
|
for (natural_t i = 0; i < coreCount; i++) {
|
||||||
|
uint64_t user = currTicks[i].cpu_ticks[CPU_STATE_USER];
|
||||||
|
uint64_t system = currTicks[i].cpu_ticks[CPU_STATE_SYSTEM];
|
||||||
|
uint64_t idle = currTicks[i].cpu_ticks[CPU_STATE_IDLE];
|
||||||
|
uint64_t nice = currTicks[i].cpu_ticks[CPU_STATE_NICE];
|
||||||
|
|
||||||
|
uint64_t deltaUser = 0;
|
||||||
|
uint64_t deltaSystem = 0;
|
||||||
|
uint64_t deltaIdle = 0;
|
||||||
|
uint64_t deltaNice = 0;
|
||||||
|
|
||||||
|
if (prevTicks != NULL) {
|
||||||
|
deltaUser = (user >= prevTicks[i].cpu_ticks[CPU_STATE_USER]) ? (user - prevTicks[i].cpu_ticks[CPU_STATE_USER]) : 0;
|
||||||
|
deltaSystem = (system >= prevTicks[i].cpu_ticks[CPU_STATE_SYSTEM]) ? (system - prevTicks[i].cpu_ticks[CPU_STATE_SYSTEM]) : 0;
|
||||||
|
deltaIdle = (idle >= prevTicks[i].cpu_ticks[CPU_STATE_IDLE]) ? (idle - prevTicks[i].cpu_ticks[CPU_STATE_IDLE]) : 0;
|
||||||
|
deltaNice = (nice >= prevTicks[i].cpu_ticks[CPU_STATE_NICE]) ? (nice - prevTicks[i].cpu_ticks[CPU_STATE_NICE]) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t deltaTotal = deltaUser + deltaSystem + deltaIdle + deltaNice;
|
||||||
|
double uPct = 0.0, sPct = 0.0, iPct = 100.0, aPct = 0.0;
|
||||||
|
|
||||||
|
if (deltaTotal > 0) {
|
||||||
|
uPct = ((double)deltaUser / (double)deltaTotal) * 100.0;
|
||||||
|
sPct = ((double)deltaSystem / (double)deltaTotal) * 100.0;
|
||||||
|
iPct = ((double)deltaIdle / (double)deltaTotal) * 100.0;
|
||||||
|
aPct = 100.0 - iPct;
|
||||||
|
if (aPct < 0.0) aPct = 0.0;
|
||||||
|
if (aPct > 100.0) aPct = 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
totalUserPercent += uPct;
|
||||||
|
totalSystemPercent += sPct;
|
||||||
|
totalIdlePercent += iPct;
|
||||||
|
totalActivePercent += aPct;
|
||||||
|
|
||||||
|
[coresList addObject:@{
|
||||||
|
@"coreIndex": @(i),
|
||||||
|
@"userPercent": @(uPct),
|
||||||
|
@"systemPercent": @(sPct),
|
||||||
|
@"idlePercent": @(iPct),
|
||||||
|
@"totalPercent": @(aPct)
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
double avgUser = coreCount > 0 ? (totalUserPercent / coreCount) : 0.0;
|
||||||
|
double avgSystem = coreCount > 0 ? (totalSystemPercent / coreCount) : 0.0;
|
||||||
|
double avgIdle = coreCount > 0 ? (totalIdlePercent / coreCount) : 100.0;
|
||||||
|
double avgTotal = coreCount > 0 ? (totalActivePercent / coreCount) : 0.0;
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"cores": coresList,
|
||||||
|
@"coreCount": @(coreCount),
|
||||||
|
@"userPercent": @(avgUser),
|
||||||
|
@"systemPercent": @(avgSystem),
|
||||||
|
@"idlePercent": @(avgIdle),
|
||||||
|
@"totalPercent": @(avgTotal)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
natural_t numCPUs = 0;
|
||||||
|
processor_info_array_t cpuInfo = NULL;
|
||||||
|
mach_msg_type_number_t numCpuInfo = 0;
|
||||||
|
|
||||||
|
kern_return_t kr = host_processor_info(
|
||||||
|
mach_host_self(),
|
||||||
|
PROCESSOR_CPU_LOAD_INFO,
|
||||||
|
&numCPUs,
|
||||||
|
&cpuInfo,
|
||||||
|
&numCpuInfo
|
||||||
|
);
|
||||||
|
|
||||||
|
if (kr != KERN_SUCCESS || cpuInfo == NULL) {
|
||||||
|
if (error) {
|
||||||
|
*error = [NSError errorWithDomain:@"com.i3omb.MacMonitor.CPU"
|
||||||
|
code:kr
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey: @"host_processor_info failed to read CPU ticks"}];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
os_unfair_lock_lock(&_lock);
|
||||||
|
|
||||||
|
processor_cpu_load_info_t currentCpuInfo = (processor_cpu_load_info_t)cpuInfo;
|
||||||
|
NSDictionary<NSString *, id> *metrics = [MMCPULoadProvider calculateLoadFromPreviousTicks:_previousCpuInfo
|
||||||
|
currentTicks:currentCpuInfo
|
||||||
|
coreCount:numCPUs];
|
||||||
|
|
||||||
|
// Free previous malloc buffer
|
||||||
|
if (_previousCpuInfo != NULL) {
|
||||||
|
free(_previousCpuInfo);
|
||||||
|
_previousCpuInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate new buffer to preserve state for the next delta
|
||||||
|
vm_size_t bufferSize = numCpuInfo * sizeof(integer_t);
|
||||||
|
_previousCpuInfo = (processor_cpu_load_info_t)malloc(bufferSize);
|
||||||
|
if (_previousCpuInfo != NULL) {
|
||||||
|
memcpy(_previousCpuInfo, cpuInfo, bufferSize);
|
||||||
|
_previousCpuInfoCount = numCpuInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deallocate the buffer returned by the kernel
|
||||||
|
vm_deallocate(mach_task_self(), (vm_address_t)cpuInfo, numCpuInfo * sizeof(integer_t));
|
||||||
|
|
||||||
|
os_unfair_lock_unlock(&_lock);
|
||||||
|
|
||||||
|
// Read current frequency
|
||||||
|
uint64_t currentFreq = 0;
|
||||||
|
size_t size = sizeof(currentFreq);
|
||||||
|
if (sysctlbyname("hw.cpufrequency", ¤tFreq, &size, NULL, 0) != 0) {
|
||||||
|
currentFreq = _maxFrequencyHz;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thermal State
|
||||||
|
NSProcessInfoThermalState thermalState = [NSProcessInfo processInfo].thermalState;
|
||||||
|
BOOL isThrottled = (thermalState >= NSProcessInfoThermalStateSerious);
|
||||||
|
|
||||||
|
NSMutableDictionary<NSString *, id> *result = [metrics mutableCopy];
|
||||||
|
result[@"frequencyHz"] = @(currentFreq);
|
||||||
|
result[@"maxFrequencyHz"] = @(_maxFrequencyHz);
|
||||||
|
result[@"thermalState"] = @(thermalState);
|
||||||
|
result[@"isThrottled"] = @(isThrottled);
|
||||||
|
|
||||||
|
return [result copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef MMFanTelemetryProvider_h
|
||||||
|
#define MMFanTelemetryProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
#import "MMAppleSMCClient.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMFanTelemetryProvider
|
||||||
|
* Samples multi-fan telemetry from AppleSMC: current RPM, min RPM, max RPM, target RPM,
|
||||||
|
* and fan utilization percentages.
|
||||||
|
*/
|
||||||
|
@interface MMFanTelemetryProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, strong, readonly) MMAppleSMCClient *smcClient;
|
||||||
|
@property (nonatomic, readonly) NSInteger fanCount;
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static calculator method for deterministic unit testing.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateFanMetricsFromFanList:(NSArray<NSDictionary<NSString *, NSNumber *> *> *)fanList;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMFanTelemetryProvider_h */
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
#import "MMFanTelemetryProvider.h"
|
||||||
|
|
||||||
|
@interface MMFanTelemetryProvider () {
|
||||||
|
MMAppleSMCClient *_smcClient;
|
||||||
|
NSInteger _probedFanCount;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMFanTelemetryProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
return [self initWithSMCClient:[MMAppleSMCClient sharedClient]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_smcClient = client;
|
||||||
|
_probedFanCount = -1;
|
||||||
|
[self probeFans];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)probeFans {
|
||||||
|
if (!_smcClient.isAvailable) return;
|
||||||
|
|
||||||
|
NSNumber *num = [_smcClient readNumericValueForKey:@"FNum" error:nil];
|
||||||
|
if (num) {
|
||||||
|
_probedFanCount = [num integerValue];
|
||||||
|
} else {
|
||||||
|
// Fallback probe F0Ac
|
||||||
|
NSNumber *f0 = [_smcClient readNumericValueForKey:@"F0Ac" error:nil];
|
||||||
|
if (f0 && [f0 doubleValue] >= 0.0) {
|
||||||
|
_probedFanCount = 1;
|
||||||
|
NSNumber *f1 = [_smcClient readNumericValueForKey:@"F1Ac" error:nil];
|
||||||
|
if (f1 && [f1 doubleValue] >= 0.0) {
|
||||||
|
_probedFanCount = 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_probedFanCount = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainFan;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.fan";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return _smcClient.isAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMAppleSMCClient *)smcClient {
|
||||||
|
return _smcClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSInteger)fanCount {
|
||||||
|
return (_probedFanCount >= 0) ? _probedFanCount : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateFanMetricsFromFanList:(NSArray<NSDictionary<NSString *, NSNumber *> *> *)fanList {
|
||||||
|
if (!fanList || fanList.count == 0) {
|
||||||
|
return @{
|
||||||
|
@"fanCount": @(0),
|
||||||
|
@"fans": @[],
|
||||||
|
@"averageRPM": @(0.0),
|
||||||
|
@"peakRPM": @(0.0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableArray<NSDictionary<NSString *, id> *> *resultList = [NSMutableArray arrayWithCapacity:fanList.count];
|
||||||
|
double sumRPM = 0.0;
|
||||||
|
double peakRPM = 0.0;
|
||||||
|
|
||||||
|
for (NSUInteger i = 0; i < fanList.count; i++) {
|
||||||
|
NSDictionary<NSString *, NSNumber *> *raw = fanList[i];
|
||||||
|
double current = [raw[@"currentRPM"] doubleValue];
|
||||||
|
double min = [raw[@"minRPM"] doubleValue];
|
||||||
|
double max = [raw[@"maxRPM"] doubleValue];
|
||||||
|
double target = [raw[@"targetRPM"] doubleValue];
|
||||||
|
|
||||||
|
double util = 0.0;
|
||||||
|
if (max > min && current >= min) {
|
||||||
|
util = ((current - min) / (max - min)) * 100.0;
|
||||||
|
if (util < 0.0) util = 0.0;
|
||||||
|
if (util > 100.0) util = 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current > peakRPM) peakRPM = current;
|
||||||
|
sumRPM += current;
|
||||||
|
|
||||||
|
[resultList addObject:@{
|
||||||
|
@"fanIndex": @(i),
|
||||||
|
@"currentRPM": @(current),
|
||||||
|
@"minRPM": @(min),
|
||||||
|
@"maxRPM": @(max),
|
||||||
|
@"targetRPM": @(target),
|
||||||
|
@"utilizationPercent": @(util)
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
double avgRPM = fanList.count > 0 ? (sumRPM / fanList.count) : 0.0;
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"fanCount": @(fanList.count),
|
||||||
|
@"fans": [resultList copy],
|
||||||
|
@"averageRPM": @(avgRPM),
|
||||||
|
@"peakRPM": @(peakRPM)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
if (_probedFanCount < 0 && _smcClient.isAvailable) {
|
||||||
|
[self probeFans];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSInteger count = [self fanCount];
|
||||||
|
NSMutableArray<NSDictionary<NSString *, NSNumber *> *> *rawList = [NSMutableArray arrayWithCapacity:count];
|
||||||
|
|
||||||
|
for (NSInteger i = 0; i < count; i++) {
|
||||||
|
NSString *acKey = [NSString stringWithFormat:@"F%ldAc", (long)i];
|
||||||
|
NSString *mnKey = [NSString stringWithFormat:@"F%ldMn", (long)i];
|
||||||
|
NSString *mxKey = [NSString stringWithFormat:@"F%ldMx", (long)i];
|
||||||
|
NSString *tgKey = [NSString stringWithFormat:@"F%ldTg", (long)i];
|
||||||
|
|
||||||
|
NSNumber *ac = [_smcClient readNumericValueForKey:acKey error:nil] ?: @(0.0);
|
||||||
|
NSNumber *mn = [_smcClient readNumericValueForKey:mnKey error:nil] ?: @(0.0);
|
||||||
|
NSNumber *mx = [_smcClient readNumericValueForKey:mxKey error:nil] ?: @(6000.0);
|
||||||
|
NSNumber *tg = [_smcClient readNumericValueForKey:tgKey error:nil] ?: ac;
|
||||||
|
|
||||||
|
[rawList addObject:@{
|
||||||
|
@"currentRPM": ac,
|
||||||
|
@"minRPM": mn,
|
||||||
|
@"maxRPM": mx,
|
||||||
|
@"targetRPM": tg
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [MMFanTelemetryProvider calculateFanMetricsFromFanList:rawList];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#ifndef MMKernelTelemetryProvider_h
|
||||||
|
#define MMKernelTelemetryProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMKernelTelemetryProvider
|
||||||
|
* Samples low-level Mach kernel performance counters: context switches, system calls,
|
||||||
|
* page faults (soft, COW, zero-fill), pageins/pageouts, and computes instantaneous rates per second.
|
||||||
|
*/
|
||||||
|
@interface MMKernelTelemetryProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static calculator method for deterministic unit testing.
|
||||||
|
* Computes event rates per second based on previous and current cumulative counters over delta time.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateRatesWithCurrentCounters:(NSDictionary<NSString *, NSNumber *> *)current
|
||||||
|
previousCounters:(nullable NSDictionary<NSString *, NSNumber *> *)previous
|
||||||
|
timeDelta:(NSTimeInterval)timeDelta;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMKernelTelemetryProvider_h */
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#import "MMKernelTelemetryProvider.h"
|
||||||
|
#import <mach/mach.h>
|
||||||
|
#import <mach/mach_time.h>
|
||||||
|
#import <libproc.h>
|
||||||
|
#import <os/lock.h>
|
||||||
|
|
||||||
|
@interface MMKernelTelemetryProvider () {
|
||||||
|
os_unfair_lock _lock;
|
||||||
|
NSDictionary<NSString *, NSNumber *> *_previousCounters;
|
||||||
|
uint64_t _previousTimestamp;
|
||||||
|
mach_timebase_info_data_t _timebase;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMKernelTelemetryProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_lock = OS_UNFAIR_LOCK_INIT;
|
||||||
|
_previousCounters = nil;
|
||||||
|
_previousTimestamp = 0;
|
||||||
|
mach_timebase_info(&_timebase);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainSystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.kernel.counters";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateRatesWithCurrentCounters:(NSDictionary<NSString *, NSNumber *> *)current
|
||||||
|
previousCounters:(nullable NSDictionary<NSString *, NSNumber *> *)previous
|
||||||
|
timeDelta:(NSTimeInterval)timeDelta {
|
||||||
|
NSMutableDictionary<NSString *, id> *result = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
|
// Copy all current cumulative counters into result
|
||||||
|
[current enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSNumber *val, BOOL *stop) {
|
||||||
|
result[[@"cumulative_" stringByAppendingString:key]] = val;
|
||||||
|
}];
|
||||||
|
|
||||||
|
NSArray<NSString *> *rateKeys = @[
|
||||||
|
@"contextSwitches", @"syscalls", @"pageFaults", @"cowFaults",
|
||||||
|
@"zeroFills", @"pageins", @"pageouts", @"decompressions", @"compressions"
|
||||||
|
];
|
||||||
|
|
||||||
|
for (NSString *key in rateKeys) {
|
||||||
|
double currentVal = [current[key] doubleValue];
|
||||||
|
double prevVal = previous ? [previous[key] doubleValue] : currentVal;
|
||||||
|
double delta = (currentVal >= prevVal) ? (currentVal - prevVal) : 0.0;
|
||||||
|
double rate = (timeDelta > 0.0001) ? (delta / timeDelta) : 0.0;
|
||||||
|
result[[key stringByAppendingString:@"Rate"]] = @(rate);
|
||||||
|
}
|
||||||
|
|
||||||
|
result[@"timeDelta"] = @(timeDelta);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
uint64_t now = mach_absolute_time();
|
||||||
|
|
||||||
|
// 1. Query Mach VM Statistics for page faults, COW, zero fills, pageins/outs
|
||||||
|
vm_statistics64_data_t vmStats;
|
||||||
|
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
|
||||||
|
kern_return_t kr = host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vmStats, &count);
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
if (error) {
|
||||||
|
*error = [NSError errorWithDomain:@"com.i3omb.macmonitor.kernel"
|
||||||
|
code:kr
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey: @"Failed to query host_statistics64"}];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Query process table for cumulative context switches and system calls
|
||||||
|
int pids[4096];
|
||||||
|
int bytes = proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids));
|
||||||
|
int pidCount = bytes / sizeof(int);
|
||||||
|
|
||||||
|
uint64_t totalCSW = 0;
|
||||||
|
uint64_t totalSyscalls = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < pidCount; i++) {
|
||||||
|
if (pids[i] <= 0) continue;
|
||||||
|
struct proc_taskinfo ti;
|
||||||
|
if (proc_pidinfo(pids[i], PROC_PIDTASKINFO, 0, &ti, sizeof(ti)) == sizeof(ti)) {
|
||||||
|
totalCSW += ti.pti_csw;
|
||||||
|
totalSyscalls += (uint64_t)ti.pti_syscalls_unix + (uint64_t)ti.pti_syscalls_mach;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary<NSString *, NSNumber *> *currentCounters = @{
|
||||||
|
@"contextSwitches": @(totalCSW),
|
||||||
|
@"syscalls": @(totalSyscalls),
|
||||||
|
@"pageFaults": @(vmStats.faults),
|
||||||
|
@"cowFaults": @(vmStats.cow_faults),
|
||||||
|
@"zeroFills": @(vmStats.zero_fill_count),
|
||||||
|
@"pageins": @(vmStats.pageins),
|
||||||
|
@"pageouts": @(vmStats.pageouts),
|
||||||
|
@"decompressions": @(vmStats.decompressions),
|
||||||
|
@"compressions": @(vmStats.compressions)
|
||||||
|
};
|
||||||
|
|
||||||
|
os_unfair_lock_lock(&_lock);
|
||||||
|
NSDictionary<NSString *, NSNumber *> *prev = _previousCounters;
|
||||||
|
uint64_t prevTime = _previousTimestamp;
|
||||||
|
|
||||||
|
_previousCounters = currentCounters;
|
||||||
|
_previousTimestamp = now;
|
||||||
|
os_unfair_lock_unlock(&_lock);
|
||||||
|
|
||||||
|
NSTimeInterval timeDelta = 1.0;
|
||||||
|
if (prevTime > 0) {
|
||||||
|
uint64_t elapsed = now - prevTime;
|
||||||
|
timeDelta = (double)elapsed * _timebase.numer / _timebase.denom / 1e9;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [MMKernelTelemetryProvider calculateRatesWithCurrentCounters:currentCounters
|
||||||
|
previousCounters:prev
|
||||||
|
timeDelta:timeDelta];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef MMMemoryTelemetryProvider_h
|
||||||
|
#define MMMemoryTelemetryProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <mach/mach.h>
|
||||||
|
#import <sys/sysctl.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMMemoryTelemetryProvider
|
||||||
|
* Samples Mach virtual memory statistics, wired/active/inactive/compressed memory allocations,
|
||||||
|
* swap usage, and system-wide memory pressure levels.
|
||||||
|
*/
|
||||||
|
@interface MMMemoryTelemetryProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, readonly) uint64_t totalPhysicalMemoryBytes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deterministic helper method for unit testing VM metric calculations.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateMemoryMetricsWithVMInfo:(const vm_statistics64_data_t *)vmInfo
|
||||||
|
pageSize:(vm_size_t)pageSize
|
||||||
|
totalPhysicalRAM:(uint64_t)totalRAM
|
||||||
|
swapUsage:(const struct xsw_usage * _Nullable)swap;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMMemoryTelemetryProvider_h */
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
#import "MMMemoryTelemetryProvider.h"
|
||||||
|
#import <sys/sysctl.h>
|
||||||
|
|
||||||
|
@interface MMMemoryTelemetryProvider () {
|
||||||
|
uint64_t _totalPhysicalMemoryBytes;
|
||||||
|
vm_size_t _pageSize;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMMemoryTelemetryProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
// Read physical memory size
|
||||||
|
uint64_t memSize = 0;
|
||||||
|
size_t size = sizeof(memSize);
|
||||||
|
sysctlbyname("hw.memsize", &memSize, &size, NULL, 0);
|
||||||
|
_totalPhysicalMemoryBytes = memSize;
|
||||||
|
|
||||||
|
// Read virtual memory page size
|
||||||
|
vm_size_t pSize = 4096;
|
||||||
|
host_page_size(mach_host_self(), &pSize);
|
||||||
|
_pageSize = pSize;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainMemory;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.memory";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (uint64_t)totalPhysicalMemoryBytes {
|
||||||
|
return _totalPhysicalMemoryBytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateMemoryMetricsWithVMInfo:(const vm_statistics64_data_t *)vmInfo
|
||||||
|
pageSize:(vm_size_t)pageSize
|
||||||
|
totalPhysicalRAM:(uint64_t)totalRAM
|
||||||
|
swapUsage:(const struct xsw_usage * _Nullable)swap {
|
||||||
|
if (!vmInfo) return @{};
|
||||||
|
|
||||||
|
uint64_t appMemory = (vmInfo->internal_page_count > vmInfo->purgeable_count)
|
||||||
|
? (uint64_t)(vmInfo->internal_page_count - vmInfo->purgeable_count) * pageSize
|
||||||
|
: 0;
|
||||||
|
uint64_t wired = (uint64_t)vmInfo->wire_count * pageSize;
|
||||||
|
uint64_t compressed = (uint64_t)vmInfo->compressor_page_count * pageSize;
|
||||||
|
uint64_t used = appMemory + wired + compressed;
|
||||||
|
|
||||||
|
uint64_t freeRAM = (uint64_t)vmInfo->free_count * pageSize;
|
||||||
|
uint64_t purgeable = (uint64_t)vmInfo->purgeable_count * pageSize;
|
||||||
|
uint64_t active = (uint64_t)vmInfo->active_count * pageSize;
|
||||||
|
uint64_t inactive = (uint64_t)vmInfo->inactive_count * pageSize;
|
||||||
|
|
||||||
|
// Calculate Memory Pressure percentage
|
||||||
|
uint64_t availableForUse = (uint64_t)(vmInfo->free_count + vmInfo->inactive_count) * pageSize;
|
||||||
|
double pressurePct = 0.0;
|
||||||
|
if (totalRAM > 0) {
|
||||||
|
pressurePct = (1.0 - ((double)availableForUse / (double)totalRAM)) * 100.0;
|
||||||
|
if (pressurePct < 0.0) pressurePct = 0.0;
|
||||||
|
if (pressurePct > 100.0) pressurePct = 100.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *pressureStatus = @"Normal";
|
||||||
|
if (pressurePct >= 80.0) {
|
||||||
|
pressureStatus = @"Critical";
|
||||||
|
} else if (pressurePct >= 60.0) {
|
||||||
|
pressureStatus = @"Warning";
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t swapTotal = swap ? swap->xsu_total : 0;
|
||||||
|
uint64_t swapUsed = swap ? swap->xsu_used : 0;
|
||||||
|
uint64_t swapFree = swap ? swap->xsu_avail : 0;
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"totalBytes": @(totalRAM),
|
||||||
|
@"usedBytes": @(used),
|
||||||
|
@"freeBytes": @(freeRAM),
|
||||||
|
@"appMemoryBytes": @(appMemory),
|
||||||
|
@"wiredBytes": @(wired),
|
||||||
|
@"compressedBytes": @(compressed),
|
||||||
|
@"purgeableBytes": @(purgeable),
|
||||||
|
@"activeBytes": @(active),
|
||||||
|
@"inactiveBytes": @(inactive),
|
||||||
|
@"memoryPressurePercent": @(pressurePct),
|
||||||
|
@"memoryPressureStatus": pressureStatus,
|
||||||
|
@"swapTotalBytes": @(swapTotal),
|
||||||
|
@"swapUsedBytes": @(swapUsed),
|
||||||
|
@"swapFreeBytes": @(swapFree)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
vm_statistics64_data_t vmInfo = {0};
|
||||||
|
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
|
||||||
|
|
||||||
|
kern_return_t kr = host_statistics64(
|
||||||
|
mach_host_self(),
|
||||||
|
HOST_VM_INFO64,
|
||||||
|
(host_info64_t)&vmInfo,
|
||||||
|
&count
|
||||||
|
);
|
||||||
|
|
||||||
|
if (kr != KERN_SUCCESS) {
|
||||||
|
if (error) {
|
||||||
|
*error = [NSError errorWithDomain:@"com.i3omb.MacMonitor.Memory"
|
||||||
|
code:kr
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey: @"host_statistics64 failed to sample VM metrics"}];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read swap usage
|
||||||
|
struct xsw_usage swap = {0};
|
||||||
|
size_t swapSize = sizeof(swap);
|
||||||
|
struct xsw_usage *swapPtr = NULL;
|
||||||
|
if (sysctlbyname("vm.swapusage", &swap, &swapSize, NULL, 0) == 0) {
|
||||||
|
swapPtr = &swap;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [MMMemoryTelemetryProvider calculateMemoryMetricsWithVMInfo:&vmInfo
|
||||||
|
pageSize:_pageSize
|
||||||
|
totalPhysicalRAM:_totalPhysicalMemoryBytes
|
||||||
|
swapUsage:swapPtr];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
#ifndef MMPowerTelemetryProvider_h
|
||||||
|
#define MMPowerTelemetryProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
#import "MMAppleSMCClient.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMPowerTelemetryProvider
|
||||||
|
* Samples system power draw, CPU/GPU package wattage, rail voltages, and currents
|
||||||
|
* via AppleSMC and AppleSmartBattery IOKit interfaces.
|
||||||
|
*/
|
||||||
|
@interface MMPowerTelemetryProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, strong, readonly) MMAppleSMCClient *smcClient;
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *discoveredPowerKeys;
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *discoveredVoltageKeys;
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *discoveredCurrentKeys;
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Friendly name for power, voltage, and current SMC keys.
|
||||||
|
*/
|
||||||
|
+ (NSString *)humanReadableNameForKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit of measurement for SMC key ("W", "V", "A").
|
||||||
|
*/
|
||||||
|
+ (NSString *)unitForKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pure calculator method for deterministic unit testing.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculatePowerMetricsWithReadings:(NSDictionary<NSString *, NSNumber *> *)readings
|
||||||
|
batteryInfo:(nullable NSDictionary<NSString *, id> *)batteryInfo;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMPowerTelemetryProvider_h */
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
#import "MMPowerTelemetryProvider.h"
|
||||||
|
#import <IOKit/IOKitLib.h>
|
||||||
|
#import <IOKit/ps/IOPowerSources.h>
|
||||||
|
#import <IOKit/ps/IOPSKeys.h>
|
||||||
|
|
||||||
|
@interface MMPowerTelemetryProvider () {
|
||||||
|
MMAppleSMCClient *_smcClient;
|
||||||
|
NSMutableArray<NSString *> *_discoveredPowerKeys;
|
||||||
|
NSMutableArray<NSString *> *_discoveredVoltageKeys;
|
||||||
|
NSMutableArray<NSString *> *_discoveredCurrentKeys;
|
||||||
|
BOOL _probed;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMPowerTelemetryProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
return [self initWithSMCClient:[MMAppleSMCClient sharedClient]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_smcClient = client;
|
||||||
|
_discoveredPowerKeys = [NSMutableArray array];
|
||||||
|
_discoveredVoltageKeys = [NSMutableArray array];
|
||||||
|
_discoveredCurrentKeys = [NSMutableArray array];
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)probeSensors {
|
||||||
|
if (!_smcClient.isAvailable) return;
|
||||||
|
|
||||||
|
NSArray<NSString *> *powerCandidates = @[
|
||||||
|
@"PSTR", @"PDTR", @"PCPR", @"PCTR", @"PC0C", @"PCPT",
|
||||||
|
@"PG0R", @"PGTR", @"PMSR", @"PM0R", @"PCPC"
|
||||||
|
];
|
||||||
|
|
||||||
|
NSArray<NSString *> *voltageCandidates = @[
|
||||||
|
@"VC0C", @"VD0R", @"VN0C", @"VM0R", @"VP0R"
|
||||||
|
];
|
||||||
|
|
||||||
|
NSArray<NSString *> *currentCandidates = @[
|
||||||
|
@"IC0C", @"ID0R", @"IG0C", @"IM0R"
|
||||||
|
];
|
||||||
|
|
||||||
|
[_discoveredPowerKeys removeAllObjects];
|
||||||
|
for (NSString *key in powerCandidates) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0 && [val doubleValue] < 5000.0) {
|
||||||
|
[_discoveredPowerKeys addObject:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[_discoveredVoltageKeys removeAllObjects];
|
||||||
|
for (NSString *key in voltageCandidates) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0) {
|
||||||
|
[_discoveredVoltageKeys addObject:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[_discoveredCurrentKeys removeAllObjects];
|
||||||
|
for (NSString *key in currentCandidates) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0) {
|
||||||
|
[_discoveredCurrentKeys addObject:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_probed = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainPower;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.power";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return _smcClient.isAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMAppleSMCClient *)smcClient {
|
||||||
|
return _smcClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)discoveredPowerKeys {
|
||||||
|
return [_discoveredPowerKeys copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)discoveredVoltageKeys {
|
||||||
|
return [_discoveredVoltageKeys copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)discoveredCurrentKeys {
|
||||||
|
return [_discoveredCurrentKeys copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString *)unitForKey:(NSString *)key {
|
||||||
|
if ([key hasPrefix:@"P"]) return @"W";
|
||||||
|
if ([key hasPrefix:@"V"]) return @"V";
|
||||||
|
if ([key hasPrefix:@"I"]) return @"A";
|
||||||
|
return @"";
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString *)humanReadableNameForKey:(NSString *)key {
|
||||||
|
static NSDictionary<NSString *, NSString *> *names = nil;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
names = @{
|
||||||
|
@"PSTR": @"Total System Power",
|
||||||
|
@"PDTR": @"DC-In Total Power",
|
||||||
|
@"PCPR": @"CPU Package Power",
|
||||||
|
@"PCTR": @"CPU Total Power",
|
||||||
|
@"PC0C": @"CPU Core Power",
|
||||||
|
@"PCPT": @"CPU Package Total Power",
|
||||||
|
@"PG0R": @"GPU 0 Power",
|
||||||
|
@"PGTR": @"GPU Total Power",
|
||||||
|
@"PMSR": @"Memory Subsystem Power",
|
||||||
|
@"PM0R": @"Memory Rail Power",
|
||||||
|
@"PCPC": @"Power Supply In / AC",
|
||||||
|
@"VC0C": @"CPU Core Voltage",
|
||||||
|
@"VD0R": @"DC-In Rail Voltage",
|
||||||
|
@"VN0C": @"PCH Rail Voltage",
|
||||||
|
@"VM0R": @"Memory Rail Voltage",
|
||||||
|
@"VP0R": @"Power Supply Voltage",
|
||||||
|
@"IC0C": @"CPU Core Current",
|
||||||
|
@"ID0R": @"DC-In Rail Current",
|
||||||
|
@"IG0C": @"GPU Rail Current",
|
||||||
|
@"IM0R": @"Memory Rail Current"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
NSString *match = names[key];
|
||||||
|
return match ?: key;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculatePowerMetricsWithReadings:(NSDictionary<NSString *, NSNumber *> *)readings
|
||||||
|
batteryInfo:(nullable NSDictionary<NSString *, id> *)batteryInfo {
|
||||||
|
// Determine system total power
|
||||||
|
double systemTotal = 0.0;
|
||||||
|
if (readings[@"PSTR"]) {
|
||||||
|
systemTotal = [readings[@"PSTR"] doubleValue];
|
||||||
|
} else if (readings[@"PDTR"]) {
|
||||||
|
systemTotal = [readings[@"PDTR"] doubleValue];
|
||||||
|
} else if (batteryInfo[@"batteryWatts"]) {
|
||||||
|
systemTotal = [batteryInfo[@"batteryWatts"] doubleValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
// CPU wattage
|
||||||
|
double cpuWatts = 0.0;
|
||||||
|
if (readings[@"PCPR"]) {
|
||||||
|
cpuWatts = [readings[@"PCPR"] doubleValue];
|
||||||
|
} else if (readings[@"PCTR"]) {
|
||||||
|
cpuWatts = [readings[@"PCTR"] doubleValue];
|
||||||
|
} else if (readings[@"PC0C"]) {
|
||||||
|
cpuWatts = [readings[@"PC0C"] doubleValue];
|
||||||
|
} else if (readings[@"PCPT"]) {
|
||||||
|
cpuWatts = [readings[@"PCPT"] doubleValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Voltage & Current
|
||||||
|
double cpuVoltage = readings[@"VC0C"] ? [readings[@"VC0C"] doubleValue] : 0.0;
|
||||||
|
double cpuCurrent = readings[@"IC0C"] ? [readings[@"IC0C"] doubleValue] : 0.0;
|
||||||
|
|
||||||
|
// Fallback: calculate cpuWatts from V * I if SMC didn't provide direct wattage
|
||||||
|
if (cpuWatts == 0.0 && cpuVoltage > 0.0 && cpuCurrent > 0.0) {
|
||||||
|
cpuWatts = cpuVoltage * cpuCurrent;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GPU wattage
|
||||||
|
double gpuWatts = 0.0;
|
||||||
|
if (readings[@"PG0R"]) {
|
||||||
|
gpuWatts = [readings[@"PG0R"] doubleValue];
|
||||||
|
} else if (readings[@"PGTR"]) {
|
||||||
|
gpuWatts = [readings[@"PGTR"] doubleValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Memory wattage
|
||||||
|
double memoryWatts = 0.0;
|
||||||
|
if (readings[@"PMSR"]) {
|
||||||
|
memoryWatts = [readings[@"PMSR"] doubleValue];
|
||||||
|
} else if (readings[@"PM0R"]) {
|
||||||
|
memoryWatts = [readings[@"PM0R"] doubleValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect all individual sensor entries
|
||||||
|
NSMutableArray<NSDictionary<NSString *, id> *> *sensors = [NSMutableArray arrayWithCapacity:readings.count];
|
||||||
|
NSArray<NSString *> *sortedKeys = [readings.allKeys sortedArrayUsingSelector:@selector(compare:)];
|
||||||
|
for (NSString *k in sortedKeys) {
|
||||||
|
double val = [readings[k] doubleValue];
|
||||||
|
[sensors addObject:@{
|
||||||
|
@"key": k,
|
||||||
|
@"name": [self humanReadableNameForKey:k],
|
||||||
|
@"value": @(val),
|
||||||
|
@"unit": [self unitForKey:k]
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *powerSource = batteryInfo[@"powerSource"] ?: @"AC Power";
|
||||||
|
BOOL isCharging = [batteryInfo[@"isCharging"] boolValue];
|
||||||
|
double batteryLevel = [batteryInfo[@"batteryLevel"] doubleValue];
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"systemTotalWatts": @(systemTotal),
|
||||||
|
@"cpuWatts": @(cpuWatts),
|
||||||
|
@"gpuWatts": @(gpuWatts),
|
||||||
|
@"memoryWatts": @(memoryWatts),
|
||||||
|
@"cpuVoltage": @(cpuVoltage),
|
||||||
|
@"cpuCurrent": @(cpuCurrent),
|
||||||
|
@"powerSource": powerSource,
|
||||||
|
@"isCharging": @(isCharging),
|
||||||
|
@"batteryLevel": @(batteryLevel),
|
||||||
|
@"sensors": sensors
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleBatteryInfo {
|
||||||
|
CFTypeRef psInfo = IOPSCopyPowerSourcesInfo();
|
||||||
|
if (!psInfo) return nil;
|
||||||
|
|
||||||
|
CFArrayRef psList = IOPSCopyPowerSourcesList(psInfo);
|
||||||
|
if (!psList) {
|
||||||
|
CFRelease(psInfo);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *stateStr = @"AC Power";
|
||||||
|
BOOL isCharging = NO;
|
||||||
|
double capacity = 100.0;
|
||||||
|
|
||||||
|
if (CFArrayGetCount(psList) > 0) {
|
||||||
|
CFTypeRef ps = CFArrayGetValueAtIndex(psList, 0);
|
||||||
|
CFDictionaryRef desc = IOPSGetPowerSourceDescription(psInfo, ps);
|
||||||
|
if (desc) {
|
||||||
|
NSDictionary *dict = (__bridge NSDictionary *)desc;
|
||||||
|
stateStr = dict[@"Power Source State"] ?: @"AC Power";
|
||||||
|
isCharging = [dict[@"Is Charging"] boolValue];
|
||||||
|
if (dict[@"Current Capacity"]) {
|
||||||
|
capacity = [dict[@"Current Capacity"] doubleValue];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CFRelease(psList);
|
||||||
|
CFRelease(psInfo);
|
||||||
|
|
||||||
|
// Sample AppleSmartBattery for instantaneous voltage and current
|
||||||
|
double batteryWatts = 0.0;
|
||||||
|
double batteryVoltage = 0.0;
|
||||||
|
double batteryAmperage = 0.0;
|
||||||
|
|
||||||
|
io_service_t service = IOServiceGetMatchingService(kIOMainPortDefault, IOServiceMatching("AppleSmartBattery"));
|
||||||
|
if (service != IO_OBJECT_NULL) {
|
||||||
|
CFMutableDictionaryRef props = NULL;
|
||||||
|
if (IORegistryEntryCreateCFProperties(service, &props, kCFAllocatorDefault, 0) == KERN_SUCCESS && props) {
|
||||||
|
NSDictionary *dict = (__bridge NSDictionary *)props;
|
||||||
|
double v_mV = [dict[@"Voltage"] doubleValue];
|
||||||
|
double a_mA = dict[@"InstantAmperage"] ? [dict[@"InstantAmperage"] doubleValue] : [dict[@"Amperage"] doubleValue];
|
||||||
|
|
||||||
|
batteryVoltage = v_mV / 1000.0;
|
||||||
|
batteryAmperage = fabs(a_mA) / 1000.0;
|
||||||
|
batteryWatts = batteryVoltage * batteryAmperage;
|
||||||
|
|
||||||
|
CFRelease(props);
|
||||||
|
}
|
||||||
|
IOObjectRelease(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"powerSource": stateStr,
|
||||||
|
@"isCharging": @(isCharging),
|
||||||
|
@"batteryLevel": @(capacity),
|
||||||
|
@"batteryVoltage": @(batteryVoltage),
|
||||||
|
@"batteryAmperage": @(batteryAmperage),
|
||||||
|
@"batteryWatts": @(batteryWatts)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
if (!_probed && _smcClient.isAvailable) {
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableDictionary<NSString *, NSNumber *> *readings = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
|
NSMutableArray<NSString *> *allKeys = [NSMutableArray arrayWithArray:_discoveredPowerKeys];
|
||||||
|
[allKeys addObjectsFromArray:_discoveredVoltageKeys];
|
||||||
|
[allKeys addObjectsFromArray:_discoveredCurrentKeys];
|
||||||
|
|
||||||
|
for (NSString *key in allKeys) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val) {
|
||||||
|
double v = [val doubleValue];
|
||||||
|
// Normalize mV or mA if values appear raw
|
||||||
|
if ([key hasPrefix:@"V"] && v > 100.0) {
|
||||||
|
v /= 1000.0;
|
||||||
|
} else if ([key hasPrefix:@"I"] && v > 500.0) {
|
||||||
|
v /= 1000.0;
|
||||||
|
}
|
||||||
|
readings[key] = @(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSDictionary<NSString *, id> *batteryInfo = [self sampleBatteryInfo];
|
||||||
|
return [MMPowerTelemetryProvider calculatePowerMetricsWithReadings:readings
|
||||||
|
batteryInfo:batteryInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef MMStorageTelemetryProvider_h
|
||||||
|
#define MMStorageTelemetryProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import <sys/mount.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMStorageTelemetryProvider
|
||||||
|
* Samples mounted disk volumes, APFS containers, used/free storage capacity,
|
||||||
|
* and mount filesystem attributes.
|
||||||
|
*/
|
||||||
|
@interface MMStorageTelemetryProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static parser method for converting statfs structures into volume dictionaries.
|
||||||
|
*/
|
||||||
|
+ (NSArray<NSDictionary<NSString *, id> *> *)parseStatFSBuffer:(const struct statfs *)buffer count:(int)count;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMStorageTelemetryProvider_h */
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
#import "MMStorageTelemetryProvider.h"
|
||||||
|
|
||||||
|
@implementation MMStorageTelemetryProvider
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.storage";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSArray<NSDictionary<NSString *, id> *> *)parseStatFSBuffer:(const struct statfs *)buffer count:(int)count {
|
||||||
|
if (!buffer || count <= 0) return @[];
|
||||||
|
|
||||||
|
NSMutableArray<NSDictionary<NSString *, id> *> *volumes = [NSMutableArray arrayWithCapacity:count];
|
||||||
|
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
const struct statfs *mnt = &buffer[i];
|
||||||
|
|
||||||
|
// Only include local mounts
|
||||||
|
if (!(mnt->f_flags & MNT_LOCAL)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString *mountPoint = [NSString stringWithUTF8String:mnt->f_mntonname];
|
||||||
|
NSString *deviceName = [NSString stringWithUTF8String:mnt->f_mntfromname];
|
||||||
|
NSString *fsType = [NSString stringWithUTF8String:mnt->f_fstypename];
|
||||||
|
|
||||||
|
// Exclude virtual/internal devfs, autodefs, and synthetic system roots
|
||||||
|
if ([fsType isEqualToString:@"devfs"] ||
|
||||||
|
[fsType isEqualToString:@"autofs"] ||
|
||||||
|
[mountPoint hasPrefix:@"/System/Volumes/Data/"] ||
|
||||||
|
[deviceName containsString:@"com.apple.os.update"]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t blockSize = (uint64_t)mnt->f_bsize;
|
||||||
|
uint64_t totalBytes = (uint64_t)mnt->f_blocks * blockSize;
|
||||||
|
uint64_t freeBytes = (uint64_t)mnt->f_bfree * blockSize;
|
||||||
|
uint64_t availBytes = (uint64_t)mnt->f_bavail * blockSize;
|
||||||
|
uint64_t usedBytes = (totalBytes >= freeBytes) ? (totalBytes - freeBytes) : 0;
|
||||||
|
|
||||||
|
if (totalBytes == 0) continue;
|
||||||
|
|
||||||
|
double usedPercent = ((double)usedBytes / (double)totalBytes) * 100.0;
|
||||||
|
if (usedPercent < 0.0) usedPercent = 0.0;
|
||||||
|
if (usedPercent > 100.0) usedPercent = 100.0;
|
||||||
|
|
||||||
|
NSString *volumeName = [mountPoint lastPathComponent];
|
||||||
|
if ([mountPoint isEqualToString:@"/"]) {
|
||||||
|
volumeName = @"Macintosh HD";
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL isReadOnly = (mnt->f_flags & MNT_RDONLY) != 0;
|
||||||
|
|
||||||
|
[volumes addObject:@{
|
||||||
|
@"volumeName": volumeName,
|
||||||
|
@"mountPoint": mountPoint,
|
||||||
|
@"devicePath": deviceName,
|
||||||
|
@"fsType": fsType,
|
||||||
|
@"totalBytes": @(totalBytes),
|
||||||
|
@"usedBytes": @(usedBytes),
|
||||||
|
@"freeBytes": @(freeBytes),
|
||||||
|
@"availableBytes": @(availBytes),
|
||||||
|
@"usedPercent": @(usedPercent),
|
||||||
|
@"isReadOnly": @(isReadOnly)
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [volumes copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
struct statfs *mntbuf = NULL;
|
||||||
|
int count = getmntinfo(&mntbuf, MNT_WAIT);
|
||||||
|
|
||||||
|
if (count <= 0 || mntbuf == NULL) {
|
||||||
|
if (error) {
|
||||||
|
*error = [NSError errorWithDomain:@"com.i3omb.MacMonitor.Storage"
|
||||||
|
code:-1
|
||||||
|
userInfo:@{NSLocalizedDescriptionKey: @"getmntinfo returned no mounted filesystems"}];
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSArray *volumes = [MMStorageTelemetryProvider parseStatFSBuffer:mntbuf count:count];
|
||||||
|
|
||||||
|
uint64_t totalStorage = 0;
|
||||||
|
uint64_t totalUsed = 0;
|
||||||
|
for (NSDictionary *v in volumes) {
|
||||||
|
totalStorage += [v[@"totalBytes"] unsignedLongLongValue];
|
||||||
|
totalUsed += [v[@"usedBytes"] unsignedLongLongValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"volumes": volumes,
|
||||||
|
@"volumeCount": @(volumes.count),
|
||||||
|
@"aggregateTotalBytes": @(totalStorage),
|
||||||
|
@"aggregateUsedBytes": @(totalUsed)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef MMCPUThermalProvider_h
|
||||||
|
#define MMCPUThermalProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
#import "MMAppleSMCClient.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMCPUThermalProvider
|
||||||
|
* Samples real-time CPU die, proximity, and per-core temperature sensors from AppleSMC
|
||||||
|
* alongside OS thermal pressure states.
|
||||||
|
*/
|
||||||
|
@interface MMCPUThermalProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, strong, readonly) MMAppleSMCClient *smcClient;
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *discoveredCoreKeys;
|
||||||
|
@property (nonatomic, readonly, nullable) NSString *packageKey;
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static calculator method for deterministic unit testing.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateThermalMetricsWithPackageTemp:(nullable NSNumber *)pkgTemp
|
||||||
|
coreTemps:(NSDictionary<NSString *, NSNumber *> *)coreDict
|
||||||
|
thermalState:(NSProcessInfoThermalState)state;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMCPUThermalProvider_h */
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
#import "MMCPUThermalProvider.h"
|
||||||
|
#import <sys/sysctl.h>
|
||||||
|
|
||||||
|
@interface MMCPUThermalProvider () {
|
||||||
|
MMAppleSMCClient *_smcClient;
|
||||||
|
NSMutableArray<NSString *> *_discoveredCoreKeys;
|
||||||
|
NSString *_packageKey;
|
||||||
|
BOOL _probed;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMCPUThermalProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
return [self initWithSMCClient:[MMAppleSMCClient sharedClient]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_smcClient = client;
|
||||||
|
_discoveredCoreKeys = [NSMutableArray array];
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)probeSensors {
|
||||||
|
if (!_smcClient.isAvailable) return;
|
||||||
|
|
||||||
|
// Probe package temperature key
|
||||||
|
NSArray<NSString *> *packageCandidates = @[@"TC0P", @"TC0D", @"TC0H", @"TCXC"];
|
||||||
|
for (NSString *candidate in packageCandidates) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:candidate error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0 && [val doubleValue] < 125.0) {
|
||||||
|
_packageKey = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Probe core keys (TC0C, TC1C, etc.)
|
||||||
|
int coreCount = 1;
|
||||||
|
size_t size = sizeof(coreCount);
|
||||||
|
sysctlbyname("hw.physicalcpu", &coreCount, &size, NULL, 0);
|
||||||
|
if (coreCount <= 0) coreCount = 4;
|
||||||
|
|
||||||
|
for (int i = 0; i < coreCount && i < 32; i++) {
|
||||||
|
NSString *key = [NSString stringWithFormat:@"TC%dC", i];
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0 && [val doubleValue] < 125.0) {
|
||||||
|
[_discoveredCoreKeys addObject:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_probed = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainThermal;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.thermal.cpu";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return _smcClient.isAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMAppleSMCClient *)smcClient {
|
||||||
|
return _smcClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)discoveredCoreKeys {
|
||||||
|
return [_discoveredCoreKeys copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)packageKey {
|
||||||
|
return _packageKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateThermalMetricsWithPackageTemp:(nullable NSNumber *)pkgTemp
|
||||||
|
coreTemps:(NSDictionary<NSString *, NSNumber *> *)coreDict
|
||||||
|
thermalState:(NSProcessInfoThermalState)state {
|
||||||
|
double peak = pkgTemp ? [pkgTemp doubleValue] : 0.0;
|
||||||
|
double sum = 0.0;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
NSMutableArray<NSDictionary<NSString *, id> *> *coresList = [NSMutableArray arrayWithCapacity:coreDict.count];
|
||||||
|
NSArray<NSString *> *sortedKeys = [coreDict.allKeys sortedArrayUsingSelector:@selector(compare:)];
|
||||||
|
|
||||||
|
for (NSUInteger idx = 0; idx < sortedKeys.count; idx++) {
|
||||||
|
NSString *k = sortedKeys[idx];
|
||||||
|
double temp = [coreDict[k] doubleValue];
|
||||||
|
if (temp > peak) peak = temp;
|
||||||
|
sum += temp;
|
||||||
|
count++;
|
||||||
|
|
||||||
|
[coresList addObject:@{
|
||||||
|
@"coreIndex": @(idx),
|
||||||
|
@"key": k,
|
||||||
|
@"temperature": @(temp)
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
double avg = (count > 0) ? (sum / count) : (pkgTemp ? [pkgTemp doubleValue] : 0.0);
|
||||||
|
|
||||||
|
NSString *stateStr = @"Nominal";
|
||||||
|
switch (state) {
|
||||||
|
case NSProcessInfoThermalStateNominal: stateStr = @"Nominal"; break;
|
||||||
|
case NSProcessInfoThermalStateFair: stateStr = @"Fair"; break;
|
||||||
|
case NSProcessInfoThermalStateSerious: stateStr = @"Serious"; break;
|
||||||
|
case NSProcessInfoThermalStateCritical: stateStr = @"Critical"; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"packageTemperature": pkgTemp ?: @(0.0),
|
||||||
|
@"averageCoreTemperature": @(avg),
|
||||||
|
@"peakCoreTemperature": @(peak),
|
||||||
|
@"coreTemperatures": coresList,
|
||||||
|
@"thermalPressureState": stateStr,
|
||||||
|
@"isThrottling": @(state >= NSProcessInfoThermalStateSerious)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
if (!_probed && _smcClient.isAvailable) {
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSNumber *pkgTemp = nil;
|
||||||
|
if (_packageKey) {
|
||||||
|
pkgTemp = [_smcClient readNumericValueForKey:_packageKey error:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableDictionary<NSString *, NSNumber *> *coreTemps = [NSMutableDictionary dictionary];
|
||||||
|
for (NSString *coreKey in _discoveredCoreKeys) {
|
||||||
|
NSNumber *t = [_smcClient readNumericValueForKey:coreKey error:nil];
|
||||||
|
if (t) {
|
||||||
|
coreTemps[coreKey] = t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NSProcessInfoThermalState thermalState = [NSProcessInfo processInfo].thermalState;
|
||||||
|
|
||||||
|
return [MMCPUThermalProvider calculateThermalMetricsWithPackageTemp:pkgTemp
|
||||||
|
coreTemps:coreTemps
|
||||||
|
thermalState:thermalState];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#ifndef MMComponentThermalProvider_h
|
||||||
|
#define MMComponentThermalProvider_h
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "MMTelemetryProvider.h"
|
||||||
|
#import "MMAppleSMCClient.h"
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MMComponentThermalProvider
|
||||||
|
* Samples motherboard, PCH chipset, heatsink, memory, and enclosure ambient temperatures
|
||||||
|
* via AppleSMC.
|
||||||
|
*/
|
||||||
|
@interface MMComponentThermalProvider : NSObject <MMTelemetryProvider>
|
||||||
|
|
||||||
|
@property (nonatomic, strong, readonly) MMAppleSMCClient *smcClient;
|
||||||
|
@property (nonatomic, readonly) NSArray<NSString *> *discoveredKeys;
|
||||||
|
|
||||||
|
- (instancetype)init;
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Categorize SMC temperature key into component domain (e.g., PCH / Chipset, Heatsink, Memory, etc.)
|
||||||
|
*/
|
||||||
|
+ (NSString *)categoryForKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Human-readable friendly name for known component SMC keys.
|
||||||
|
*/
|
||||||
|
+ (NSString *)humanReadableNameForKey:(NSString *)key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static calculator method for deterministic unit testing.
|
||||||
|
*/
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateComponentMetricsFromDictionary:(NSDictionary<NSString *, NSNumber *> *)readings;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
#endif /* MMComponentThermalProvider_h */
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
#import "MMComponentThermalProvider.h"
|
||||||
|
|
||||||
|
@interface MMComponentThermalProvider () {
|
||||||
|
MMAppleSMCClient *_smcClient;
|
||||||
|
NSMutableArray<NSString *> *_discoveredKeys;
|
||||||
|
BOOL _probed;
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation MMComponentThermalProvider
|
||||||
|
|
||||||
|
- (instancetype)init {
|
||||||
|
return [self initWithSMCClient:[MMAppleSMCClient sharedClient]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithSMCClient:(MMAppleSMCClient *)client {
|
||||||
|
self = [super init];
|
||||||
|
if (self) {
|
||||||
|
_smcClient = client;
|
||||||
|
_discoveredKeys = [NSMutableArray array];
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)probeSensors {
|
||||||
|
if (!_smcClient.isAvailable) return;
|
||||||
|
|
||||||
|
NSArray<NSString *> *candidates = @[
|
||||||
|
@"TPCD", @"TP0P", @"TP0D",
|
||||||
|
@"Th0H", @"Th1H", @"Th2H", @"Th3H",
|
||||||
|
@"TM0P", @"TM1P", @"TM2P", @"TM3P", @"TM0S", @"TM1S",
|
||||||
|
@"Tp0P", @"Tp1P", @"Tp2P", @"Tp0C",
|
||||||
|
@"TA0P", @"TA1P", @"TA0S", @"TA1S",
|
||||||
|
@"TTLD", @"TT1D", @"TB0T", @"TB1T"
|
||||||
|
];
|
||||||
|
|
||||||
|
[_discoveredKeys removeAllObjects];
|
||||||
|
for (NSString *key in candidates) {
|
||||||
|
NSNumber *val = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (val && [val doubleValue] > 0.0 && [val doubleValue] < 125.0) {
|
||||||
|
[_discoveredKeys addObject:key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_probed = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMTelemetryDomain)domain {
|
||||||
|
return MMTelemetryDomainThermal;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)providerIdentifier {
|
||||||
|
return @"com.i3omb.macmonitor.telemetry.thermal.components";
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)isAvailable {
|
||||||
|
return _smcClient.isAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (MMAppleSMCClient *)smcClient {
|
||||||
|
return _smcClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSArray<NSString *> *)discoveredKeys {
|
||||||
|
return [_discoveredKeys copy];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString *)categoryForKey:(NSString *)key {
|
||||||
|
if ([key hasPrefix:@"TP"]) return @"PCH / Chipset";
|
||||||
|
if ([key hasPrefix:@"Th"]) return @"Heatsink";
|
||||||
|
if ([key hasPrefix:@"TM"]) return @"Memory";
|
||||||
|
if ([key hasPrefix:@"Tp"]) return @"Power Supply";
|
||||||
|
if ([key hasPrefix:@"TA"]) return @"Ambient / Enclosure";
|
||||||
|
if ([key hasPrefix:@"TT"] || [key hasPrefix:@"TB"] || [key hasPrefix:@"TI"]) return @"Thunderbolt / IO";
|
||||||
|
return @"Other";
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString *)humanReadableNameForKey:(NSString *)key {
|
||||||
|
static NSDictionary<NSString *, NSString *> *names = nil;
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
names = @{
|
||||||
|
@"TPCD": @"Platform Controller Hub (Die)",
|
||||||
|
@"TP0P": @"Platform Controller Hub (Proximity)",
|
||||||
|
@"TP0D": @"Platform Controller Hub (Die Alternate)",
|
||||||
|
@"Th0H": @"Main Heatsink A",
|
||||||
|
@"Th1H": @"Main Heatsink B",
|
||||||
|
@"Th2H": @"Main Heatsink C",
|
||||||
|
@"Th3H": @"Main Heatsink D",
|
||||||
|
@"TM0P": @"Memory Bank 0 Proximity",
|
||||||
|
@"TM1P": @"Memory Bank 1 Proximity",
|
||||||
|
@"TM2P": @"Memory Bank 2 Proximity",
|
||||||
|
@"TM3P": @"Memory Bank 3 Proximity",
|
||||||
|
@"TM0S": @"Memory Module 0",
|
||||||
|
@"TM1S": @"Memory Module 1",
|
||||||
|
@"Tp0P": @"Power Supply Primary",
|
||||||
|
@"Tp1P": @"Power Supply Secondary",
|
||||||
|
@"Tp2P": @"Power Supply Tertiary",
|
||||||
|
@"Tp0C": @"Power Supply Core",
|
||||||
|
@"TA0P": @"Ambient Air Intake",
|
||||||
|
@"TA1P": @"Ambient Air Exhaust",
|
||||||
|
@"TA0S": @"Ambient Air Enclosure",
|
||||||
|
@"TA1S": @"Ambient Air Secondary",
|
||||||
|
@"TTLD": @"Thunderbolt Controller Die",
|
||||||
|
@"TT1D": @"Thunderbolt Controller Secondary",
|
||||||
|
@"TB0T": @"Thunderbolt Port 0",
|
||||||
|
@"TB1T": @"Thunderbolt Port 1"
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
NSString *match = names[key];
|
||||||
|
return match ?: key;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSDictionary<NSString *, id> *)calculateComponentMetricsFromDictionary:(NSDictionary<NSString *, NSNumber *> *)readings {
|
||||||
|
NSMutableArray<NSDictionary<NSString *, id> *> *components = [NSMutableArray arrayWithCapacity:readings.count];
|
||||||
|
NSMutableDictionary<NSString *, NSMutableArray<NSDictionary<NSString *, id> *> *> *categorized = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
|
NSArray<NSString *> *sortedKeys = [readings.allKeys sortedArrayUsingSelector:@selector(compare:)];
|
||||||
|
double peak = 0.0;
|
||||||
|
double sum = 0.0;
|
||||||
|
|
||||||
|
for (NSString *k in sortedKeys) {
|
||||||
|
double temp = [readings[k] doubleValue];
|
||||||
|
if (temp > peak) peak = temp;
|
||||||
|
sum += temp;
|
||||||
|
|
||||||
|
NSString *cat = [self categoryForKey:k];
|
||||||
|
NSString *name = [self humanReadableNameForKey:k];
|
||||||
|
|
||||||
|
NSDictionary<NSString *, id> *entry = @{
|
||||||
|
@"key": k,
|
||||||
|
@"name": name,
|
||||||
|
@"category": cat,
|
||||||
|
@"temperature": @(temp)
|
||||||
|
};
|
||||||
|
|
||||||
|
[components addObject:entry];
|
||||||
|
|
||||||
|
if (!categorized[cat]) {
|
||||||
|
categorized[cat] = [NSMutableArray array];
|
||||||
|
}
|
||||||
|
[categorized[cat] addObject:entry];
|
||||||
|
}
|
||||||
|
|
||||||
|
double avg = readings.count > 0 ? (sum / (double)readings.count) : 0.0;
|
||||||
|
|
||||||
|
return @{
|
||||||
|
@"components": components,
|
||||||
|
@"categorized": categorized,
|
||||||
|
@"sensorCount": @(readings.count),
|
||||||
|
@"peakTemperature": @(peak),
|
||||||
|
@"averageTemperature": @(avg)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
- (nullable NSDictionary<NSString *, id> *)sampleTelemetryWithError:(NSError **)error {
|
||||||
|
if (!_probed && _smcClient.isAvailable) {
|
||||||
|
[self probeSensors];
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableDictionary<NSString *, NSNumber *> *readings = [NSMutableDictionary dictionary];
|
||||||
|
for (NSString *key in _discoveredKeys) {
|
||||||
|
NSNumber *temp = [_smcClient readNumericValueForKey:key error:nil];
|
||||||
|
if (temp) {
|
||||||
|
readings[key] = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [MMComponentThermalProvider calculateComponentMetricsFromDictionary:readings];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
+495
-82
@@ -2,6 +2,7 @@ import SwiftUI
|
|||||||
|
|
||||||
public struct ContentView: View {
|
public struct ContentView: View {
|
||||||
@State private var store = SystemTelemetryStore.shared
|
@State private var store = SystemTelemetryStore.shared
|
||||||
|
@State private var selectedTab: String = "Dashboard"
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
@@ -11,59 +12,111 @@ public struct ContentView: View {
|
|||||||
} detail: {
|
} detail: {
|
||||||
detailContent
|
detailContent
|
||||||
}
|
}
|
||||||
.frame(minWidth: 800, minHeight: 520)
|
.frame(minWidth: 900, minHeight: 650)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
store.start()
|
store.start()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Sidebar
|
||||||
private var sidebarContent: some View {
|
private var sidebarContent: some View {
|
||||||
List {
|
List(selection: $selectedTab) {
|
||||||
Section("System Status") {
|
Section("Overview") {
|
||||||
Label("Dashboard", systemImage: "gauge.with.needle")
|
Label("Dashboard", systemImage: "gauge.with.needle")
|
||||||
Label("Architecture", systemImage: "cpu")
|
.tag("Dashboard")
|
||||||
|
Label("Hardware Architecture", systemImage: "cpu")
|
||||||
|
.tag("Architecture")
|
||||||
}
|
}
|
||||||
|
|
||||||
Section("Telemetry Domains") {
|
Section("Primary Telemetry") {
|
||||||
Label("CPU & Thermals", systemImage: "flame")
|
Label("CPU Load & Cores", systemImage: "chart.bar.xaxis")
|
||||||
|
.tag("CPU")
|
||||||
|
Label("Thermal Matrix", systemImage: "flame")
|
||||||
|
.tag("Thermals")
|
||||||
Label("Fans & Cooling", systemImage: "fanblades")
|
Label("Fans & Cooling", systemImage: "fanblades")
|
||||||
|
.tag("Fans")
|
||||||
Label("Memory & Swap", systemImage: "memorychip")
|
Label("Memory & Swap", systemImage: "memorychip")
|
||||||
Label("Disks & Volumes", systemImage: "internaldrive")
|
.tag("Memory")
|
||||||
Label("Processes", systemImage: "list.bullet.rectangle")
|
Label("Storage Volumes", systemImage: "internaldrive")
|
||||||
Label("Network", systemImage: "network")
|
.tag("Storage")
|
||||||
Label("Graphics (GPU)", systemImage: "display")
|
Label("Power & Voltage", systemImage: "bolt.fill")
|
||||||
|
.tag("Power")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.listStyle(.sidebar)
|
.listStyle(.sidebar)
|
||||||
.navigationSplitViewColumnWidth(min: 200, ideal: 220, max: 280)
|
.navigationSplitViewColumnWidth(min: 200, ideal: 230, max: 280)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Detail Content Router
|
||||||
|
@ViewBuilder
|
||||||
private var detailContent: some View {
|
private var detailContent: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
VStack(alignment: .leading, spacing: 20) {
|
VStack(alignment: .leading, spacing: 20) {
|
||||||
// Header Banner
|
|
||||||
headerCard
|
headerCard
|
||||||
|
|
||||||
// Telemetry Engine Control
|
|
||||||
engineControlCard
|
engineControlCard
|
||||||
|
|
||||||
// System Specifications
|
switch selectedTab {
|
||||||
specsCard
|
case "Dashboard":
|
||||||
|
dashboardView
|
||||||
// Providers Status
|
case "Architecture":
|
||||||
providersCard
|
specsCard
|
||||||
|
providersCard
|
||||||
|
case "CPU":
|
||||||
|
cpuLoadCard
|
||||||
|
specsCard
|
||||||
|
case "Thermals":
|
||||||
|
cpuThermalCard
|
||||||
|
componentThermalCard
|
||||||
|
case "Fans":
|
||||||
|
fansCard
|
||||||
|
case "Memory":
|
||||||
|
memoryCard
|
||||||
|
case "Storage":
|
||||||
|
storageCard
|
||||||
|
case "Power":
|
||||||
|
powerCard
|
||||||
|
default:
|
||||||
|
dashboardView
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding(24)
|
.padding(24)
|
||||||
}
|
}
|
||||||
.navigationTitle("MacMonitor Dashboard")
|
.navigationTitle("MacMonitor — \(selectedTab)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Dashboard Composite View
|
||||||
|
private var dashboardView: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 20) {
|
||||||
|
// Top Row: CPU & Memory Summary Cards
|
||||||
|
HStack(alignment: .top, spacing: 16) {
|
||||||
|
cpuLoadCard
|
||||||
|
memoryCard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Middle Row: Thermals & Fans Summary Cards
|
||||||
|
HStack(alignment: .top, spacing: 16) {
|
||||||
|
cpuThermalCard
|
||||||
|
fansCard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Power & Storage Summary
|
||||||
|
HStack(alignment: .top, spacing: 16) {
|
||||||
|
powerCard
|
||||||
|
storageCard
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detailed Component Thermals Matrix
|
||||||
|
componentThermalCard
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Header Banner
|
||||||
private var headerCard: some View {
|
private var headerCard: some View {
|
||||||
HStack(alignment: .center, spacing: 16) {
|
HStack(alignment: .center, spacing: 16) {
|
||||||
Image(systemName: "macpro.gen3.fill")
|
Image(systemName: "macpro.gen3.fill")
|
||||||
.resizable()
|
.resizable()
|
||||||
.scaledToFit()
|
.scaledToFit()
|
||||||
.frame(width: 48, height: 48)
|
.frame(width: 44, height: 44)
|
||||||
.foregroundStyle(.blue)
|
.foregroundStyle(.blue)
|
||||||
|
|
||||||
VStack(alignment: .leading, spacing: 4) {
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
@@ -80,7 +133,7 @@ public struct ContentView: View {
|
|||||||
Circle()
|
Circle()
|
||||||
.fill(store.isRunning ? Color.green : Color.red)
|
.fill(store.isRunning ? Color.green : Color.red)
|
||||||
.frame(width: 10, height: 10)
|
.frame(width: 10, height: 10)
|
||||||
Text(store.isRunning ? "ENGINE ACTIVE" : "ENGINE PAUSED")
|
Text(store.isRunning ? "ACTIVE" : "PAUSED")
|
||||||
.font(.caption.bold())
|
.font(.caption.bold())
|
||||||
.foregroundStyle(store.isRunning ? .green : .secondary)
|
.foregroundStyle(store.isRunning ? .green : .secondary)
|
||||||
}
|
}
|
||||||
@@ -93,55 +146,307 @@ public struct ContentView: View {
|
|||||||
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Telemetry Coordinator Controls
|
||||||
private var engineControlCard: some View {
|
private var engineControlCard: some View {
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
HStack(spacing: 16) {
|
||||||
Text("Telemetry Coordinator Engine")
|
Button(action: {
|
||||||
.font(.headline)
|
if store.isRunning { store.stop() } else { store.start() }
|
||||||
|
}) {
|
||||||
|
Label(store.isRunning ? "Pause Engine" : "Start Engine",
|
||||||
|
systemImage: store.isRunning ? "pause.fill" : "play.fill")
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(store.isRunning ? .orange : .green)
|
||||||
|
|
||||||
HStack(spacing: 16) {
|
Button(action: { store.triggerManualSample() }) {
|
||||||
Button(action: {
|
Label("Sample Now", systemImage: "arrow.clockwise")
|
||||||
if store.isRunning {
|
}
|
||||||
store.stop()
|
.buttonStyle(.bordered)
|
||||||
} else {
|
|
||||||
store.start()
|
Spacer()
|
||||||
}
|
|
||||||
}) {
|
Picker("Interval:", selection: Binding(
|
||||||
Label(store.isRunning ? "Pause Engine" : "Start Engine",
|
get: { store.sampleInterval },
|
||||||
systemImage: store.isRunning ? "pause.fill" : "play.fill")
|
set: { store.setSampleInterval($0) }
|
||||||
}
|
)) {
|
||||||
.buttonStyle(.borderedProminent)
|
Text("0.5s").tag(0.5)
|
||||||
.tint(store.isRunning ? .orange : .green)
|
Text("1.0s").tag(1.0)
|
||||||
|
Text("2.0s").tag(2.0)
|
||||||
Button(action: {
|
Text("5.0s").tag(5.0)
|
||||||
store.triggerManualSample()
|
}
|
||||||
}) {
|
.pickerStyle(.segmented)
|
||||||
Label("Sample Now", systemImage: "arrow.clockwise")
|
.frame(width: 220)
|
||||||
}
|
|
||||||
.buttonStyle(.bordered)
|
Text("Updated: \(store.lastUpdateTimestamp.formatted(date: .omitted, time: .standard))")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.padding(14)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - CPU Load Card
|
||||||
|
private var cpuLoadCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("CPU Activity", systemImage: "cpu")
|
||||||
|
.font(.headline)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
if store.cpuLoad.isThrottled {
|
||||||
Picker("Polling Interval:", selection: Binding(
|
Text("THROTTLED")
|
||||||
get: { store.sampleInterval },
|
.font(.caption.bold())
|
||||||
set: { store.setSampleInterval($0) }
|
.foregroundStyle(.red)
|
||||||
)) {
|
.padding(.horizontal, 6)
|
||||||
Text("0.5s").tag(0.5)
|
.padding(.vertical, 2)
|
||||||
Text("1.0s").tag(1.0)
|
.background(Color.red.opacity(0.15), in: Capsule())
|
||||||
Text("2.0s").tag(2.0)
|
|
||||||
Text("5.0s").tag(5.0)
|
|
||||||
}
|
}
|
||||||
.pickerStyle(.segmented)
|
Text(String(format: "%.1f%%", store.cpuLoad.totalLoad))
|
||||||
.frame(width: 220)
|
.font(.title3.bold().monospacedDigit())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ProgressView(value: min(store.cpuLoad.totalLoad / 100.0, 1.0))
|
||||||
|
.tint(store.cpuLoad.totalLoad > 85 ? .red : (store.cpuLoad.totalLoad > 60 ? .orange : .blue))
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("Last Sample Cycle: \(store.lastUpdateTimestamp.formatted(date: .omitted, time: .standard))")
|
Text("User: \(String(format: "%.1f%%", store.cpuLoad.userLoad))")
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
Spacer()
|
Spacer()
|
||||||
Text("Queue: com.i3omb.macmonitor.telemetry (QOS_UTILITY)")
|
Text("System: \(String(format: "%.1f%%", store.cpuLoad.systemLoad))")
|
||||||
|
Spacer()
|
||||||
|
Text("Idle: \(String(format: "%.1f%%", store.cpuLoad.idleLoad))")
|
||||||
|
}
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
|
||||||
|
if !store.cpuLoad.perCoreLoad.isEmpty {
|
||||||
|
Divider()
|
||||||
|
Text("Per-Core Utilization (\(store.cpuLoad.perCoreLoad.count) Cores)")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
|
||||||
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 70))], spacing: 8) {
|
||||||
|
ForEach(Array(store.cpuLoad.perCoreLoad.enumerated()), id: \.offset) { idx, load in
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
Text("Core \(idx)")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
ProgressView(value: min(load / 100.0, 1.0))
|
||||||
|
.tint(load > 85 ? .red : .blue)
|
||||||
|
Text(String(format: "%.0f%%", load))
|
||||||
|
.font(.system(size: 10, weight: .bold, design: .monospaced))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Memory & Swap Card
|
||||||
|
private var memoryCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("Memory & Swap", systemImage: "memorychip")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text(store.memory.pressureLevel)
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(pressureColor(store.memory.pressureLevel))
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background(pressureColor(store.memory.pressureLevel).opacity(0.15), in: Capsule())
|
||||||
|
Text(String(format: "%.1f%%", store.memory.utilizationPercentage))
|
||||||
|
.font(.title3.bold().monospacedDigit())
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressView(value: min(store.memory.utilizationPercentage / 100.0, 1.0))
|
||||||
|
.tint(pressureColor(store.memory.pressureLevel))
|
||||||
|
|
||||||
|
Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 6) {
|
||||||
|
GridRow {
|
||||||
|
Text("Physical RAM:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.totalBytes)).bold()
|
||||||
|
Text("Used:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.usedBytes)).bold()
|
||||||
|
}
|
||||||
|
GridRow {
|
||||||
|
Text("Wired:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.wiredBytes))
|
||||||
|
Text("Compressed:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.compressedBytes))
|
||||||
|
}
|
||||||
|
GridRow {
|
||||||
|
Text("Active:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.activeBytes))
|
||||||
|
Text("Free / Inactive:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.freeBytes + store.memory.inactiveBytes))
|
||||||
|
}
|
||||||
|
if store.memory.swapTotalBytes > 0 {
|
||||||
|
GridRow {
|
||||||
|
Text("Swap Total:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.swapTotalBytes))
|
||||||
|
Text("Swap Used:").foregroundStyle(.secondary)
|
||||||
|
Text(formatBytes(store.memory.swapUsedBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.font(.caption)
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - CPU Thermal Card
|
||||||
|
private var cpuThermalCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("CPU Thermals", systemImage: "flame.fill")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text(store.cpuThermal.thermalPressureState)
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(store.cpuThermal.isThrottling ? .red : .green)
|
||||||
|
.padding(.horizontal, 6)
|
||||||
|
.padding(.vertical, 2)
|
||||||
|
.background((store.cpuThermal.isThrottling ? Color.red : Color.green).opacity(0.15), in: Capsule())
|
||||||
|
Text(String(format: "%.1f°C", store.cpuThermal.packageTemperature))
|
||||||
|
.font(.title3.bold().monospacedDigit())
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: 24) {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text("Package Temp").font(.caption).foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f°C", store.cpuThermal.packageTemperature)).bold()
|
||||||
|
}
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text("Peak Core").font(.caption).foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f°C", store.cpuThermal.peakCoreTemperature)).bold()
|
||||||
|
}
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text("Average Core").font(.caption).foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f°C", store.cpuThermal.averageCoreTemperature)).bold()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !store.cpuThermal.coreTemperatures.isEmpty {
|
||||||
|
Divider()
|
||||||
|
Text("Core Temperature Breakdown")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
|
||||||
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 80))], spacing: 8) {
|
||||||
|
ForEach(store.cpuThermal.coreTemperatures, id: \.key) { core in
|
||||||
|
VStack(spacing: 2) {
|
||||||
|
Text("Core \(core.index)")
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f°C", core.temperature))
|
||||||
|
.font(.system(size: 11, weight: .bold, design: .monospaced))
|
||||||
|
.foregroundStyle(core.temperature > 85 ? .red : (core.temperature > 70 ? .orange : .primary))
|
||||||
|
}
|
||||||
|
.padding(6)
|
||||||
|
.background(.quaternary, in: RoundedRectangle(cornerRadius: 6))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Fans & Tachometers Card
|
||||||
|
private var fansCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("Cooling Fans", systemImage: "fanblades.fill")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text("\(store.fans.count) Detected")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
if store.fans.isEmpty {
|
||||||
|
Text("No active AppleSMC fans detected or passive cooling chassis.")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
|
.padding(.vertical, 8)
|
||||||
|
} else {
|
||||||
|
ForEach(store.fans) { fan in
|
||||||
|
VStack(alignment: .leading, spacing: 6) {
|
||||||
|
HStack {
|
||||||
|
Text(fan.name).bold()
|
||||||
|
Spacer()
|
||||||
|
Text(String(format: "%.0f RPM (%.0f%%)", fan.currentRPM, fan.utilization))
|
||||||
|
.font(.subheadline.bold().monospacedDigit())
|
||||||
|
}
|
||||||
|
ProgressView(value: min(fan.utilization / 100.0, 1.0))
|
||||||
|
.tint(fan.utilization > 80 ? .red : .blue)
|
||||||
|
HStack {
|
||||||
|
Text("Min: \(Int(fan.minRPM)) RPM")
|
||||||
|
Spacer()
|
||||||
|
Text("Target: \(Int(fan.targetRPM)) RPM")
|
||||||
|
Spacer()
|
||||||
|
Text("Max: \(Int(fan.maxRPM)) RPM")
|
||||||
|
}
|
||||||
|
.font(.system(size: 10))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
.padding(8)
|
||||||
|
.background(.quaternary, in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Component Thermals Matrix Card
|
||||||
|
private var componentThermalCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("Chassis & Component Thermals", systemImage: "thermometer.medium")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text("\(store.componentTemps.count) Sensors")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
if store.componentTemps.isEmpty {
|
||||||
|
Text("Awaiting component thermal probe...")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
LazyVGrid(columns: [GridItem(.adaptive(minimum: 160))], spacing: 10) {
|
||||||
|
ForEach(store.componentTemps) { item in
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
Text(item.name)
|
||||||
|
.font(.system(size: 11, weight: .semibold))
|
||||||
|
.lineLimit(1)
|
||||||
|
HStack {
|
||||||
|
Text(item.category)
|
||||||
|
.font(.system(size: 9))
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Text(String(format: "%.1f°C", item.temperature))
|
||||||
|
.font(.system(size: 11, weight: .bold, design: .monospaced))
|
||||||
|
.foregroundStyle(item.temperature > 75 ? .red : .primary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(8)
|
||||||
|
.background(.quaternary, in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(16)
|
.padding(16)
|
||||||
@@ -149,6 +454,108 @@ public struct ContentView: View {
|
|||||||
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Storage Volumes Card
|
||||||
|
private var storageCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("Storage Volumes", systemImage: "internaldrive")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
Text("\(store.storageVolumes.count) Mounted")
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
}
|
||||||
|
|
||||||
|
if store.storageVolumes.isEmpty {
|
||||||
|
Text("No mounted APFS/HFS volumes discovered.")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
} else {
|
||||||
|
ForEach(store.storageVolumes) { vol in
|
||||||
|
VStack(alignment: .leading, spacing: 4) {
|
||||||
|
HStack {
|
||||||
|
Text(vol.volumeName).bold()
|
||||||
|
Text("(\(vol.fileSystem))").font(.caption).foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Text("\(formatBytes(vol.usedBytes)) / \(formatBytes(vol.totalBytes))")
|
||||||
|
.font(.caption.monospacedDigit())
|
||||||
|
}
|
||||||
|
ProgressView(value: min(vol.usedPercentage / 100.0, 1.0))
|
||||||
|
.tint(vol.usedPercentage > 90 ? .red : .blue)
|
||||||
|
HStack {
|
||||||
|
Text("Mount: \(vol.mountPoint)").font(.system(size: 10)).foregroundStyle(.secondary)
|
||||||
|
Spacer()
|
||||||
|
Text(String(format: "%.1f%% Used", vol.usedPercentage)).font(.system(size: 10, weight: .bold))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(8)
|
||||||
|
.background(.quaternary, in: RoundedRectangle(cornerRadius: 8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Power & Voltage Card
|
||||||
|
private var powerCard: some View {
|
||||||
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
|
HStack {
|
||||||
|
Label("Power & Voltage", systemImage: "bolt.fill")
|
||||||
|
.font(.headline)
|
||||||
|
Spacer()
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Image(systemName: store.power.powerSource.contains("Battery") ? "battery.75" : "powerplug.fill")
|
||||||
|
Text(store.power.powerSource)
|
||||||
|
}
|
||||||
|
.font(.caption.bold())
|
||||||
|
.foregroundStyle(.secondary)
|
||||||
|
|
||||||
|
Text(String(format: "%.1f W", store.power.systemTotalWatts))
|
||||||
|
.font(.title3.bold().monospacedDigit())
|
||||||
|
}
|
||||||
|
|
||||||
|
Grid(alignment: .leading, horizontalSpacing: 16, verticalSpacing: 6) {
|
||||||
|
GridRow {
|
||||||
|
Text("Total Draw:").foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f W", store.power.systemTotalWatts)).bold()
|
||||||
|
Text("CPU Package:").foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f W", store.power.cpuWatts)).bold()
|
||||||
|
}
|
||||||
|
GridRow {
|
||||||
|
Text("CPU Core Voltage:").foregroundStyle(.secondary)
|
||||||
|
Text(store.power.cpuVoltage > 0 ? String(format: "%.3f V", store.power.cpuVoltage) : "N/A")
|
||||||
|
Text("CPU Current:").foregroundStyle(.secondary)
|
||||||
|
Text(store.power.cpuCurrent > 0 ? String(format: "%.2f A", store.power.cpuCurrent) : "N/A")
|
||||||
|
}
|
||||||
|
if store.power.gpuWatts > 0 || store.power.memoryWatts > 0 {
|
||||||
|
GridRow {
|
||||||
|
Text("GPU Draw:").foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f W", store.power.gpuWatts))
|
||||||
|
Text("Memory Subsystem:").foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.1f W", store.power.memoryWatts))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if store.power.powerSource.contains("Battery") {
|
||||||
|
GridRow {
|
||||||
|
Text("Battery Level:").foregroundStyle(.secondary)
|
||||||
|
Text(String(format: "%.0f%% %@", store.power.batteryLevel, store.power.isCharging ? "(Charging)" : ""))
|
||||||
|
Text("Status:").foregroundStyle(.secondary)
|
||||||
|
Text(store.power.isCharging ? "Charging" : "Discharging")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.font(.caption)
|
||||||
|
}
|
||||||
|
.padding(16)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .topLeading)
|
||||||
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Hardware Specs Card
|
||||||
private var specsCard: some View {
|
private var specsCard: some View {
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
Text("Host Architecture & Kernel")
|
Text("Host Architecture & Kernel")
|
||||||
@@ -180,6 +587,7 @@ public struct ContentView: View {
|
|||||||
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Providers Card
|
||||||
private var providersCard: some View {
|
private var providersCard: some View {
|
||||||
VStack(alignment: .leading, spacing: 12) {
|
VStack(alignment: .leading, spacing: 12) {
|
||||||
HStack {
|
HStack {
|
||||||
@@ -195,33 +603,38 @@ public struct ContentView: View {
|
|||||||
.clipShape(Capsule())
|
.clipShape(Capsule())
|
||||||
}
|
}
|
||||||
|
|
||||||
if store.latestSnapshot.isEmpty {
|
ForEach(Array(store.latestSnapshot.keys.sorted()), id: \.self) { key in
|
||||||
HStack(spacing: 12) {
|
HStack {
|
||||||
Image(systemName: "info.circle")
|
Image(systemName: "checkmark.circle.fill")
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.green)
|
||||||
Text("Telemetry coordinator initialized. Awaiting provider metrics.")
|
Text(key)
|
||||||
.font(.subheadline)
|
.font(.system(.body, design: .monospaced))
|
||||||
|
Spacer()
|
||||||
|
Text("\(store.latestSnapshot[key]?.count ?? 0) metrics")
|
||||||
|
.font(.caption)
|
||||||
.foregroundStyle(.secondary)
|
.foregroundStyle(.secondary)
|
||||||
}
|
}
|
||||||
.padding(.vertical, 8)
|
.padding(.vertical, 4)
|
||||||
} else {
|
|
||||||
ForEach(Array(store.latestSnapshot.keys.sorted()), id: \.self) { key in
|
|
||||||
HStack {
|
|
||||||
Image(systemName: "checkmark.circle.fill")
|
|
||||||
.foregroundStyle(.green)
|
|
||||||
Text(key)
|
|
||||||
.font(.system(.body, design: .monospaced))
|
|
||||||
Spacer()
|
|
||||||
Text("\(store.latestSnapshot[key]?.count ?? 0) metrics")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(.secondary)
|
|
||||||
}
|
|
||||||
.padding(.vertical, 4)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(16)
|
.padding(16)
|
||||||
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
.background(.background, in: RoundedRectangle(cornerRadius: 12))
|
||||||
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
.overlay(RoundedRectangle(cornerRadius: 12).stroke(.separator, lineWidth: 1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Formatting Helpers
|
||||||
|
private func formatBytes(_ bytes: UInt64) -> String {
|
||||||
|
let formatter = ByteCountFormatter()
|
||||||
|
formatter.allowedUnits = [.useGB, .useMB]
|
||||||
|
formatter.countStyle = .memory
|
||||||
|
return formatter.string(fromByteCount: Int64(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func pressureColor(_ level: String) -> Color {
|
||||||
|
switch level {
|
||||||
|
case "Critical": return .red
|
||||||
|
case "Warning": return .orange
|
||||||
|
default: return .green
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMCPULoadTests: XCTestCase {
|
||||||
|
|
||||||
|
func testTickDeltaCalculation() {
|
||||||
|
var prevTicks = [processor_cpu_load_info_data_t]()
|
||||||
|
var currTicks = [processor_cpu_load_info_data_t]()
|
||||||
|
|
||||||
|
// Setup mock Core 0: 20% user, 10% system, 70% idle
|
||||||
|
var core0Prev = processor_cpu_load_info_data_t()
|
||||||
|
core0Prev.cpu_ticks.0 = 100 // USER
|
||||||
|
core0Prev.cpu_ticks.1 = 50 // SYSTEM
|
||||||
|
core0Prev.cpu_ticks.2 = 850 // IDLE
|
||||||
|
core0Prev.cpu_ticks.3 = 0 // NICE
|
||||||
|
prevTicks.append(core0Prev)
|
||||||
|
|
||||||
|
var core0Curr = processor_cpu_load_info_data_t()
|
||||||
|
core0Curr.cpu_ticks.0 = 300 // USER (+200)
|
||||||
|
core0Curr.cpu_ticks.1 = 150 // SYSTEM (+100)
|
||||||
|
core0Curr.cpu_ticks.2 = 1550 // IDLE (+700)
|
||||||
|
core0Curr.cpu_ticks.3 = 0 // NICE (+0)
|
||||||
|
currTicks.append(core0Curr)
|
||||||
|
|
||||||
|
prevTicks.withUnsafeBufferPointer { prevBuf in
|
||||||
|
currTicks.withUnsafeBufferPointer { currBuf in
|
||||||
|
let metrics = MMCPULoadProvider.calculateLoad(
|
||||||
|
fromPreviousTicks: prevBuf.baseAddress,
|
||||||
|
currentTicks: currBuf.baseAddress!,
|
||||||
|
coreCount: 1
|
||||||
|
)
|
||||||
|
|
||||||
|
let totalPct = metrics["totalPercent"] as? Double ?? 0
|
||||||
|
let userPct = metrics["userPercent"] as? Double ?? 0
|
||||||
|
let systemPct = metrics["systemPercent"] as? Double ?? 0
|
||||||
|
let idlePct = metrics["idlePercent"] as? Double ?? 0
|
||||||
|
|
||||||
|
// Total delta = 200 + 100 + 700 = 1000
|
||||||
|
// User = 20%, System = 10%, Idle = 70%, Total Active = 30%
|
||||||
|
XCTAssertEqual(totalPct, 30.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(userPct, 20.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(systemPct, 10.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(idlePct, 70.0, accuracy: 0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveCPULoadProvider() throws {
|
||||||
|
let provider = MMCPULoadProvider()
|
||||||
|
XCTAssertTrue(provider.isAvailable)
|
||||||
|
XCTAssertEqual(provider.domain, .cpu)
|
||||||
|
XCTAssertGreaterThan(provider.coreCount, 0)
|
||||||
|
|
||||||
|
// Initial sample establishes baseline
|
||||||
|
let sample1 = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample1)
|
||||||
|
|
||||||
|
// Second sample produces live deltas
|
||||||
|
usleep(100_000) // 100ms
|
||||||
|
let sample2 = try provider.sampleTelemetry()
|
||||||
|
let cores = sample2["cores"] as? [[String: Any]]
|
||||||
|
XCTAssertNotNil(cores)
|
||||||
|
XCTAssertEqual(cores?.count, Int(provider.coreCount))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMCPUThermalTests: XCTestCase {
|
||||||
|
|
||||||
|
func testThermalMetricsCalculation() {
|
||||||
|
let pkgTemp = NSNumber(value: 55.0)
|
||||||
|
let coreDict: [String: NSNumber] = [
|
||||||
|
"TC0C": NSNumber(value: 52.0),
|
||||||
|
"TC1C": NSNumber(value: 56.0),
|
||||||
|
"TC2C": NSNumber(value: 54.0),
|
||||||
|
"TC3C": NSNumber(value: 58.0)
|
||||||
|
]
|
||||||
|
|
||||||
|
let metrics = MMCPUThermalProvider.calculateThermalMetrics(
|
||||||
|
withPackageTemp: pkgTemp,
|
||||||
|
coreTemps: coreDict,
|
||||||
|
thermalState: .nominal
|
||||||
|
)
|
||||||
|
|
||||||
|
let peak = metrics["peakCoreTemperature"] as? Double ?? 0
|
||||||
|
let avg = metrics["averageCoreTemperature"] as? Double ?? 0
|
||||||
|
let state = metrics["thermalPressureState"] as? String ?? ""
|
||||||
|
let isThrottling = metrics["isThrottling"] as? Bool ?? true
|
||||||
|
|
||||||
|
XCTAssertEqual(peak, 58.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(avg, 55.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(state, "Nominal")
|
||||||
|
XCTAssertFalse(isThrottling)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testThermalThrottlingDetection() {
|
||||||
|
let metrics = MMCPUThermalProvider.calculateThermalMetrics(
|
||||||
|
withPackageTemp: NSNumber(value: 99.0),
|
||||||
|
coreTemps: [:],
|
||||||
|
thermalState: .serious
|
||||||
|
)
|
||||||
|
|
||||||
|
let isThrottling = metrics["isThrottling"] as? Bool ?? false
|
||||||
|
let state = metrics["thermalPressureState"] as? String ?? ""
|
||||||
|
|
||||||
|
XCTAssertTrue(isThrottling)
|
||||||
|
XCTAssertEqual(state, "Serious")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveCPUThermalProvider() throws {
|
||||||
|
let provider = MMCPUThermalProvider()
|
||||||
|
XCTAssertEqual(provider.domain, .thermal)
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample)
|
||||||
|
XCTAssertNotNil(sample["thermalPressureState"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMComponentThermalTests: XCTestCase {
|
||||||
|
|
||||||
|
func testCategoryClassification() {
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TPCD"), "PCH / Chipset")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TP0P"), "PCH / Chipset")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "Th0H"), "Heatsink")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "Th1H"), "Heatsink")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TM0P"), "Memory")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TM1S"), "Memory")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "Tp0P"), "Power Supply")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TA0P"), "Ambient / Enclosure")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TTLD"), "Thunderbolt / IO")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "TB0T"), "Thunderbolt / IO")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.category(forKey: "ZZ99"), "Other")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testHumanReadableNames() {
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.humanReadableName(forKey: "TPCD"), "Platform Controller Hub (Die)")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.humanReadableName(forKey: "Th0H"), "Main Heatsink A")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.humanReadableName(forKey: "TA0P"), "Ambient Air Intake")
|
||||||
|
XCTAssertEqual(MMComponentThermalProvider.humanReadableName(forKey: "CUSTOM"), "CUSTOM")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testComponentMetricsCalculation() {
|
||||||
|
let readings: [String: NSNumber] = [
|
||||||
|
"TPCD": NSNumber(value: 65.5),
|
||||||
|
"Th0H": NSNumber(value: 48.0),
|
||||||
|
"TM0P": NSNumber(value: 42.0),
|
||||||
|
"TA0P": NSNumber(value: 28.5)
|
||||||
|
]
|
||||||
|
|
||||||
|
let metrics = MMComponentThermalProvider.calculateComponentMetrics(from: readings)
|
||||||
|
|
||||||
|
let peak = metrics["peakTemperature"] as? Double ?? 0
|
||||||
|
let avg = metrics["averageTemperature"] as? Double ?? 0
|
||||||
|
let count = metrics["sensorCount"] as? Int ?? 0
|
||||||
|
let components = metrics["components"] as? [[String: Any]] ?? []
|
||||||
|
let categorized = metrics["categorized"] as? [String: [[String: Any]]] ?? [:]
|
||||||
|
|
||||||
|
XCTAssertEqual(peak, 65.5, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(avg, (65.5 + 48.0 + 42.0 + 28.5) / 4.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(count, 4)
|
||||||
|
XCTAssertEqual(components.count, 4)
|
||||||
|
|
||||||
|
let pchList = categorized["PCH / Chipset"]
|
||||||
|
XCTAssertNotNil(pchList)
|
||||||
|
let firstPchName = pchList?.first?["name"] as? String
|
||||||
|
XCTAssertEqual(firstPchName, "Platform Controller Hub (Die)")
|
||||||
|
XCTAssertEqual(categorized["Heatsink"]?.count, 1)
|
||||||
|
XCTAssertEqual(categorized["Memory"]?.count, 1)
|
||||||
|
XCTAssertEqual(categorized["Ambient / Enclosure"]?.count, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testEmptyReadingsCalculation() {
|
||||||
|
let metrics = MMComponentThermalProvider.calculateComponentMetrics(from: [:])
|
||||||
|
|
||||||
|
let peak = metrics["peakTemperature"] as? Double ?? -1
|
||||||
|
let avg = metrics["averageTemperature"] as? Double ?? -1
|
||||||
|
let count = metrics["sensorCount"] as? Int ?? -1
|
||||||
|
|
||||||
|
XCTAssertEqual(peak, 0.0)
|
||||||
|
XCTAssertEqual(avg, 0.0)
|
||||||
|
XCTAssertEqual(count, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveComponentThermalProvider() throws {
|
||||||
|
let provider = MMComponentThermalProvider()
|
||||||
|
XCTAssertEqual(provider.domain, .thermal)
|
||||||
|
XCTAssertEqual(provider.providerIdentifier, "com.i3omb.macmonitor.telemetry.thermal.components")
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample)
|
||||||
|
XCTAssertNotNil(sample["sensorCount"])
|
||||||
|
XCTAssertNotNil(sample["components"])
|
||||||
|
XCTAssertNotNil(sample["categorized"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMFanTests: XCTestCase {
|
||||||
|
|
||||||
|
func testFanUtilizationCalculation() {
|
||||||
|
let fanList: [[String: NSNumber]] = [
|
||||||
|
[
|
||||||
|
"currentRPM": NSNumber(value: 2000.0),
|
||||||
|
"minRPM": NSNumber(value: 1200.0),
|
||||||
|
"maxRPM": NSNumber(value: 5000.0),
|
||||||
|
"targetRPM": NSNumber(value: 2000.0)
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"currentRPM": NSNumber(value: 2500.0),
|
||||||
|
"minRPM": NSNumber(value: 1200.0),
|
||||||
|
"maxRPM": NSNumber(value: 5000.0),
|
||||||
|
"targetRPM": NSNumber(value: 2500.0)
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
let metrics = MMFanTelemetryProvider.calculateFanMetrics(fromFanList: fanList)
|
||||||
|
|
||||||
|
let count = metrics["fanCount"] as? Int ?? 0
|
||||||
|
let avgRPM = metrics["averageRPM"] as? Double ?? 0
|
||||||
|
let peakRPM = metrics["peakRPM"] as? Double ?? 0
|
||||||
|
let fans = metrics["fans"] as? [[String: Any]] ?? []
|
||||||
|
|
||||||
|
XCTAssertEqual(count, 2)
|
||||||
|
XCTAssertEqual(avgRPM, 2250.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(peakRPM, 2500.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(fans.count, 2)
|
||||||
|
|
||||||
|
let fan0 = fans[0]
|
||||||
|
let util0 = fan0["utilizationPercent"] as? Double ?? 0
|
||||||
|
// (2000 - 1200) / 3800 * 100 = 21.05%
|
||||||
|
XCTAssertEqual(util0, 21.05, accuracy: 0.1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveFanProvider() throws {
|
||||||
|
let provider = MMFanTelemetryProvider()
|
||||||
|
XCTAssertEqual(provider.domain, .fan)
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample)
|
||||||
|
XCTAssertNotNil(sample["fanCount"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMKernelTelemetryTests: XCTestCase {
|
||||||
|
|
||||||
|
func testKernelRatesCalculation() {
|
||||||
|
let prev: [String: NSNumber] = [
|
||||||
|
"contextSwitches": NSNumber(value: 100_000),
|
||||||
|
"syscalls": NSNumber(value: 200_000),
|
||||||
|
"pageFaults": NSNumber(value: 50_000),
|
||||||
|
"cowFaults": NSNumber(value: 1_000),
|
||||||
|
"zeroFills": NSNumber(value: 10_000),
|
||||||
|
"pageins": NSNumber(value: 500),
|
||||||
|
"pageouts": NSNumber(value: 100),
|
||||||
|
"decompressions": NSNumber(value: 200),
|
||||||
|
"compressions": NSNumber(value: 300)
|
||||||
|
]
|
||||||
|
|
||||||
|
let curr: [String: NSNumber] = [
|
||||||
|
"contextSwitches": NSNumber(value: 102_500), // delta = 2,500
|
||||||
|
"syscalls": NSNumber(value: 210_000), // delta = 10,000
|
||||||
|
"pageFaults": NSNumber(value: 51_000), // delta = 1,000
|
||||||
|
"cowFaults": NSNumber(value: 1_050), // delta = 50
|
||||||
|
"zeroFills": NSNumber(value: 10_200), // delta = 200
|
||||||
|
"pageins": NSNumber(value: 520), // delta = 20
|
||||||
|
"pageouts": NSNumber(value: 105), // delta = 5
|
||||||
|
"decompressions": NSNumber(value: 210), // delta = 10
|
||||||
|
"compressions": NSNumber(value: 315) // delta = 15
|
||||||
|
]
|
||||||
|
|
||||||
|
let timeDelta: TimeInterval = 2.0 // 2 seconds
|
||||||
|
|
||||||
|
let rates = MMKernelTelemetryProvider.calculateRates(
|
||||||
|
withCurrentCounters: curr,
|
||||||
|
previousCounters: prev,
|
||||||
|
timeDelta: timeDelta
|
||||||
|
)
|
||||||
|
|
||||||
|
let cswRate = rates["contextSwitchesRate"] as? Double ?? 0
|
||||||
|
let syscallRate = rates["syscallsRate"] as? Double ?? 0
|
||||||
|
let faultRate = rates["pageFaultsRate"] as? Double ?? 0
|
||||||
|
let cowRate = rates["cowFaultsRate"] as? Double ?? 0
|
||||||
|
let zeroFillRate = rates["zeroFillsRate"] as? Double ?? 0
|
||||||
|
let pageinsRate = rates["pageinsRate"] as? Double ?? 0
|
||||||
|
|
||||||
|
XCTAssertEqual(cswRate, 1250.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(syscallRate, 5000.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(faultRate, 500.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(cowRate, 25.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(zeroFillRate, 100.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(pageinsRate, 10.0, accuracy: 0.1)
|
||||||
|
|
||||||
|
let cumCSW = rates["cumulative_contextSwitches"] as? UInt64 ?? 0
|
||||||
|
XCTAssertEqual(cumCSW, 102_500)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveKernelProvider() throws {
|
||||||
|
let provider = MMKernelTelemetryProvider()
|
||||||
|
XCTAssertEqual(provider.domain, .system)
|
||||||
|
XCTAssertEqual(provider.providerIdentifier, "com.i3omb.macmonitor.telemetry.kernel.counters")
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample)
|
||||||
|
XCTAssertNotNil(sample["cumulative_contextSwitches"])
|
||||||
|
XCTAssertNotNil(sample["cumulative_syscalls"])
|
||||||
|
XCTAssertNotNil(sample["cumulative_pageFaults"])
|
||||||
|
XCTAssertNotNil(sample["contextSwitchesRate"])
|
||||||
|
XCTAssertNotNil(sample["syscallsRate"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMMemoryTests: XCTestCase {
|
||||||
|
|
||||||
|
func testMemoryMetricCalculation() {
|
||||||
|
var vmInfo = vm_statistics64_data_t()
|
||||||
|
let pageSize: vm_size_t = 4096
|
||||||
|
let totalRAM: UInt64 = 16 * 1024 * 1024 * 1024 // 16 GB
|
||||||
|
|
||||||
|
// 1GB wired (262144 pages), 2GB app (524288 pages), 1GB compressed (262144 pages)
|
||||||
|
vmInfo.wire_count = 262_144
|
||||||
|
vmInfo.internal_page_count = 524_288
|
||||||
|
vmInfo.purgeable_count = 0
|
||||||
|
vmInfo.compressor_page_count = 262_144
|
||||||
|
vmInfo.active_count = 524_288
|
||||||
|
vmInfo.inactive_count = 1_048_576 // 4GB
|
||||||
|
vmInfo.free_count = 2_097_152 // 8GB
|
||||||
|
|
||||||
|
var swap = xsw_usage()
|
||||||
|
swap.xsu_total = 2 * 1024 * 1024 * 1024
|
||||||
|
swap.xsu_used = 512 * 1024 * 1024
|
||||||
|
swap.xsu_avail = swap.xsu_total - swap.xsu_used
|
||||||
|
|
||||||
|
withUnsafePointer(to: vmInfo) { vmPtr in
|
||||||
|
withUnsafePointer(to: swap) { swapPtr in
|
||||||
|
let metrics = MMMemoryTelemetryProvider.calculateMemoryMetrics(
|
||||||
|
withVMInfo: vmPtr,
|
||||||
|
pageSize: pageSize,
|
||||||
|
totalPhysicalRAM: totalRAM,
|
||||||
|
swapUsage: swapPtr
|
||||||
|
)
|
||||||
|
|
||||||
|
let wired = metrics["wiredBytes"] as? UInt64 ?? 0
|
||||||
|
let app = metrics["appMemoryBytes"] as? UInt64 ?? 0
|
||||||
|
let compressed = metrics["compressedBytes"] as? UInt64 ?? 0
|
||||||
|
let used = metrics["usedBytes"] as? UInt64 ?? 0
|
||||||
|
let pressureStatus = metrics["memoryPressureStatus"] as? String ?? ""
|
||||||
|
|
||||||
|
XCTAssertEqual(wired, 1024 * 1024 * 1024)
|
||||||
|
XCTAssertEqual(app, 2 * 1024 * 1024 * 1024)
|
||||||
|
XCTAssertEqual(compressed, 1024 * 1024 * 1024)
|
||||||
|
XCTAssertEqual(used, 4 * 1024 * 1024 * 1024)
|
||||||
|
XCTAssertEqual(pressureStatus, "Normal")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveMemoryProvider() throws {
|
||||||
|
let provider = MMMemoryTelemetryProvider()
|
||||||
|
XCTAssertTrue(provider.isAvailable)
|
||||||
|
XCTAssertEqual(provider.domain, .memory)
|
||||||
|
XCTAssertGreaterThan(provider.totalPhysicalMemoryBytes, 0)
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
let total = sample["totalBytes"] as? UInt64 ?? 0
|
||||||
|
let used = sample["usedBytes"] as? UInt64 ?? 0
|
||||||
|
let free = sample["freeBytes"] as? UInt64 ?? 0
|
||||||
|
|
||||||
|
XCTAssertGreaterThan(total, 0)
|
||||||
|
XCTAssertGreaterThan(used, 0)
|
||||||
|
XCTAssertGreaterThanOrEqual(free, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMPowerTests: XCTestCase {
|
||||||
|
|
||||||
|
func testUnitsAndNames() {
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.unit(forKey: "PSTR"), "W")
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.unit(forKey: "VC0C"), "V")
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.unit(forKey: "IC0C"), "A")
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.unit(forKey: "UNKNOWN"), "")
|
||||||
|
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.humanReadableName(forKey: "PSTR"), "Total System Power")
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.humanReadableName(forKey: "VC0C"), "CPU Core Voltage")
|
||||||
|
XCTAssertEqual(MMPowerTelemetryProvider.humanReadableName(forKey: "IC0C"), "CPU Core Current")
|
||||||
|
}
|
||||||
|
|
||||||
|
func testPowerMetricsCalculationFromSMC() {
|
||||||
|
let readings: [String: NSNumber] = [
|
||||||
|
"PSTR": NSNumber(value: 45.2),
|
||||||
|
"PCPR": NSNumber(value: 28.4),
|
||||||
|
"PG0R": NSNumber(value: 8.5),
|
||||||
|
"PMSR": NSNumber(value: 3.1),
|
||||||
|
"VC0C": NSNumber(value: 1.15),
|
||||||
|
"IC0C": NSNumber(value: 24.5)
|
||||||
|
]
|
||||||
|
|
||||||
|
let batteryInfo: [String: Any] = [
|
||||||
|
"powerSource": "AC Power",
|
||||||
|
"isCharging": false,
|
||||||
|
"batteryLevel": 100.0,
|
||||||
|
"batteryWatts": 0.0
|
||||||
|
]
|
||||||
|
|
||||||
|
let metrics = MMPowerTelemetryProvider.calculatePowerMetrics(
|
||||||
|
withReadings: readings,
|
||||||
|
batteryInfo: batteryInfo
|
||||||
|
)
|
||||||
|
|
||||||
|
let systemWatts = metrics["systemTotalWatts"] as? Double ?? 0
|
||||||
|
let cpuWatts = metrics["cpuWatts"] as? Double ?? 0
|
||||||
|
let gpuWatts = metrics["gpuWatts"] as? Double ?? 0
|
||||||
|
let memWatts = metrics["memoryWatts"] as? Double ?? 0
|
||||||
|
let cpuV = metrics["cpuVoltage"] as? Double ?? 0
|
||||||
|
let cpuI = metrics["cpuCurrent"] as? Double ?? 0
|
||||||
|
let powerSource = metrics["powerSource"] as? String ?? ""
|
||||||
|
let sensors = metrics["sensors"] as? [[String: Any]] ?? []
|
||||||
|
|
||||||
|
XCTAssertEqual(systemWatts, 45.2, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(cpuWatts, 28.4, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(gpuWatts, 8.5, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(memWatts, 3.1, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(cpuV, 1.15, accuracy: 0.01)
|
||||||
|
XCTAssertEqual(cpuI, 24.5, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(powerSource, "AC Power")
|
||||||
|
XCTAssertEqual(sensors.count, 6)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testBatteryFallbackCalculation() {
|
||||||
|
// No PSTR, no PCPR, but VC0C and IC0C are present
|
||||||
|
let readings: [String: NSNumber] = [
|
||||||
|
"VC0C": NSNumber(value: 1.2),
|
||||||
|
"IC0C": NSNumber(value: 10.0)
|
||||||
|
]
|
||||||
|
|
||||||
|
let batteryInfo: [String: Any] = [
|
||||||
|
"powerSource": "Battery Power",
|
||||||
|
"isCharging": false,
|
||||||
|
"batteryLevel": 75.0,
|
||||||
|
"batteryWatts": 18.5
|
||||||
|
]
|
||||||
|
|
||||||
|
let metrics = MMPowerTelemetryProvider.calculatePowerMetrics(
|
||||||
|
withReadings: readings,
|
||||||
|
batteryInfo: batteryInfo
|
||||||
|
)
|
||||||
|
|
||||||
|
let systemWatts = metrics["systemTotalWatts"] as? Double ?? 0
|
||||||
|
let cpuWatts = metrics["cpuWatts"] as? Double ?? 0
|
||||||
|
let powerSource = metrics["powerSource"] as? String ?? ""
|
||||||
|
let isCharging = metrics["isCharging"] as? Bool ?? true
|
||||||
|
|
||||||
|
// System watts falls back to batteryWatts (18.5)
|
||||||
|
XCTAssertEqual(systemWatts, 18.5, accuracy: 0.1)
|
||||||
|
// CPU watts calculated from V * I = 1.2 * 10.0 = 12.0 W
|
||||||
|
XCTAssertEqual(cpuWatts, 12.0, accuracy: 0.1)
|
||||||
|
XCTAssertEqual(powerSource, "Battery Power")
|
||||||
|
XCTAssertFalse(isCharging)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLivePowerProvider() throws {
|
||||||
|
let provider = MMPowerTelemetryProvider()
|
||||||
|
XCTAssertEqual(provider.domain, .power)
|
||||||
|
XCTAssertEqual(provider.providerIdentifier, "com.i3omb.macmonitor.telemetry.power")
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
XCTAssertNotNil(sample)
|
||||||
|
XCTAssertNotNil(sample["systemTotalWatts"])
|
||||||
|
XCTAssertNotNil(sample["powerSource"])
|
||||||
|
XCTAssertNotNil(sample["sensors"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import MacMonitor
|
||||||
|
|
||||||
|
final class MMStorageTests: XCTestCase {
|
||||||
|
|
||||||
|
func testStatFSBufferParsing() {
|
||||||
|
var stat = statfs()
|
||||||
|
stat.f_bsize = 4096
|
||||||
|
stat.f_blocks = 125_000_000 // 500 GB
|
||||||
|
stat.f_bfree = 50_000_000 // 200 GB
|
||||||
|
stat.f_bavail = 45_000_000
|
||||||
|
stat.f_flags = UInt32(MNT_LOCAL)
|
||||||
|
|
||||||
|
let mountPath = "/Volumes/External"
|
||||||
|
let devicePath = "/dev/disk2s1"
|
||||||
|
let fsType = "apfs"
|
||||||
|
|
||||||
|
_ = mountPath.withCString { mntPtr in
|
||||||
|
strncpy(&stat.f_mntonname.0, mntPtr, Int(MNAMELEN))
|
||||||
|
}
|
||||||
|
_ = devicePath.withCString { devPtr in
|
||||||
|
strncpy(&stat.f_mntfromname.0, devPtr, Int(MNAMELEN))
|
||||||
|
}
|
||||||
|
_ = fsType.withCString { fsPtr in
|
||||||
|
strncpy(&stat.f_fstypename.0, fsPtr, Int(MFSTYPENAMELEN))
|
||||||
|
}
|
||||||
|
|
||||||
|
withUnsafePointer(to: stat) { ptr in
|
||||||
|
let volumes = MMStorageTelemetryProvider.parseStatFSBuffer(ptr, count: 1)
|
||||||
|
XCTAssertEqual(volumes.count, 1)
|
||||||
|
|
||||||
|
let vol = volumes.first!
|
||||||
|
XCTAssertEqual(vol["volumeName"] as? String, "External")
|
||||||
|
XCTAssertEqual(vol["mountPoint"] as? String, "/Volumes/External")
|
||||||
|
XCTAssertEqual(vol["devicePath"] as? String, "/dev/disk2s1")
|
||||||
|
XCTAssertEqual(vol["fsType"] as? String, "apfs")
|
||||||
|
|
||||||
|
let total = vol["totalBytes"] as? UInt64 ?? 0
|
||||||
|
let free = vol["freeBytes"] as? UInt64 ?? 0
|
||||||
|
let used = vol["usedBytes"] as? UInt64 ?? 0
|
||||||
|
let pct = vol["usedPercent"] as? Double ?? 0
|
||||||
|
|
||||||
|
XCTAssertEqual(total, 512_000_000_000)
|
||||||
|
XCTAssertEqual(free, 204_800_000_000)
|
||||||
|
XCTAssertEqual(used, 307_200_000_000)
|
||||||
|
XCTAssertEqual(pct, 60.0, accuracy: 0.1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testLiveStorageProvider() throws {
|
||||||
|
let provider = MMStorageTelemetryProvider()
|
||||||
|
XCTAssertTrue(provider.isAvailable)
|
||||||
|
XCTAssertEqual(provider.domain, .storage)
|
||||||
|
|
||||||
|
let sample = try provider.sampleTelemetry()
|
||||||
|
let volumes = sample["volumes"] as? [[String: Any]]
|
||||||
|
XCTAssertNotNil(volumes)
|
||||||
|
XCTAssertGreaterThan(volumes?.count ?? 0, 0)
|
||||||
|
|
||||||
|
let firstVol = volumes?.first
|
||||||
|
XCTAssertNotNil(firstVol?["mountPoint"])
|
||||||
|
XCTAssertGreaterThan(firstVol?["totalBytes"] as? UInt64 ?? 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,4 +23,15 @@ final class MacMonitorCoreTests: XCTestCase {
|
|||||||
let thermalStr = MMTelemetryDomainToString(.thermal)
|
let thermalStr = MMTelemetryDomainToString(.thermal)
|
||||||
XCTAssertEqual(thermalStr, "Thermal")
|
XCTAssertEqual(thermalStr, "Thermal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
func testSystemTelemetryStoreInitialStateAndProviders() {
|
||||||
|
let store = SystemTelemetryStore.shared
|
||||||
|
XCTAssertNotNil(store)
|
||||||
|
XCTAssertEqual(store.registeredProviderCount, 7)
|
||||||
|
XCTAssertFalse(store.hostModel.isEmpty)
|
||||||
|
XCTAssertFalse(store.kernelVersion.isEmpty)
|
||||||
|
XCTAssertGreaterThanOrEqual(store.physicalCpuCount, 1)
|
||||||
|
XCTAssertGreaterThanOrEqual(store.logicalCpuCount, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user