JSON format profile printer (additions) #326
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is some additions to pull request #270, as per the discussion there.
I've added a layer of indirection between
Ruby#printProfileData
and the profile printers to make it possible to write a profile to a file. I also addedProfilePrinter#printHeader
and#printFooter
to make it possible to write all thread profiles into the same file when the format is HTML or JSON, without the output being all weird. I've also updated all profile printers to support this.All changes should be backwards compatible, and I've marked the old version of
Ruby#printProfileData
that took aPrintStream
as deprecated.I've added an optional argument to
--profile.xxx
that is the file to write to. Please check that part extra carefully so that I haven't done anything stupid. There wasn't any other argument that took optional parameters on the form--xyz optarg
, only arguments like-Ioptarg
or that always expected a value. The way I did it was by checking if there is one more argument, and making sure that argument doesn't start with a dash. It will fail in this case:ruby --profile.json hello_world.rb
, becausehello_world.rb
will be interpreted as the argument to--profile.json
, not the script to run. I don't know if this is acceptable. Maybe it would be better to do it like--profile.json=output.json
, but that's not how the other arguments that take values work (e.g.--compat RUBY_18
).I'm not entirely satisfied with the way profiles are printed, and I'd like to do some more changes to structure it differently, but I think that another pull request that can aim for a later release.