Skip to content

Commit

Permalink
Fix #8 and #9, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dehydratedpotato committed May 31, 2023
1 parent d29651e commit 2bd9613
Show file tree
Hide file tree
Showing 9 changed files with 1,929 additions and 0 deletions.
6 changes: 6 additions & 0 deletions iorepdump/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

CC=clang
CFLAGS=-fobjc-arc -funroll-loops -arch arm64 -lIOReport -framework Foundation

iorepdump:
$(CC) $(CFLAGS) -o iorepdump iorepdump.m
82 changes: 82 additions & 0 deletions iorepdump/iorepdump.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// iorepdump.m
// socpwrbud (iorepdump)
//
// Copyright (c) 2023 dehydratedpotato.
//

#include "../socpwrbud/socpwrbud.h"

extern CFMutableDictionaryRef IOReportCopyAllChannels(uint64_t, uint64_t);
extern int IOReportChannelGetFormat(CFDictionaryRef samples);

enum {
kIOReportInvalidFormat = 0,
kIOReportFormatSimple = 1,
kIOReportFormatState = 2,
kIOReportFormatSimpleArray = 4
};

NSString* getcpu(void)
{
size_t len = 32;
char* cpubrand = malloc(len);
sysctlbyname("machdep.cpu.brand_string", cpubrand, &len, NULL, 0);

NSString* ret = [NSString stringWithFormat:@"%s", cpubrand, nil];

free(cpubrand);

return ret;
}

int main(int argc, char* argv[])
{
@autoreleasepool
{
NSString* cpu = getcpu();
int clusters = 2;

if (([cpu rangeOfString:@"Pro"].location != NSNotFound) ||
([cpu rangeOfString:@"Max"].location != NSNotFound))
clusters = 3;
else if ([cpu rangeOfString:@"Ultra"].location != NSNotFound)
clusters = 6;

CFMutableDictionaryRef subchn = NULL;
CFMutableDictionaryRef chn = IOReportCopyAllChannels(0, 0);
IOReportSubscriptionRef sub = IOReportCreateSubscription(NULL, chn, &subchn, 0, 0);

IOReportIterate(IOReportCreateSamples(sub, subchn, NULL), ^(IOReportSampleRef sample) {
NSString* group = IOReportChannelGetGroup(sample);
NSString* subgroup = IOReportChannelGetSubGroup(sample);
NSString* chann_name = IOReportChannelGetChannelName(sample);

if ([group isEqual:@"CPU Stats"] ||
[group isEqual:@"GPU Stats"] ||
[group isEqual:@"AMC Stats"] ||
[group isEqual:@"CLPC Stats"] ||
[group isEqual:@"PMP"] ||
[group isEqual:@"Energy Model"]) {

switch (IOReportChannelGetFormat(sample)) {
case kIOReportFormatSimple:
printf("Grp: %s Subgrp: %s Chn: %s Int: %ld\n", [group UTF8String] , [subgroup UTF8String], [chann_name UTF8String], IOReportSimpleGetIntegerValue(sample, 0));
break;
case kIOReportFormatState:
for (int i = 0; i < IOReportStateGetCount(sample); i++)
printf("Grp: %s Subgrp: %s Chn: %s State: %s Res: %lld\n", [group UTF8String] , [subgroup UTF8String], [chann_name UTF8String], [IOReportStateGetNameForIndex(sample, i) UTF8String], IOReportStateGetResidency(sample, i));
break;
case kIOReportFormatSimpleArray:
for (int i = 0; i < clusters; i++)
printf("Grp: %s Subgrp: %s Chn: %s Arr: %lld\n", [group UTF8String] , [subgroup UTF8String], [chann_name UTF8String], IOReportArrayGetValueAtIndex(sample, i));
break;
}

}
return kIOReportIterOk;
});

return 0;
}
}
Loading

0 comments on commit 2bd9613

Please sign in to comment.