jruby/jruby — pull request #326 by iconara (2012-10-01 12:04:58+00:00)
Title: JSON format profile printer (additions)

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 added `ProfilePrinter#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 a `PrintStream` 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`, because `hello_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.