Skip to content

Only output number of executed instructions in swift-parser-cli on macOS #1462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/_InstructionCounter/include/InstructionsExecuted.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@

#include <unistd.h>

/// 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();
14 changes: 14 additions & 0 deletions Sources/_InstructionCounter/src/InstructionsExecuted.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@
//
//===----------------------------------------------------------------------===//

#if __APPLE__
#include <TargetConditionals.h>
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
#define TARGET_IS_MACOS 1
#endif
#endif

#include "InstructionsExecuted.h"

#ifdef TARGET_IS_MACOS
#include <libproc.h>
#include <sys/resource.h>

Expand All @@ -21,3 +30,8 @@ uint64_t getInstructionsExecuted() {
}
return 0;
}
#else
uint64_t getInstructionsExecuted() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to see if we can do something cross platform here, but fine for now I suppose 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. But let’s wait to see if a need comes up first since this is just a testing utility anyway.

return 0;
}
#endif
6 changes: 5 additions & 1 deletion Sources/swift-parser-cli/swift-parser-cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))")
}
}
}

Expand Down