osyoyu/pf2

Does not work on mac.

Closed this issue ยท 3 comments

When I tried to run pf2 gem version 0.5.1 on mac, I got the following error and it did not work.

Note that pf2 gem version 0.3.0 worked.

Tried source code

  • test2.rb
require 'pf2'

# Threads in `threads` will be tracked
Pf2.start(time_mode: :wall, threads: [Thread.current])

puts "Hello"

# Stop profiling and save the profile for visualization
profile = Pf2.stop
File.write("my_program.pf2profile", profile)

Result

$ ruby test2.rb 
thread '<unnamed>' panicked at ext/pf2/src/signal_scheduler_unsupported_platform.rs:37:9:
not implemented
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

I thought YJIT might have affected it because of the RUST_BACKTRACE statement, but the same was true for ruby 3.3.1 with YJIT disabled build.

Environment

$ ruby -v
ruby 3.3.3 (2024-06-12 revision f1c7b6f435) [arm64-darwin22]
$ rustc -V
rustc 1.79.0 (129f3b996 2024-06-10)
$ gem list pf2

*** LOCAL GEMS ***

pf2 (0.5.1)
$ ruby -e 'puts RubyVM::YJIT.enable'
true

Detail

$ RUST_BACKTRACE=1 ruby test2.rb 
thread '<unnamed>' panicked at ext/pf2/src/signal_scheduler_unsupported_platform.rs:37:9:
not implemented
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: pf2::signal_scheduler_unsupported_platform::SignalScheduler::new
   4: pf2::session::Session::new_from_rb_initialize
   5: pf2::session::ruby_object::SessionRubyObject::rb_initialize
   6: _vm_call0_body
   7: _rb_call0
   8: _rb_class_new_instance_pass_kw
   9: _vm_call_cfunc_with_frame_
  10: _vm_exec_core
  11: _rb_vm_exec
  12: _rb_ec_exec_node
  13: _ruby_run_node
  14: _main
$ RUST_BACKTRACE=full ruby test2.rb 
thread '<unnamed>' panicked at ext/pf2/src/signal_scheduler_unsupported_platform.rs:37:9:
not implemented
stack backtrace:
   0:        0x1012727f4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1f3776e0b5c7517d
   1:        0x101287e4c - core::fmt::write::heedef092c8c0962e
   2:        0x101270cbc - std::io::Write::write_fmt::h7178e8e2ea928914
   3:        0x10127264c - std::sys_common::backtrace::print::h417292deb95532ed
   4:        0x101273718 - std::panicking::default_hook::{{closure}}::h0cb68f1228c4613a
   5:        0x10127340c - std::panicking::default_hook::h24535936bc1f51de
   6:        0x101273fd0 - std::panicking::rust_panic_with_hook::h5db4d2345b297bed
   7:        0x1012739d4 - std::panicking::begin_panic_handler::{{closure}}::h3fd558f09a0d5492
   8:        0x101272c7c - std::sys_common::backtrace::__rust_end_short_backtrace::hfc76eebe1ce501b2
   9:        0x101273770 - _rust_begin_unwind
  10:        0x101290734 - core::panicking::panic_fmt::hc2b459a5bd3dce66
  11:        0x1012907b4 - core::panicking::panic::h65d5df1c072e7907
  12:        0x10124f33c - pf2::signal_scheduler_unsupported_platform::SignalScheduler::new::h20bc82372ef12abd
  13:        0x101252b74 - pf2::session::Session::new_from_rb_initialize::hf34c2464d7e1f752
  14:        0x10124f020 - pf2::session::ruby_object::SessionRubyObject::rb_initialize::h3eb8fcb92f97a51d
  15:        0x10165c7b4 - _vm_call0_body
  16:        0x10165d9e8 - _rb_call0
  17:        0x101538ef8 - _rb_class_new_instance_pass_kw
  18:        0x101657328 - _vm_call_cfunc_with_frame_
  19:        0x10163cb08 - _vm_exec_core
  20:        0x101639d88 - _rb_vm_exec
  21:        0x1014b1a80 - _rb_ec_exec_node
  22:        0x1014b1978 - _ruby_run_node
  23:        0x100dc7f24 - _main
fatal runtime error: failed to initiate panic, error 5
Abort trap: 6

Thank you for your report! Pf2 has two schedulers (TimerThreadScheduler and SignalScheduler; please refer to README for more details), and only the former can be used on macOS. Some work (#19) needs to be done to run SignalScheduler on non-Linux environments.
However, I see that SignalScheduler is chosen in your environment, and this is a bug on Pf2. Let me fix this in the next release.

This should be fixed in #21 , which was released in 0.5.2. Once again, thank you for raising this issue!

One additional note: your test2.rb might not produce any interesting profile, since it is short-lived to the point that Pf2 won't have a chance to capture a sample. 1000.times { puts "Hello" } worked on my MacBook Air.

pf2 0.5.2 worked on my mac. ๐ŸŽ‰
Thanks!