New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it easier to avoid profiling startup code #329
Comments
So the old/deprecated API more or less worked like that. RubyProf.start But I wanted to move away from the shared global object instance. |
Can there ever be more than one Profiles running at the same time in the same thread? Tbh, I already fixed the problem using This does not have a high priority, of course. |
Right, only one profile per thread. Probably only one profile period, never tested with having different threads with different profiles. I don't think I'm really understanding your issue though. Since you have to write code to call profile.resume anyway, then why not just create and start the profile at that point (ie, after warmup)? Or are you profiling using the ruby-prof script and want it to start paused? Edit - Just reread your original description:
That works for me - happy to take a MR. |
It's not a big issue, tbh. I'd have liked getting all the CLI options for free, instead of hardcoding a single mode and profiler. MR = merge request? I'll have to take a look at the source of this gem first. Not familiar with it yet. I'd have to:
My C isn't amazing... |
I don't think there is any c code involved. You'd update the ruby-prof script to take a So the then question is how to get that profile instance from some random place in your code base. One possible way is store it in a thread local variable (of course if your code has multiple threads, any child thread won't be able to get at it. Another way I suppose is store it in a global constant: class CMD You'll get warnings from Ruby setting a constant. Or you could store the profile at the class level: def self.profile=(value) Etc...you get the idea. |
Hi @paddor - just wondering how you want to proceed? Sorry this got bogged down a bit. |
Sorry, couldn't find the time anymore. To me this is now low priority as I've solved it in the meantime. Should I close these for now? |
No worries. I'll keep this open for now. Thanks for using ruby-prof! |
Suggestion:
It would be nice if the currently running
RubyProf::Profile
instance was available somehow, maybe throughRubyProf::Profile.current
, so it can be paused during startup of an application and resumed when the application is started (warmed up). That way, an app could doRubyProf::Profile.current.pause if defined?(RubyProf)
before warmup andRubyProf::Profile.current.resume if defined?(RubyProf)
after warmup.Alternative suggestion:
Alternatively, a new option
--start-paused
could be introduced, which then can be resumed by the application after warmup usingRubyProf::Profile.current.resume if defined?(RubyProf)
.Reason:
Personally, I think that would be way more elegant than using
-R, --require-noprof=lib
or-E, --eval-noprof=code
, which make it clumsy to preload something and use it later. You'd have to store the preloaded object in some global.I noticed that the constant
RubyProf
is defined when running a script withruby-prof my_script.rb
. So there should be a way. Unfortunately@profile
is not set inRubyProf
if the CLI is used.Advantage:
The advantage would be that the application does not need to manually/intrusively create a
RubyProf::Profile
after warmup. It could be done on the command line withruby-prof
and all profiling and output/formatting options would be available for free.The text was updated successfully, but these errors were encountered: