Skip to content

Commit 2a756e7

Browse files
yulnrrcoh
andauthored
fix: make perf-self-profile compile on macOS (#174)
* fix: make perf-self-profile compile on macOS Cfg-gates linux-specific code to allow compilation on non-linux platofrms. Also fixes missing required-features for blocking_pool_tracking example and silences dead code warnings that fired without the cpu-profiling feature enabled. * Gate entire cpu_sample_clock_alignment test * Remove dead PerfSampler methods * Replace glob re-exports with named imports * Add comment for Linux-specific EventSource variants * Add macOS to CI build matrix * Move prlimit into test step * Add perf sysctl to e2e trace workflow * Gate cpu_sample_clock_alignment test * Gate cpu profiling tests to linux * Restore macOS on the build matrix --------- Co-authored-by: Russell Cohen <rcoh@amazon.com>
1 parent 35bfa39 commit 2a756e7

27 files changed

Lines changed: 1112 additions & 974 deletions

.github/actions/rust-build/action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ runs:
2222
fi
2323
cargo build --all-targets --all-features
2424
- name: Enable perf_event_open and kallsyms for tests
25+
if: runner.os == 'Linux'
2526
shell: bash
2627
run: |
2728
sudo sysctl kernel.perf_event_paranoid=1
@@ -31,6 +32,8 @@ runs:
3132
env:
3233
RUSTFLAGS: "--cfg tokio_unstable"
3334
run: |
34-
# Raise locked-memory limit for large perf ring buffers
35-
sudo prlimit --pid $$ --memlock=unlimited:unlimited
35+
if [ "$RUNNER_OS" = "Linux" ]; then
36+
# Raise locked-memory limit for large perf ring buffers
37+
sudo prlimit --pid $$ --memlock=unlimited:unlimited
38+
fi
3639
cargo test --all-features

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ jobs:
2929
RUSTFLAGS: "--cfg tokio_unstable"
3030

3131
build:
32-
name: Build (${{ matrix.toolchain }})
33-
runs-on: ubuntu-latest
32+
name: Build (${{ matrix.os }}, ${{ matrix.toolchain }})
33+
runs-on: ${{ matrix.os }}
3434
strategy:
3535
matrix:
36+
os: [ubuntu-latest, macos-latest]
3637
toolchain: [stable, nightly]
3738
env:
3839
RUST_BACKTRACE: 1

dial9-tokio-telemetry/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ harness = false
7777
name = "e2e_workload"
7878
harness = false
7979

80+
[[example]]
81+
name = "blocking_pool_tracking"
82+
required-features = ["cpu-profiling"]
83+
8084
[[example]]
8185
name = "blocking_sleep"
8286
required-features = ["cpu-profiling"]

dial9-tokio-telemetry/src/telemetry/events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ pub(crate) enum RawEvent {
301301
target_worker: u8,
302302
},
303303
/// A CPU stack trace sample from perf_event, attributed to a worker thread.
304+
#[cfg_attr(not(feature = "cpu-profiling"), allow(dead_code))]
304305
CpuSample(Box<CpuSampleData>),
305306
}
306307

dial9-tokio-telemetry/src/telemetry/recorder/event_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl EventWriter {
3737
}
3838

3939
/// Encode a RawEvent into a batch and write it through the writer.
40-
#[cfg(test)]
40+
#[cfg(all(test, feature = "cpu-profiling"))]
4141
pub(crate) fn write_raw_event(
4242
&mut self,
4343
raw: crate::telemetry::events::RawEvent,

dial9-tokio-telemetry/tests/background_symbolization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Verifies that when cpu-profiling is configured with a trace path,
44
//! the background worker symbolizes sealed segments and writes them
55
//! back to disk with gzip compression.
6-
#![cfg(feature = "cpu-profiling")]
6+
#![cfg(all(feature = "cpu-profiling", target_os = "linux"))]
77

88
use dial9_tokio_telemetry::telemetry::cpu_profile::CpuProfilingConfig;
99
use dial9_tokio_telemetry::telemetry::{RotatingWriter, TracedRuntime};

dial9-tokio-telemetry/tests/cpu_sample_clock_alignment.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
//! by finding the `PollStart` event whose time interval (PollStart →
1313
//! corresponding PollEnd) contains the burn window.
1414
15+
#![cfg(all(feature = "cpu-profiling", target_os = "linux"))]
16+
1517
mod common;
1618

17-
#[cfg(feature = "cpu-profiling")]
1819
#[test]
1920
fn cpu_sample_timestamps_align_with_wall_clock() {
2021
let _ = tracing_subscriber::fmt::try_init();
@@ -235,7 +236,6 @@ fn cpu_sample_timestamps_align_with_wall_clock() {
235236
}
236237
}
237238

238-
#[cfg(feature = "cpu-profiling")]
239239
fn burn_cpu(duration: std::time::Duration) {
240240
let start = std::time::Instant::now();
241241
let mut x: u64 = 1;
@@ -256,7 +256,6 @@ fn burn_cpu(duration: std::time::Duration) {
256256
/// `/proc/self/task/<tid>/comm` while the threads are still alive. The final
257257
/// `ThreadNameDef` emission happens later at write time, after the threads
258258
/// have exited — proving the eager cache is necessary.
259-
#[cfg(feature = "cpu-profiling")]
260259
#[test]
261260
fn thread_name_attribution_for_external_and_blocking_threads() {
262261
let _ = tracing_subscriber::fmt::try_init();

dial9-tokio-telemetry/tests/sched_clock_alignment.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
//! CLOCK_MONOTONIC_RAW instead of CLOCK_MONOTONIC, timestamps would drift
88
//! and events would fall outside the expected windows.
99
10+
#![cfg(all(feature = "cpu-profiling", target_os = "linux"))]
11+
1012
mod common;
1113

12-
#[cfg(feature = "cpu-profiling")]
1314
#[test]
1415
fn sched_event_timestamps_align_with_wall_clock() {
1516
use dial9_tokio_telemetry::telemetry::TracedRuntime;

dial9-tokio-telemetry/tests/sched_events.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Integration test: sched event capture via per-thread perf profiling.
22
3+
#![cfg(all(feature = "cpu-profiling", target_os = "linux"))]
4+
35
mod common;
46

5-
#[cfg(feature = "cpu-profiling")]
67
#[test]
78
fn sched_events_capture_context_switches() {
89
use dial9_tokio_telemetry::telemetry::CpuSampleSource;

dial9-tokio-telemetry/tests/writeback_no_leaked_gz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! the original `.bin`. When the writer evicts old segments, it must also
55
//! clean up the renamed `.bin.gz` variants. A leak here means unbounded disk
66
//! growth in production.
7-
#![cfg(feature = "cpu-profiling")]
7+
#![cfg(all(feature = "cpu-profiling", target_os = "linux"))]
88

99
use dial9_tokio_telemetry::telemetry::cpu_profile::CpuProfilingConfig;
1010
use dial9_tokio_telemetry::telemetry::{RotatingWriter, TracedRuntime};

0 commit comments

Comments
 (0)