feat(menubar): 完善首排监控卡片与温度风扇采样
补充 GPU 渲染分块、内存与利用率统计,增加只读 SMC 温度及风扇信息和旋转动效。完善电池功率与耗电进程列表,统一首排布局并固定异步加载区域高度。同步验证用例、架构说明和 GPU 能力调研工具。
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
// Research only: enumerate Apple's private counter descriptors, never start sampling.
|
||||
// clang -fobjc-arc -framework Foundation -framework IOKit -framework Metal tools/gpu_raw_counter_probe.m -o /tmp/kymo-gpu-raw-probe
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <IOKit/IOKitLib.h>
|
||||
#import <Metal/Metal.h>
|
||||
#import <dlfcn.h>
|
||||
#import <unistd.h>
|
||||
|
||||
@interface NSObject (KymoRawCounterDiscovery)
|
||||
- (instancetype)initWithAcceleratorPort:(io_service_t)port;
|
||||
- (NSArray *)sourceList;
|
||||
- (NSArray *)availableCounters;
|
||||
- (NSString *)name;
|
||||
- (io_service_t)acceleratorPort;
|
||||
@end
|
||||
|
||||
int main(void) {
|
||||
@autoreleasepool {
|
||||
void *bundle = dlopen("/System/Library/Extensions/AGXGPURawCounterBundle.bundle/Contents/MacOS/AGXGPURawCounterBundle", RTLD_LAZY);
|
||||
Class type = NSClassFromString(@"AGXGPURawCounterSourceGroup");
|
||||
if (!bundle || !type) { fprintf(stderr, "Raw counter plugin unavailable\n"); return 1; }
|
||||
io_iterator_t iterator = 0;
|
||||
if (IOServiceGetMatchingServices(kIOMainPortDefault, IOServiceMatching("IOAccelerator"), &iterator) != KERN_SUCCESS) return 2;
|
||||
NSMutableArray *devices = [NSMutableArray array];
|
||||
io_service_t service;
|
||||
while ((service = IOIteratorNext(iterator))) {
|
||||
io_connect_t connection = IO_OBJECT_NULL;
|
||||
@try {
|
||||
id group = [[type alloc] initWithAcceleratorPort:service];
|
||||
// Also test the standard type-0 device connection; do not guess
|
||||
// privileged user-client types or enable performance collection.
|
||||
kern_return_t openStatus = KERN_SUCCESS;
|
||||
BOOL serviceInitialized = group != nil;
|
||||
if (!group) {
|
||||
openStatus = IOServiceOpen(service, mach_task_self(), 0, &connection);
|
||||
if (openStatus == KERN_SUCCESS) group = [[type alloc] initWithAcceleratorPort:connection];
|
||||
}
|
||||
BOOL connectionInitialized = group != nil;
|
||||
uint64_t registryID = 0;
|
||||
IORegistryEntryGetRegistryEntryID(service, ®istryID);
|
||||
NSArray<id<MTLDevice>> *metalDevices = MTLCopyAllDevices();
|
||||
BOOL metalPortAttempted = NO;
|
||||
for (id device in metalDevices) {
|
||||
if (!group && (metalDevices.count == 1 || [device registryID] == registryID) && [device respondsToSelector:@selector(acceleratorPort)]) {
|
||||
metalPortAttempted = YES;
|
||||
group = [[type alloc] initWithAcceleratorPort:[device acceleratorPort]];
|
||||
}
|
||||
}
|
||||
NSMutableArray *sources = [NSMutableArray array];
|
||||
for (id source in [group sourceList]) {
|
||||
NSMutableArray *counters = [NSMutableArray array];
|
||||
for (id counter in [source availableCounters]) {
|
||||
[counters addObject:@{@"name": [counter name] ?: @"", @"description": [counter description] ?: @""}];
|
||||
}
|
||||
[sources addObject:@{@"name": [source name] ?: @"", @"counters": counters}];
|
||||
}
|
||||
[devices addObject:@{@"serviceInitialized": @(serviceInitialized), @"connectionInitialized": @(connectionInitialized), @"metalPortAttempted": @(metalPortAttempted), @"initialized": @(group != nil), @"type0OpenStatus": @(openStatus), @"sources": sources}];
|
||||
group = nil;
|
||||
} @catch (NSException *exception) {
|
||||
[devices addObject:@{@"error": exception.reason ?: exception.name}];
|
||||
} @finally {
|
||||
if (connection != IO_OBJECT_NULL) IOServiceClose(connection);
|
||||
IOObjectRelease(service);
|
||||
}
|
||||
}
|
||||
IOObjectRelease(iterator);
|
||||
NSError *error = nil;
|
||||
NSDictionary *report = @{@"uid": @(getuid()), @"euid": @(geteuid()),
|
||||
@"devices": devices};
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:&error];
|
||||
if (!data) { fprintf(stderr, "%s\n", error.description.UTF8String); return 3; }
|
||||
puts([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding].UTF8String);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user