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
Add pumactl command to print thread backtraces #2054
Add pumactl command to print thread backtraces #2054
Conversation
a52fd51
to
7eb7ad8
Compare
lib/puma/app/status.rb
Outdated
when /\/thread-backtraces$/ | ||
strings = Puma::Events.strings | ||
@cli.log_thread_status(strings) | ||
rack_response(200, strings.stdout.string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be JSON instead of the raw string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. All current responses are json, so we're going to need to turn this into json object.
Maybe something like:
threads: [
{ name: "", backtrace: "" },
{ name: "", backtrace: "" }
]
lib/puma/app/status.rb
Outdated
when /\/thread-backtraces$/ | ||
strings = Puma::Events.strings | ||
@cli.log_thread_status(strings) | ||
rack_response(200, strings.stdout.string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. All current responses are json, so we're going to need to turn this into json object.
Maybe something like:
threads: [
{ name: "", backtrace: "" },
{ name: "", backtrace: "" }
]
@@ -11,7 +11,8 @@ | |||
module Puma | |||
class ControlCLI | |||
|
|||
COMMANDS = %w{halt restart phased-restart start stats status stop reload-worker-directory gc gc-stats} | |||
COMMANDS = %w{halt restart phased-restart start stats status stop reload-worker-directory gc gc-stats thread-backtraces} | |||
PRINTABLE_COMMANDS = %w{gc-stats stats thread-backtraces} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
lib/puma/launcher.rb
Outdated
@@ -205,6 +205,21 @@ def close_binder_listeners | |||
@binder.close_listeners | |||
end | |||
|
|||
def log_thread_status(events) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you'll need to refactor this out a bit so that you have two methods - one that prepares a Ruby object representation of threads and backtraces, then one method that logs that info to events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nateberkopec Should we always use the object representation, or do you want to preserve the existing format for the SIGINFO and use the object representation only for the status app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what matters is that the current logged output remains the same, the status app outputs JSON, and that they both use the same method underneath for obtaining that info.
Completes 1 of 2 items from puma#1964 This commit adds an endpoint to the status app to print thread backtraces, and control cli command to call that endpoint. I tried this locally by starting a server with: ```sh bundle exec bin/puma test/rackup/hello.ru \ --control-url="unix://test.sock" \ --control-token="token" ``` and then printing the backtraces with: ```sh bundle exec bin/pumactl thread-backtraces \ --control-url="unix://test.sock" \ --control-token="token" ```
7eb7ad8
to
e87d82d
Compare
With this commit the status app sends the thread backtraces as an array of objects with `name` and `backtrace` keys, rather than as a string matching the SIGINFO output. While working on this I noticed that we logged the thread TID twice. This commit simplifies that so we only log the thread TID once, with both the label (I don't know when the label would get set) and name if they are available.
e87d82d
to
a344d75
Compare
Ready for another review |
Nice work! |
Woah, that was fast! Thanks! |
From the sidelines: this is super helpful! The tab that was added to each backtrace line makes for an ergonomic developer experience. |
Is there a timeline for releasing this? |
This was merged 3 days after 4.3 was released, so I realize it's been in the backlog for a while. You can see progress on 5.0 here: https://github.com/puma/puma/milestone/7 |
Completes 1 of 2 items from #1964
This commit adds an endpoint to the status app to print thread
backtraces, and control cli command to call that endpoint.
I tried this locally by starting a server with:
and then printing the backtraces with:
[changelog skip]
to all commit messages.[ci skip]
to the commit messages.#issue
" to the PR description or my commit messages.