diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e36aba6..146d266 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ jobs: - name: Install uses: actions-rs/toolchain@v1 with: - toolchain: beta + toolchain: 1.66.0 profile: minimal override: true - name: Build @@ -48,7 +48,7 @@ jobs: - name: Install uses: actions-rs/toolchain@v1 with: - toolchain: beta + toolchain: stable target: ${{ matrix.target }} profile: minimal override: true diff --git a/Cargo.toml b/Cargo.toml index 49e11cb..c904ec1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ -[project] +[package] name = "probe" -version = "0.3.0" +version = "0.4.0" authors = ["Josh Stone "] description = "Static instrumentation probes" documentation = "https://docs.rs/probe/" @@ -8,6 +8,7 @@ homepage = "https://github.com/cuviper/rust-libprobe" repository = "https://github.com/cuviper/rust-libprobe" license = "Apache-2.0 OR MIT" edition = "2021" +rust-version = "1.66" exclude = ["/.github/**"] [lib] diff --git a/README.md b/README.md index 2cffcfc..d8cb9c2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # libprobe: Static probes for Rust [![probe crate](https://img.shields.io/crates/v/probe.svg)](https://crates.io/crates/probe) -![minimum rustc 1.59](https://img.shields.io/badge/rustc-1.59+-red.svg) +![minimum rustc 1.66](https://img.shields.io/badge/rustc-1.66+-red.svg) [![probe documentation](https://docs.rs/probe/badge.svg)](https://docs.rs/probe) [![build status](https://github.com/cuviper/rust-libprobe/workflows/CI/badge.svg)](https://github.com/cuviper/rust-libprobe/actions) @@ -20,7 +20,7 @@ The recommended way to use it is to add a line into your Cargo.toml such as: ```toml [dependencies] -probe = "0.3" +probe = "0.4" ``` Then `use probe::probe;` in your code and insert macro calls wherever you want diff --git a/examples/semaphore.rs b/examples/semaphore.rs new file mode 100644 index 0000000..b53c60b --- /dev/null +++ b/examples/semaphore.rs @@ -0,0 +1,16 @@ +use probe::probe; + +fn main() { + let mut iter = 0; + loop { + iter += 1; + probe!(foo, iter, { + // This delay is an exaggeration of the overhead of a probe argument, but it's only + // incurred while something is attached to the probe, thanks to the semaphore. + std::thread::sleep(std::time::Duration::from_secs(1)); + iter + }); + } +} + +// bcc/tools/trace.py -p $(pidof semaphore) 'u::foo:iter "iter = %d", arg1' diff --git a/src/platform/default.rs b/src/platform/default.rs index 21aeed8..39d4f04 100644 --- a/src/platform/default.rs +++ b/src/platform/default.rs @@ -1,5 +1,10 @@ #[doc(hidden)] #[macro_export] macro_rules! platform_probe( - ($provider:ident, $name:ident, $($arg:expr,)*) => () + ($provider:ident, $name:ident, $($arg:expr,)*) => ({ + // Expand the arguments so they don't cause unused warnings. + if false { + let _ = ($($arg,)*); + } + }) ); diff --git a/src/platform/systemtap.rs b/src/platform/systemtap.rs index e05ba6f..82413b8 100644 --- a/src/platform/systemtap.rs +++ b/src/platform/systemtap.rs @@ -101,7 +101,9 @@ macro_rules! sdt_asm( #[macro_export] macro_rules! _sdt_asm( ($size:literal, options ($($opt:ident),*), $provider:ident, $name:ident, $($argstr:literal, $arg:expr,)*) => ( - ::core::arch::asm!(concat!(r#" + static mut SEMAPHORE: u16 = 0; + if ::core::ptr::read_volatile(&SEMAPHORE) != 0 { + ::core::arch::asm!(concat!(r#" 990: nop .pushsection .note.stapsdt,"?","note" .balign 4 @@ -110,7 +112,7 @@ macro_rules! _sdt_asm( 992: .balign 4 993: ."#, $size, r#"byte 990b ."#, $size, r#"byte _.stapsdt.base - ."#, $size, r#"byte 0 // FIXME set semaphore address + ."#, $size, r#"byte {} .asciz ""#, stringify!($provider), r#"" .asciz ""#, stringify!($name), r#"" .asciz ""#, $($argstr,)* r#"" @@ -123,10 +125,10 @@ macro_rules! _sdt_asm( _.stapsdt.base: .space 1 .size _.stapsdt.base, 1 .popsection -.endif -"# - ), - $(in(reg) (($arg) as isize) ,)* - options(readonly, nostack, preserves_flags, $($opt),*), - ) +.endif"#), + sym SEMAPHORE, + $(in(reg) (($arg) as isize) ,)* + options(readonly, nostack, preserves_flags, $($opt),*), + ); + } ));