-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.m
62 lines (49 loc) · 2.74 KB
/
test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Testing out IOReport
*
* code by dehydratedpotato, 2023
*/
#import <Foundation/Foundation.h>
#import "IOReport_decompile.h"
typedef uint8_t IOReportFormat;
enum {
kIOReportInvalidFormat = 0,
kIOReportFormatSimple = 1,
kIOReportFormatState = 2,
kIOReportFormatHistogram = 3,
kIOReportFormatSimpleArray = 4
};
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString * group = @"CPU Stats";
CFMutableDictionaryRef chn = IOReportCopyChannelsInGroup(group, 0, 0, 0, 0); // or IOReportCopyAllChannels(0, 0);
CFMutableDictionaryRef subchn = NULL; // can be omitted, as there seemed to be no use for this param, so I added no logic for it ;)
IOReportSubscriptionRef sub = IOReportCreateSubscription(NULL, chn, &subchn, 0, 0);
CFDictionaryRef samples = IOReportCreateSamples(sub, chn, NULL);
IOReportIterate(samples, ^(IOReportSampleRef sample) {
NSString* subgroup = IOReportChannelGetSubGroup(sample);
NSString* group = IOReportChannelGetGroup(sample);
NSString* driver = IOReportChannelGetDriverName(sample);
NSString* chann_name = IOReportChannelGetChannelName(sample);
NSString* unit_label = IOReportChannelGetUnitLabel(sample);
int chann_format = IOReportChannelGetFormat(sample);
if (chann_format == kIOReportFormatState) {
long state_count = IOReportStateGetCount(sample);
NSString* idx_name = IOReportStateGetNameForIndex(sample, 0);
uint64_t residency = IOReportStateGetResidency(sample, 0);
NSLog(@"driver: %@ group: %@ subgroup: %@ unit_label: %@, state_name: %@ chann_name: %@ chann_format: %u state_cnt: %ld res: %llu", driver, group, subgroup, unit_label, idx_name, chann_name, chann_format, state_count, residency);
} else if (chann_format == kIOReportFormatSimple) {
long state_count = IOReportStateGetCount(sample);
NSString* idx_name = IOReportStateGetNameForIndex(sample, 0);
long residency = IOReportSimpleGetIntegerValue(sample, 0);
NSLog(@"driver: %@ group: %@ subgroup: %@ unit_label: %@, state_name: %@ chann_name: %@ chann_format: %u state_cnt: %ld integer: %ld", driver, group, subgroup, unit_label, idx_name, chann_name, chann_format, state_count, residency);
}
else {
NSLog(@"driver: %@ group: %@ subgroup: %@ unit_label: %@ chann_name: %@ chann_format: %u value: %llu", driver, group, subgroup, unit_label, chann_name, chann_format, 0llu);
}
return re_kIOReportIterOk;
});
CFRelease(chn);
CFRelease(samples);
}
return 0;
}