From 246ee86428758be3d3af1d2c502086eb6036d9fe Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Tue, 24 Jan 2017 20:31:14 +0100 Subject: [PATCH] Disable iOS CPU Frequency readout (#335) * Add macro definition for iOS Add an additional macro definition for iOS. iOS is defined as a Mac OSX invariant in the TargetConditionals include, thus we treat it as a subset of OSX within the defines. * Skip error for hw.cpufrequency on iOS hw.cpufrequency is not available on iOS devices. As there is no way to reliably retrieve the CPU frequency on iOS we are printing out a warning that we were unable to detect the CPU frequency and set it to 0. This only disables cpu frequency readouts on actual physical iOS devices. Running this code on the simulator still gives the cpu architecture of the host computer as the simulator passes down the sysctl calls to OSX. --- src/internal_macros.h | 10 +++++++--- src/sysinfo.cc | 5 +++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/internal_macros.h b/src/internal_macros.h index 46913f41..2b3f32f3 100644 --- a/src/internal_macros.h +++ b/src/internal_macros.h @@ -30,9 +30,13 @@ #elif defined(_WIN32) #define BENCHMARK_OS_WINDOWS 1 #elif defined(__APPLE__) -// TODO(ericwf) This doesn't actually check that it is a Mac OSX system. Just -// that it is an apple system. -#define BENCHMARK_OS_MACOSX 1 +#include "TargetConditionals.h" + #if defined(TARGET_OS_MAC) + #define BENCHMARK_OS_MACOSX 1 + #if defined(TARGET_OS_IPHONE) + #define BENCHMARK_OS_IOS 1 + #endif + #endif #elif defined(__FreeBSD__) #define BENCHMARK_OS_FREEBSD 1 #elif defined(__linux__) diff --git a/src/sysinfo.cc b/src/sysinfo.cc index dd1e6630..34f9871c 100644 --- a/src/sysinfo.cc +++ b/src/sysinfo.cc @@ -295,8 +295,13 @@ void InitializeSystemInfo() { (size == sizeof(cpu_freq))) { cpuinfo_cycles_per_second = cpu_freq; } else { + #if defined BENCHMARK_OS_IOS + fprintf(stderr, "CPU frequency cannot be detected. \n"); + cpuinfo_cycles_per_second = 0; + #else fprintf(stderr, "%s\n", strerror(errno)); std::exit(EXIT_FAILURE); + #endif } #else // Generic cycles per second counter