Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b47ffd72ca | ||
|
|
c2fa0c05ed |
@@ -14,6 +14,8 @@
|
|||||||
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 */; };
|
4419FE7554489B23976E2970 /* MMCPULoadProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = D68FC8100D08DB6202F46339 /* MMCPULoadProvider.m */; };
|
||||||
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */; };
|
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */; };
|
||||||
|
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 */; };
|
||||||
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 */; };
|
||||||
@@ -39,6 +41,7 @@
|
|||||||
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>"; };
|
0130BD1E18972DF9E2955334 /* MMMemoryTelemetryProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MMMemoryTelemetryProvider.h; sourceTree = "<group>"; };
|
||||||
099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MMMemoryTests.swift; 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>"; };
|
||||||
@@ -50,6 +53,7 @@
|
|||||||
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>"; };
|
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>"; };
|
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>"; };
|
||||||
@@ -59,6 +63,7 @@
|
|||||||
991AEEAF262F3C6BE930BC77 /* MMMemoryTelemetryProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMMemoryTelemetryProvider.m; 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>"; };
|
||||||
D68FC8100D08DB6202F46339 /* MMCPULoadProvider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MMCPULoadProvider.m; 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; };
|
||||||
@@ -143,6 +148,7 @@
|
|||||||
78383CED205BCA772701AE48 /* CPU */,
|
78383CED205BCA772701AE48 /* CPU */,
|
||||||
EE2F5EFC9DC33CEDA79A131F /* Memory */,
|
EE2F5EFC9DC33CEDA79A131F /* Memory */,
|
||||||
B6EB3F6545276C40212C2992 /* Storage */,
|
B6EB3F6545276C40212C2992 /* Storage */,
|
||||||
|
DBDC37231C01F0A2D4A7FC73 /* Thermal */,
|
||||||
);
|
);
|
||||||
path = Telemetry;
|
path = Telemetry;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -178,6 +184,7 @@
|
|||||||
children = (
|
children = (
|
||||||
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */,
|
2EC3EDFCD5C50CB352FCED87 /* MacMonitorTests.swift */,
|
||||||
4CE92B1A8D7FDBB6499448E1 /* MMCPULoadTests.swift */,
|
4CE92B1A8D7FDBB6499448E1 /* MMCPULoadTests.swift */,
|
||||||
|
0F2BD3777A674DC4EB442890 /* MMCPUThermalTests.swift */,
|
||||||
099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */,
|
099DCF7EF03A58ADA40A94A1 /* MMMemoryTests.swift */,
|
||||||
940D608A1AF80F75584E744E /* MMSMCTests.swift */,
|
940D608A1AF80F75584E744E /* MMSMCTests.swift */,
|
||||||
78325870C7CD8312AECA2236 /* MMStorageTests.swift */,
|
78325870C7CD8312AECA2236 /* MMStorageTests.swift */,
|
||||||
@@ -185,6 +192,15 @@
|
|||||||
path = Tests;
|
path = Tests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
DBDC37231C01F0A2D4A7FC73 /* Thermal */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
D73CCC7B5E6BF1825EA68E2B /* MMCPUThermalProvider.h */,
|
||||||
|
62C377EFD025D6A6B5563E77 /* MMCPUThermalProvider.m */,
|
||||||
|
);
|
||||||
|
path = Thermal;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
E012FBB26EF9E35A2FAF87E2 /* AppleSMC */ = {
|
E012FBB26EF9E35A2FAF87E2 /* AppleSMC */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@@ -291,6 +307,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
160334CC765E091A7CBE21AA /* MMCPULoadTests.swift in Sources */,
|
160334CC765E091A7CBE21AA /* MMCPULoadTests.swift in Sources */,
|
||||||
|
87818E46CEA5145A8215D0E3 /* MMCPUThermalTests.swift in Sources */,
|
||||||
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */,
|
6201FD599FED061F6C736E8B /* MMMemoryTests.swift in Sources */,
|
||||||
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */,
|
EC9FA3E4A119277B89E73F8D /* MMSMCTests.swift in Sources */,
|
||||||
1B15F48F6B19E9EA4556ECD5 /* MMStorageTests.swift in Sources */,
|
1B15F48F6B19E9EA4556ECD5 /* MMStorageTests.swift in Sources */,
|
||||||
@@ -305,6 +322,7 @@
|
|||||||
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 */,
|
4419FE7554489B23976E2970 /* MMCPULoadProvider.m in Sources */,
|
||||||
|
87A9E18362486D0D385BBC4A /* MMCPUThermalProvider.m in Sources */,
|
||||||
B9C2D6574E808B517BA34C83 /* MMMemoryTelemetryProvider.m in Sources */,
|
B9C2D6574E808B517BA34C83 /* MMMemoryTelemetryProvider.m in Sources */,
|
||||||
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */,
|
1B3F1C8ABF0ADFAA290FF6F6 /* MMSMCParser.m in Sources */,
|
||||||
F2F7A141F2452EC1B4FB45D8 /* MMStorageTelemetryProvider.m in Sources */,
|
F2F7A141F2452EC1B4FB45D8 /* MMStorageTelemetryProvider.m in Sources */,
|
||||||
|
|||||||
@@ -15,5 +15,6 @@
|
|||||||
#import "MMCPULoadProvider.h"
|
#import "MMCPULoadProvider.h"
|
||||||
#import "MMMemoryTelemetryProvider.h"
|
#import "MMMemoryTelemetryProvider.h"
|
||||||
#import "MMStorageTelemetryProvider.h"
|
#import "MMStorageTelemetryProvider.h"
|
||||||
|
#import "MMCPUThermalProvider.h"
|
||||||
|
|
||||||
#endif /* MacMonitor_Bridging_Header_h */
|
#endif /* MacMonitor_Bridging_Header_h */
|
||||||
|
|||||||
@@ -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,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"])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user