profiler.rb is not concurrent-execution threadsafe
The library profiler.rb uses class variables to store data without wrapping them in mutexes. On current C Ruby, this may only rarely cause a problem, but as more and more code is allowed to run in parallel it's going to lead to issues. If I or other JRuby community members have a chance, we'll try to make it thread-safe, but I wanted to file this issue to ensure it's out there.
The library is also largely unchanged in 1.9.1.
See http://jira.codehaus.org/browse/JRUBY-2133 for the (admittedly sparse) JRuby issue.
Updated by jabley (James Abley) about 11 years ago
Sample patch attached for discussion. There are style and best
practice issues with this patch due to my lack of ruby experience.
Please forgive and be so kind as to suggest improvements.
It is intended to highlight some of the areas that must be considered
when making the change to provide thread-safe profiling.
The patch alters the code to make the capture of the data thread-safe
AFAICT. There may be some issues with the data fields / calculations.
I wasn't completely clear what each field in the array was supposed to
be storing. The main issue unresolved by this patch is how best to
present the information.
I've opted for showing information per-thread and a summary as well.
- Should there be a version number outputted, in case downstream tools are doing something with this information?
- Any comments on how the information is being presented??
- Should profiling be configurable, so that it may not show output per thread, etc.
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r38576.
Charles, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
- lib/profiler.rb (Profiler__::PROFILE_PROC, print_profile): store profile data per threads for concurrent-execution. [ruby-core:22046] [Bug #1152]