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*"(?[^"]*)"/ =~ str - end - @cargo_target_dir = dir || "target" - end - - def self.flags - cc_flags = Shellwords.split(RbConfig.expand(RbConfig::MAKEFILE_CONFIG["CC"].dup)) - - ["-C", "linker=#{cc_flags.shift}", - *cc_flags.flat_map {|a| ["-C", "link-arg=#{a}"] }, - "-L", "native=#{RbConfig::CONFIG["libdir"]}", - *dld_flags, - *platform_flags] - end - - def self.dld_flags - Shellwords.split(RbConfig::CONFIG["DLDFLAGS"]).flat_map do |arg| - arg = arg.gsub(/\$\((\w+)\)/) do - $1 == "DEFFILE" ? nil : RbConfig::CONFIG[name] - end.strip - next [] if arg.empty? - - transform_flag(arg) - end - end - - def self.platform_flags - return unless RbConfig::CONFIG["target_os"] =~ /mingw/i - - [*Shellwords.split(RbConfig::CONFIG["LIBRUBYARG"]).flat_map {|arg| transform_flag(arg)}, - "-C", "link-arg=-Wl,--dynamicbase", - "-C", "link-arg=-Wl,--disable-auto-image-base", - "-C", "link-arg=-static-libgcc"] - end - - def self.transform_flag(arg) - k, v = arg.split(/(?<=..)/, 2) - case k - when "-L" - [k, "native=#{v}"] - when "-l" - [k, v] - when "-F" - ["-l", "framework=#{v}"] - else - ["-C", "link_arg=#{k}#{v}"] - end - end - - def install_dir - File.expand_path(File.join("..", "..", "lib", gemname), __dir__) - end - - def rust_name - prefix = "lib" unless Gem.win_platform? - suffix = if RbConfig::CONFIG["target_os"] =~ /darwin/i - ".dylib" - elsif Gem.win_platform? - ".dll" - else - ".so" - end - "#{prefix}#{gemname}#{suffix}" - end - - def ruby_name - "#{gemname}.#{RbConfig::CONFIG["DLEXT"]}" - end - -end - -task default: [:thread_id_install, :thread_id_clean] -task thread_id: [:thread_id_install, :thread_id_clean] - -desc "set dev mode for subsequent task, run like `rake dev install`" -task :thread_id_dev do - @dev = true -end - -desc "build gem native extension and copy to lib" -task thread_id_install: [:thread_id_cd, :thread_id_build] do - helper = ThreadIdRakeCargoHelper.new - profile_dir = @dev ? "debug" : "release" - arch_dir = RbspyRakeCargoHelper.rust_toolchain - source = File.join(ThreadIdRakeCargoHelper.cargo_target_dir, arch_dir, profile_dir, helper.rust_name) - dest = File.join(helper.install_dir, helper.ruby_name) - mkdir_p(helper.install_dir) - rm(dest) if File.exist?(dest) - cp(source, dest) -end - -desc "build gem native extension" -task thread_id_build: [:thread_id_cargo, :thread_id_cd] do - sh "cargo", "rustc", *(["--locked", "--release"] unless @dev), "--target=#{RbspyRakeCargoHelper.rust_toolchain}", "--", *RbspyRakeCargoHelper.flags -end - -desc "clean up release build artifacts" -task thread_id_clean: [:thread_id_cargo, :thread_id_cd] do - sh "cargo clean --release" -end - -desc "clean up build artifacts" -task thread_id_clobber: [:thread_id_cargo, :thread_id_cd] do - sh "cargo clean" -end - -desc "check for cargo" -task :thread_id_cargo do - raise <<-MSG unless ThreadIdRakeCargoHelper.command?("cargo") - This gem requires a Rust compiler and the `cargo' build tool to build the - gem's native extension. See https://www.rust-lang.org/tools/install for - how to install Rust. `cargo' is usually part of the Rust installation. - MSG - - raise <<-MSG if Gem.win_platform? && ThreadIdRakeCargoHelper.rust_toolchain !~ /gnu/ - Found Rust toolchain `#{ThreadIdRakeCargoHelper.rust_toolchain}' but the gem native - extension requires the gnu toolchain on Windows. - MSG -end - -# ensure task is running in the right dir -task :thread_id_cd do - cd(__dir__) unless __dir__ == pwd -end diff --git a/pyroscope_ffi/ruby/ext/thread_id/build.rs b/pyroscope_ffi/ruby/ext/thread_id/build.rs deleted file mode 100644 index 273d1392..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/build.rs +++ /dev/null @@ -1,12 +0,0 @@ -extern crate cbindgen; - -use cbindgen::Config; - -fn main() { - let bindings = { - let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let config = Config::from_file("cbindgen.toml").unwrap(); - cbindgen::generate_with_config(&crate_dir, config).unwrap() - }; - bindings.write_to_file("include/thread_id.h"); -} diff --git a/pyroscope_ffi/ruby/ext/thread_id/cbindgen.toml b/pyroscope_ffi/ruby/ext/thread_id/cbindgen.toml deleted file mode 100644 index 32a3caed..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/cbindgen.toml +++ /dev/null @@ -1,22 +0,0 @@ -# The language to output bindings in -language = "C" -documentation_style = "C" - -style = "type" - -# An optional name to use as an include guard -include_guard = "RBSPY_H_" -# include a comment with the version of cbindgen used to generate the file -include_version = true - -# An optional string of text to output at the beginning of the generated file -header = "/* Licensed under Apache-2.0 */" -autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" - -braces = "SameLine" -tab_width = 2 -line_length = 80 - -[parse] -# Do not parse dependent crates -parse_deps = false diff --git a/pyroscope_ffi/ruby/ext/thread_id/extconf.rb b/pyroscope_ffi/ruby/ext/thread_id/extconf.rb deleted file mode 100644 index 2b650fa2..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/extconf.rb +++ /dev/null @@ -1,11 +0,0 @@ -require 'mkmf' -require 'rake' - -create_makefile('thread_id') - -app = Rake.application -app.init -app.add_import 'Rakefile' -app.load_rakefile - -app['default'].invoke diff --git a/pyroscope_ffi/ruby/ext/thread_id/include/thread_id.h b/pyroscope_ffi/ruby/ext/thread_id/include/thread_id.h deleted file mode 100644 index 604e5374..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/include/thread_id.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Licensed under Apache-2.0 */ - -#ifndef RBSPY_H_ -#define RBSPY_H_ - -/* Generated with cbindgen:0.28.0 */ - -/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ - -#include -#include -#include -#include - -uint64_t thread_id(void); - -#endif /* RBSPY_H_ */ diff --git a/pyroscope_ffi/ruby/ext/thread_id/src/lib.rs b/pyroscope_ffi/ruby/ext/thread_id/src/lib.rs deleted file mode 100644 index 4f448e94..00000000 --- a/pyroscope_ffi/ruby/ext/thread_id/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn thread_id() -> u64 { - unsafe { libc::pthread_self() as u64 } -} diff --git a/pyroscope_ffi/ruby/lib/pyroscope.rb b/pyroscope_ffi/ruby/lib/pyroscope.rb index 01c59aa9..67cfbce2 100644 --- a/pyroscope_ffi/ruby/lib/pyroscope.rb +++ b/pyroscope_ffi/ruby/lib/pyroscope.rb @@ -10,19 +10,13 @@ module Rust ffi_lib File.expand_path(File.dirname(__FILE__)) + "/rbspy/rbspy.#{RbConfig::CONFIG["DLEXT"]}" attach_function :initialize_logging, [:int], :bool attach_function :initialize_agent, [:string, :string, :string, :string, :string, :int, :bool, :bool, :bool, :bool, :string, :string, :string, :string, :string], :bool - attach_function :add_thread_tag, [:uint64, :string, :string], :bool - attach_function :remove_thread_tag, [:uint64, :string, :string], :bool + attach_function :add_thread_tag, [:string, :string], :bool + attach_function :remove_thread_tag, [:string, :string], :bool attach_function :add_global_tag, [:string, :string], :bool attach_function :remove_global_tag, [:string, :string], :bool attach_function :drop_agent, [], :bool end - module Utils - extend FFI::Library - ffi_lib File.expand_path(File.dirname(__FILE__)) + "/thread_id/thread_id.#{RbConfig::CONFIG["DLEXT"]}" - attach_function :thread_id, [], :uint64 - end - if defined?(::Rails::Engine) class Engine < ::Rails::Engine config.after_initialize do @@ -137,12 +131,11 @@ def initialize_rails_hooks end def tag_wrapper(tags) - tid = thread_id - _add_tags(tid, tags) + _add_tags(tags) begin yield ensure - _remove_tags(tid, tags) + _remove_tags(tags) end end @@ -154,19 +147,15 @@ def remove_tags(*tags) warn("deprecated. Use `Pyroscope.tag_wrapper` instead.") end - def thread_id - return Utils.thread_id - end - - def _add_tags(thread_id, tags) + def _add_tags(tags) tags.each do |tag_name, tag_value| - Rust.add_thread_tag(thread_id, tag_name.to_s, tag_value.to_s) + Rust.add_thread_tag(tag_name.to_s, tag_value.to_s) end end - def _remove_tags(thread_id, tags) + def _remove_tags(tags) tags.each do |tag_name, tag_value| - Rust.remove_thread_tag(thread_id, tag_name.to_s, tag_value.to_s) + Rust.remove_thread_tag(tag_name.to_s, tag_value.to_s) end end diff --git a/pyroscope_ffi/ruby/pyroscope.gemspec b/pyroscope_ffi/ruby/pyroscope.gemspec index 603dd1e3..62abfc85 100644 --- a/pyroscope_ffi/ruby/pyroscope.gemspec +++ b/pyroscope_ffi/ruby/pyroscope.gemspec @@ -46,13 +46,6 @@ Gem::Specification.new do |s| "ext/rbspy/extconf.rb", "ext/rbspy/include/rbspy.h", "ext/rbspy/src/lib.rs", - "ext/thread_id/Cargo.toml", - "ext/thread_id/Rakefile", - "ext/thread_id/build.rs", - "ext/thread_id/cbindgen.toml", - "ext/thread_id/extconf.rb", - "ext/thread_id/include/thread_id.h", - "ext/thread_id/src/lib.rs", "lib/pyroscope.rb", "lib/pyroscope/version.rb", "pyroscope.gemspec", @@ -62,7 +55,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 1.9.3" - s.extensions = ['ext/rbspy/extconf.rb', 'ext/thread_id/extconf.rb'] + s.extensions = ['ext/rbspy/extconf.rb'] s.add_dependency 'ffi'