Skip to content
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 ability to profile commands via CLI #116

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

fatkodima
Copy link
Contributor

Closes #113.
Closes #114.

Currently, the CLI allows to profile only ruby files. But when you want to profile a whole ruby command for its entire lifetime, it's a bit complicated to find the proper entry point and exit point to insert MemoryProfiler.start etc.

This PR extends the CLI to allow to do this easily, e.g:

$ ruby-memory-profiler run -- rubocop --cache false

Or for profiling a Rails application boot sequence:

$ ruby-memory-profiler run -- bin/rails runner ':ok'

Or a user's rake task:

$ ruby-memory-profiler run -- bin/rake users:notify

```
$ ruby-memory-profiler [options] <script.rb> [--] [script-options]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLI allows to profile single files or whole command. Since single files can be profiled as commands via simply ... ruby script.rb ..., I removed that ability from the readme to make it less confusing and for people to use the unified style.

Comment on lines -17 to -24
REPORTER_KEYS = [
:top, :trace, :ignore_files, :allow_files
].freeze

RESULTS_KEYS = [
:to_file, :color_output, :retained_strings, :allocated_strings,
:detailed_report, :scale_bytes, :normalize_paths
].freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This separation is really not needed and only complicates the code.

@fatkodima
Copy link
Contributor Author

CI is red not because of this PR changes - needs to be fixed separately.

@fatkodima fatkodima mentioned this pull request Jun 17, 2024
@SamSaffron
Copy link
Owner

I like this change a lot, merging

@SamSaffron SamSaffron merged commit c708521 into SamSaffron:master Jun 17, 2024
0 of 5 checks passed
@fatkodima fatkodima deleted the cli-profile-commands branch June 17, 2024 09:09
@Earlopain
Copy link
Contributor

Earlopain commented Jun 17, 2024

The base64 gem needs to be added to the gemspec. It will not be a default gem anymore in Ruby 3.4, for RuboCops head CI this causes a failure like this: rubocop/rubocop#13002

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What is the proper way to use memory_profiler with a rake task? Feature request: ability to profile commands
3 participants