diff --git a/Sources/_InstructionCounter/include/InstructionsExecuted.h b/Sources/_InstructionCounter/include/InstructionsExecuted.h index 49f8964370a..39fef28bfe8 100644 --- a/Sources/_InstructionCounter/include/InstructionsExecuted.h +++ b/Sources/_InstructionCounter/include/InstructionsExecuted.h @@ -12,6 +12,6 @@ #include -/// Returns the number of instructions the process has executed since it was -/// launched. +/// On macOS returns the number of instructions the process has executed since +/// it was launched, on all other platforms returns 0. uint64_t getInstructionsExecuted(); diff --git a/Sources/_InstructionCounter/src/InstructionsExecuted.c b/Sources/_InstructionCounter/src/InstructionsExecuted.c index d071e1a55b0..132d45fa799 100644 --- a/Sources/_InstructionCounter/src/InstructionsExecuted.c +++ b/Sources/_InstructionCounter/src/InstructionsExecuted.c @@ -10,7 +10,16 @@ // //===----------------------------------------------------------------------===// +#if __APPLE__ +#include +#if TARGET_OS_MAC && !TARGET_OS_IPHONE +#define TARGET_IS_MACOS 1 +#endif +#endif + #include "InstructionsExecuted.h" + +#ifdef TARGET_IS_MACOS #include #include @@ -21,3 +30,8 @@ uint64_t getInstructionsExecuted() { } return 0; } +#else +uint64_t getInstructionsExecuted() { + return 0; +} +#endif diff --git a/Sources/swift-parser-cli/swift-parser-cli.swift b/Sources/swift-parser-cli/swift-parser-cli.swift index cf9637f5ad7..1e87ff2f3d0 100644 --- a/Sources/swift-parser-cli/swift-parser-cli.swift +++ b/Sources/swift-parser-cli/swift-parser-cli.swift @@ -190,7 +190,11 @@ class PerformanceTest: ParsableCommand { let endDate = Date() print("Time: \(endDate.timeIntervalSince(start) / Double(self.iterations) * 1000)ms") - print("Instructions: \(Double(endInstructions - startInstructions) / Double(self.iterations))") + if endInstructions != startInstructions { + // endInstructions == startInstructions only happens if we are on non-macOS + // platforms that don't support `getInstructionsExecuted`. Don't display anything. + print("Instructions: \(Double(endInstructions - startInstructions) / Double(self.iterations))") + } } }