I’m trying to create a function that returns frequency of IOS device’s processor. The code I am using always returns zero. Where am I going wrong?
-(void) printProcessorInfo
{
size_t length;
int mib[6];
int result;
printf("Processor Info\n");
printf("--------------\n");
mib[0] = CTL_HW;
mib[1] = HW_CPU_FREQ;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting cpu frequency");
}
printf("CPU Frequency = %d hz\n", result);
mib[0] = CTL_HW;
mib[1] = HW_BUS_FREQ;
length = sizeof(result);
if (sysctl(mib, 2, &result, &length, NULL, 0) < 0)
{
perror("getting bus frequency");
}
printf("Bus Frequency = %d hz\n", result);
printf("\n");
}
Thanks
The code is OK — iOS doesn’t return the CPU freq for some (or possibly all) devices. E.g., I think the clock rate of the Apple A4 in the iPod 4th gen devices is still unknown.
The best you can do is estimate the clock rate.