Skip to content
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
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
components: rustfmt, clippy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files

lint-windows:
runs-on: windows-latest
test-codspeed:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: moonrepo/setup-rust@v1
with:
components: rustfmt, clippy
- uses: pre-commit/action@v3.0.1
with:
extra_args: --all-files
cache-target: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: cargo test -p codspeed

msrv-check:
runs-on: ubuntu-latest
Expand All @@ -41,6 +46,8 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
bins: cargo-msrv
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check cospeed MSRV
run: cargo msrv --path crates/codspeed verify -- cargo check --all-features --config codspeed=true
- name: Check bencher_compat MSRV
Expand All @@ -57,6 +64,8 @@ jobs:
with:
submodules: true
- uses: moonrepo/setup-rust@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: cargo test --all

compat-integration-test-instrumentation:
Expand All @@ -76,6 +85,8 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
cache-target: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: cargo install --path crates/cargo-codspeed --locked

Expand Down Expand Up @@ -105,6 +116,8 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
cache-target: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: cargo install --path crates/cargo-codspeed --locked

Expand Down Expand Up @@ -139,6 +152,8 @@ jobs:
- uses: moonrepo/setup-rust@v1
with:
targets: ${{ matrix.target }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install musl tools
run: sudo apt-get update && sudo apt-get install -y musl-tools
Expand All @@ -150,7 +165,7 @@ jobs:
if: always()
needs:
- lint
- lint-windows
- test-codspeed
- msrv-check
- tests
- compat-integration-test-instrumentation
Expand Down
5 changes: 5 additions & 0 deletions crates/codspeed/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use std::{env, path::PathBuf};

fn main() {
if cfg!(not(target_os = "linux")) {
// The instrument-hooks library is only supported on Linux.
return;
}

// Compile the C library
cc::Build::new()
.file("instrument-hooks/dist/core.c")
Expand Down
2 changes: 1 addition & 1 deletion crates/codspeed/instrument-hooks
31 changes: 24 additions & 7 deletions crates/codspeed/src/instrument_hooks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#[cfg(unix)]
#[cfg(target_os = "linux")]
mod ffi;

#[cfg(unix)]
mod unix_impl {
#[cfg(target_os = "linux")]
mod linux_impl {
use nix::sys::time::TimeValLike;

use super::ffi;
Expand Down Expand Up @@ -131,7 +131,7 @@ mod unix_impl {
}
}

#[cfg(not(unix))]
#[cfg(not(target_os = "linux"))]
mod other_impl {
pub struct InstrumentHooks;

Expand Down Expand Up @@ -169,8 +169,25 @@ mod other_impl {
}
}

#[cfg(unix)]
pub use unix_impl::InstrumentHooks;
#[cfg(target_os = "linux")]
pub use linux_impl::InstrumentHooks;

#[cfg(not(unix))]
#[cfg(not(target_os = "linux"))]
pub use other_impl::InstrumentHooks;

#[cfg(test)]
mod tests {
use super::InstrumentHooks;

#[test]
fn test_instrument_hooks() {
let hooks = InstrumentHooks::instance();
assert!(!hooks.is_instrumented() || hooks.start_benchmark().is_ok());
assert!(hooks.set_executed_benchmark("test_uri").is_ok());
assert!(hooks.set_integration("test_integration", "1.0.0").is_ok());
let start = InstrumentHooks::current_timestamp();
let end = start + 1_000_000; // Simulate 1ms later
hooks.add_benchmark_timestamps(start, end);
assert!(!hooks.is_instrumented() || hooks.stop_benchmark().is_ok());
}
}