Skip to content

[none]: profiling experiment - #129

Open
tayloraswift wants to merge 3 commits into
masterfrom
profiling
Open

tayloraswift wants to merge 3 commits into
masterfrom
profiling

Conversation

@tayloraswift

Copy link
Copy Markdown
Member

No description provided.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces Linux perf event control to the benchmarking suite, allowing for more precise hardware/software event recording by wrapping the prctl system call. The changes include a new Perf utility and updates to the benchmark script to use perf record. Feedback focuses on ensuring cross-platform compatibility by adding #if os(Linux) guards to prevent linker errors on non-Linux systems, correcting a file path in the benchmark script, and removing debug print statements to maintain clean output.

Comment on lines +41 to +48
@_silgen_name("prctl")
private func prctl(
_ option: Int32,
_ arg2: UInt,
_ arg3: UInt,
_ arg4: UInt,
_ arg5: UInt
) -> Int32

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The prctl system call is specific to Linux. Declaring it with @_silgen_name without platform guards will lead to linker errors on other platforms (like macOS) that this package supports. Wrap the declaration in #if os(Linux).

Suggested change
@_silgen_name("prctl")
private func prctl(
_ option: Int32,
_ arg2: UInt,
_ arg3: UInt,
_ arg4: UInt,
_ arg5: UInt
) -> Int32
#if os(Linux)
@_silgen_name("prctl")
private func prctl(
_ option: Int32,
_ arg2: UInt,
_ arg3: UInt,
_ arg4: UInt,
_ arg5: UInt
) -> Int32
#endif

Comment thread Scripts/Benchmark Outdated
Benchmarks/.build/release/benchmark "Benchmarks/${subject}" > ${subject}.duration

which perf
perf record -F 8000 -g -- Benchmarks/.build/release/benchmark Swift.symbols.json

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The path to the JSON file in the perf record command is incorrect. Based on the previous lines in the script, the file is located in the Benchmarks/ directory.

Suggested change
perf record -F 8000 -g -- Benchmarks/.build/release/benchmark Swift.symbols.json
perf record -F 8000 -g -- Benchmarks/.build/release/benchmark "Benchmarks/${subject}"

Comment on lines +56 to +63
public static func enable() {
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(ENABLE) failed!")
} else {
print("enabled")
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The enable() method should be platform-guarded to prevent calling prctl on non-Linux systems. Also, removing the print("enabled") message is recommended to avoid polluting the benchmark's standard output.

Suggested change
public static func enable() {
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(ENABLE) failed!")
} else {
print("enabled")
}
}
public static func enable() {
#if os(Linux)
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_ENABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(ENABLE) failed!")
}
#endif
}

Comment on lines +66 to +73
public static func disable() {
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(DISABLE) failed!")
} else {
print("disabled")
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The disable() method should be platform-guarded. Removing the success message will also make the benchmark output cleaner.

Suggested change
public static func disable() {
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(DISABLE) failed!")
} else {
print("disabled")
}
}
public static func disable() {
#if os(Linux)
let status: Int32 = prctl(PR_TASK_PERF_EVENTS_DISABLE, 0, 0, 0, 0)
if status != 0 {
print("⚠️ WARNING: prctl(DISABLE) failed!")
}
#endif
}

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown
architecture subject benchmark duration
x86_64 Swift.symbols.json disabled
enabled
disabled
1.210914132 seconds
aarch64 Swift.symbols.json disabled
enabled
disabled
0.935429013 seconds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant