diff --git a/Cargo.lock b/Cargo.lock index 08fd9350..fa21fd6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "once_cell", "version_check", "zerocopy 0.7.35", @@ -292,7 +292,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff" dependencies = [ - "clap 4.5.36", + "clap 4.5.37", "heck 0.4.1", "indexmap 2.9.0", "log", @@ -386,9 +386,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.36" +version = "4.5.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2df961d8c8a0d08aa9945718ccf584145eee3f3aa06cddbeac12933781102e04" +checksum = "eccb054f56cbd38340b380d4a8e69ef1f02f1af43db2f0cc817a4774d80ae071" dependencies = [ "clap_builder", "clap_derive 4.5.32", @@ -396,9 +396,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.36" +version = "4.5.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "132dbda40fb6753878316a489d5a1242a8ef2f0d9e47ba01c951ea8aa7d013a5" +checksum = "efd9466fac8543255d3b1fcad4762c5e116ffe808c8a3043d4263cd4fd4862a2" dependencies = [ "anstream", "anstyle", @@ -738,6 +738,7 @@ version = "0.1.0" dependencies = [ "cbindgen", "ffikit", + "libc", "log", "pretty_env_logger", "pyroscope", @@ -858,9 +859,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "js-sys", @@ -1296,7 +1297,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "232929e1d75fe899576a3d5c7416ad0d88dbfbb3c3d6aa00873a7408a50ddb88" dependencies = [ "ahash", - "clap 4.5.36", + "clap 4.5.37", "crossbeam-channel", "crossbeam-utils", "dashmap", @@ -1319,7 +1320,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2094aecddc672e902cd773bad7071542f63641e01e9187c3bba4b43005e837e9" dependencies = [ "ahash", - "clap 4.5.36", + "clap 4.5.37", "crossbeam-channel", "crossbeam-utils", "dashmap", @@ -1420,9 +1421,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "jiff" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ad87c89110f55e4cd4dc2893a9790820206729eaf221555f742d540b0724a0" +checksum = "5a064218214dc6a10fbae5ec5fa888d80c45d611aba169222fc272072bf7aef6" dependencies = [ "jiff-static", "log", @@ -1433,9 +1434,9 @@ dependencies = [ [[package]] name = "jiff-static" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d076d5b64a7e2fe6f0743f02c43ca4a6725c0f904203bfe276a5b3e793103605" +checksum = "199b7932d97e325aff3a7030e141eafe7f2c6268e1d1b24859b753a627f45254" dependencies = [ "proc-macro2", "quote", @@ -1500,9 +1501,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.11" +version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" +checksum = "c9627da5196e5d8ed0b0495e61e518847578da83483c37288316d9b2e03a7f72" [[package]] name = "libproc" @@ -1978,9 +1979,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -2084,7 +2085,7 @@ dependencies = [ name = "pyroscope-cli" version = "1.0.1" dependencies = [ - "clap 4.5.36", + "clap 4.5.37", "ctrlc", "duct", "env_logger 0.11.8", @@ -2177,13 +2178,13 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.10" +version = "0.11.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b820744eb4dc9b57a3398183639c511b5a26d2ed702cedd3febaa1393caa22cc" +checksum = "bcbafbbdbb0f638fe3f35f3c56739f77a8a1d070cb25603226c83339b391472b" dependencies = [ "bytes", "getrandom 0.3.2", - "rand 0.9.0", + "rand 0.9.1", "ring", "rustc-hash 2.1.1", "rustls", @@ -2237,13 +2238,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3779b94aeb87e8bd4e834cee3650289ee9e0d5677f976ecdb6d219e5f4f6cd94" +checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" dependencies = [ "rand_chacha 0.9.0", "rand_core 0.9.3", - "zerocopy 0.8.24", ] [[package]] @@ -2272,7 +2272,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", ] [[package]] @@ -2302,7 +2302,7 @@ checksum = "5d04acc3f231fe2902e0e1c618f403b809c6f83f96b017a64ee2f69e28569962" dependencies = [ "anyhow", "chrono", - "clap 4.5.36", + "clap 4.5.37", "ctrlc", "directories", "env_logger 0.11.8", @@ -2316,7 +2316,7 @@ dependencies = [ "nix 0.29.0", "proc-maps", "prost", - "rand 0.9.0", + "rand 0.9.1", "rbspy-ruby-structs", "remoteprocess", "semver", @@ -2363,7 +2363,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" dependencies = [ - "getrandom 0.2.15", + "getrandom 0.2.16", "libredox", "thiserror 2.0.12", ] @@ -2485,7 +2485,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" dependencies = [ "cc", "cfg-if", - "getrandom 0.2.15", + "getrandom 0.2.16", "libc", "untrusted", "windows-sys 0.52.0", @@ -2750,9 +2750,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" -version = "1.4.2" +version = "1.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +checksum = "9203b8055f63a2a00e2f593bb0510367fe707d7ff1e5c872de2f537b339e5410" dependencies = [ "libc", ] @@ -2846,9 +2846,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "symbolic-common" -version = "12.15.3" +version = "12.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb426702a1ee7c1d2ebf3b6fac2e67fde84f6d6396e581826e3f055d1bffb2a4" +checksum = "23eae23242dffa2e8e66c0e20f4ca1e28391f64e361db1e921a209c9bc70ec3a" dependencies = [ "debugid", "memmap2", @@ -2858,9 +2858,9 @@ dependencies = [ [[package]] name = "symbolic-demangle" -version = "12.15.3" +version = "12.15.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4671b7ae11875cb9c34348d2df6c5d1edd51f4c98ec45f591acb593ac8af8e0" +checksum = "153faacda0d58dc1eb3e8bbd5dab998041e95bd7f4ab2caeeadc89410617f144" dependencies = [ "cpp_demangle", "rustc-demangle", @@ -3009,14 +3009,6 @@ dependencies = [ "syn 2.0.100", ] -[[package]] -name = "thread_id" -version = "0.1.0" -dependencies = [ - "cbindgen", - "libc", -] - [[package]] name = "tinystr" version = "0.7.6" diff --git a/Cargo.toml b/Cargo.toml index e14eedca..4d1df28c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,6 @@ members = [ "pyroscope_backends/pyroscope_pyspy", "pyroscope_cli", "pyroscope_ffi/ruby/ext/rbspy", - "pyroscope_ffi/ruby/ext/thread_id", "pyroscope_ffi/python/lib", "pyroscope_ffi/ffikit", ] diff --git a/docker/gem.Dockerfile b/docker/gem.Dockerfile index 763bf557..47bc6011 100644 --- a/docker/gem.Dockerfile +++ b/docker/gem.Dockerfile @@ -22,7 +22,6 @@ ADD pyroscope_cli pyroscope_cli ADD pyroscope_ffi/ pyroscope_ffi/ # TODO --frozen RUN --mount=type=cache,target=/root/.cargo/registry cargo build -p ffiruby --release -RUN --mount=type=cache,target=/root/.cargo/registry cargo build -p thread_id --release FROM ruby:3.3 as builder-gem WORKDIR /gem @@ -31,7 +30,6 @@ ADD pyroscope_ffi/ruby /gem/ RUN bundle install COPY --from=builder /pyroscope-rs/target/release/librbspy.so lib/rbspy/rbspy.so -COPY --from=builder /pyroscope-rs/target/release/libthread_id.so lib/thread_id/thread_id.so ARG TARGET_TASK RUN rake ${TARGET_TASK} diff --git a/ffi.mk b/ffi.mk index 7afbd888..95f0286a 100644 --- a/ffi.mk +++ b/ffi.mk @@ -69,7 +69,6 @@ gem/mac/amd64: pyroscope_ffi/clean cd pyroscope_ffi/ruby && \ bundle && \ RUST_TARGET=x86_64-apple-darwin rake rbspy_install && \ - RUST_TARGET=x86_64-apple-darwin rake thread_id_install && \ RUST_TARGET=x86_64-apple-darwin rake x86_64_darwin:gem .phony: gem/mac/arm64 @@ -77,5 +76,4 @@ gem/mac/arm64: pyroscope_ffi/clean cd pyroscope_ffi/ruby && \ bundle && \ RUST_TARGET=aarch64-apple-darwin rake rbspy_install && \ - RUST_TARGET=aarch64-apple-darwin rake thread_id_install && \ RUST_TARGET=aarch64-apple-darwin rake arm64_darwin:gem \ No newline at end of file diff --git a/pyroscope_ffi/ruby/Makefile b/pyroscope_ffi/ruby/Makefile index b7e9bf39..4863200a 100644 --- a/pyroscope_ffi/ruby/Makefile +++ b/pyroscope_ffi/ruby/Makefile @@ -2,11 +2,8 @@ .phony: dev dev: cd ext/rbspy && cargo build --frozen --offline - cd ext/thread_id && cargo build --frozen --offline mkdir -p lib/rbspy/ cp ../../target/debug/librbspy.so lib/rbspy/rbspy.so - mkdir -p lib/thread_id/ - cp ../../target/debug/libthread_id.so lib/thread_id/thread_id.so bundle install rake x86_64_linux:gem # todo wth is it so slow for i in $$(ls -tr pkg/pyroscope-*-x86_64-linux.gem | tail -n 1); do gem install ./$$i; done; diff --git a/pyroscope_ffi/ruby/Rakefile b/pyroscope_ffi/ruby/Rakefile index bd388667..c5e17dcb 100644 --- a/pyroscope_ffi/ruby/Rakefile +++ b/pyroscope_ffi/ruby/Rakefile @@ -13,7 +13,6 @@ rescue Bundler::BundlerError => e exit e.status_code end -load File.expand_path('./ext/thread_id/Rakefile', __dir__) load File.expand_path('./ext/rbspy/Rakefile', __dir__) task default: %w[hello] @@ -33,7 +32,6 @@ namespace :x86_64_darwin do spec = Bundler.load_gemspec('pyroscope.gemspec') spec.platform = 'x86_64-darwin' spec.files += FileList['lib/rbspy/rbspy.*'] - spec.files += FileList['lib/thread_id/thread_id.*'] spec.extensions = [] Gem::PackageTask.new(spec) do |pkg| @@ -44,7 +42,6 @@ namespace :arm64_darwin do spec = Bundler.load_gemspec('pyroscope.gemspec') spec.platform = 'arm64-darwin' spec.files += FileList['lib/rbspy/rbspy.*'] - spec.files += FileList['lib/thread_id/thread_id.*'] spec.extensions = [] Gem::PackageTask.new(spec) do |pkg| @@ -56,7 +53,6 @@ namespace :x86_64_linux do spec.platform = 'x86_64-linux' spec.files += FileList['lib/rbspy/rbspy.*'] spec.files += FileList['lib/rbspy.libs/*'] - spec.files += FileList['lib/thread_id/thread_id.*'] spec.extensions = [] Gem::PackageTask.new(spec) do |pkg| @@ -68,7 +64,6 @@ namespace :aarch64_linux do spec.platform = 'aarch64-linux' spec.files += FileList['lib/rbspy/rbspy.*'] spec.files += FileList['lib/rbspy.libs/*'] - spec.files += FileList['lib/thread_id/thread_id.*'] spec.extensions = [] Gem::PackageTask.new(spec) do |pkg| diff --git a/pyroscope_ffi/ruby/ext/rbspy/Cargo.toml b/pyroscope_ffi/ruby/ext/rbspy/Cargo.toml index a8c5cdcf..9fef5c3e 100644 --- a/pyroscope_ffi/ruby/ext/rbspy/Cargo.toml +++ b/pyroscope_ffi/ruby/ext/rbspy/Cargo.toml @@ -15,6 +15,7 @@ ffikit = { path = "../../../ffikit" } # todo remove this dependency pretty_env_logger = "0.5" log = "0.4" +libc = "0.2.171" [build-dependencies] cbindgen = "0.28" diff --git a/pyroscope_ffi/ruby/ext/rbspy/include/rbspy.h b/pyroscope_ffi/ruby/ext/rbspy/include/rbspy.h index a7e2f36e..6ba9d41e 100644 --- a/pyroscope_ffi/ruby/ext/rbspy/include/rbspy.h +++ b/pyroscope_ffi/ruby/ext/rbspy/include/rbspy.h @@ -32,9 +32,9 @@ bool initialize_agent(const char *application_name, bool drop_agent(void); -bool add_thread_tag(uint64_t thread_id, const char *key, const char *value); +bool add_thread_tag(const char *key, const char *value); -bool remove_thread_tag(uint64_t thread_id, const char *key, const char *value); +bool remove_thread_tag(const char *key, const char *value); bool add_global_tag(const char *key, const char *value); diff --git a/pyroscope_ffi/ruby/ext/rbspy/src/lib.rs b/pyroscope_ffi/ruby/ext/rbspy/src/lib.rs index 2fc5ace6..c3ee9ee2 100644 --- a/pyroscope_ffi/ruby/ext/rbspy/src/lib.rs +++ b/pyroscope_ffi/ruby/ext/rbspy/src/lib.rs @@ -276,7 +276,7 @@ pub extern "C" fn drop_agent() -> bool { } #[no_mangle] -pub extern "C" fn add_thread_tag(thread_id: u64, key: *const c_char, value: *const c_char) -> bool { +pub extern "C" fn add_thread_tag(key: *const c_char, value: *const c_char) -> bool { let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned(); let value = unsafe { CStr::from_ptr(value) } .to_str() @@ -285,6 +285,7 @@ pub extern "C" fn add_thread_tag(thread_id: u64, key: *const c_char, value: *con let pid = std::process::id(); let mut hasher = DefaultHasher::new(); + let thread_id = thread_id(); hasher.write_u64(thread_id % pid as u64); let id = hasher.finish(); @@ -295,7 +296,7 @@ pub extern "C" fn add_thread_tag(thread_id: u64, key: *const c_char, value: *con #[no_mangle] pub extern "C" fn remove_thread_tag( - thread_id: u64, key: *const c_char, value: *const c_char, + key: *const c_char, value: *const c_char, ) -> bool { let key = unsafe { CStr::from_ptr(key) }.to_str().unwrap().to_owned(); let value = unsafe { CStr::from_ptr(value) } @@ -305,7 +306,8 @@ pub extern "C" fn remove_thread_tag( let pid = std::process::id(); let mut hasher = DefaultHasher::new(); - hasher.write_u64(thread_id % pid as u64); + let thread_id = thread_id(); + hasher.write_u64(thread_id % pid as u64); // todo why is it modules and hashing? let id = hasher.finish(); ffikit::send(ffikit::Signal::RemoveThreadTag(id, key, value)).unwrap(); @@ -356,3 +358,7 @@ fn string_to_tags<'a>(tags: &'a str) -> Vec<(&'a str, &'a str)> { tags_vec } + +pub fn thread_id() -> u64 { + unsafe { libc::pthread_self() as u64 } +} diff --git a/pyroscope_ffi/ruby/ext/thread_id/Cargo.toml b/pyroscope_ffi/ruby/ext/thread_id/Cargo.toml deleted file mode 100644 index 6c231d4f..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "thread_id" -version = "0.1.0" -edition = "2021" -rust-version = "1.64" - -[lib] -name = "thread_id" -crate-type = ["cdylib"] - -[dependencies] -libc = "*" - -[build-dependencies] -cbindgen = "0.28.0" diff --git a/pyroscope_ffi/ruby/ext/thread_id/Rakefile b/pyroscope_ffi/ruby/ext/thread_id/Rakefile deleted file mode 100644 index 0e7754f6..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/Rakefile +++ /dev/null @@ -1,163 +0,0 @@ -# frozen_string_literal: true - -require "shellwords" - -class ThreadIdRakeCargoHelper - attr_reader :gemname - - def initialize(gemname=File.basename(__dir__)) - @gemname = gemname - end - - def self.command?(name) - exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""] - ENV["PATH"].split(File::PATH_SEPARATOR).any? do |path| - exts.any? do |ext| - exe = File.join(path, "#{name}#{ext}") - File.executable?(exe) && !File.directory?(exe) - end - end - end - - def self.rust_toolchain - # return env variable if set - target = ENV["RUST_TARGET"] - return target if target - - str = `rustc --version --verbose` - info = str.lines.map {|l| l.chomp.split(/:\s+/, 2)}.drop(1).to_h - info["host"] - end - - def self.cargo_target_dir - return @cargo_target_dir if defined? @cargo_target_dir - - str = `cargo metadata --format-version 1 --offline --no-deps --quiet` - begin - require "json" - dir = JSON.parse(str)["target_directory"] - rescue LoadError # json is usually part of the stdlib, but just in case - /"target_directory"\s*:\s*"(?