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

Using a Ruby Pathname as the output file results in error #79

Closed
originalpete opened this issue Mar 14, 2017 · 1 comment
Closed

Using a Ruby Pathname as the output file results in error #79

originalpete opened this issue Mar 14, 2017 · 1 comment

Comments

@originalpete
Copy link

In Ruby its common to use the helpful Pathname class to represent a path to a file. However, if you use this with stackprof you get an exception with no helpful stacktrace (because the IO flush happens in the compiled library).

2.4.0 :063 >  StackProf.run(mode: :cpu, out: Rails.root.join("tmp/stackprof-cpu.dump")) do
2.4.0 :064 >     10.times {2**10}
2.4.0 :065?>   end
NoMethodError: undefined method `flush' for nil:NilClass
	from (irb):63:in `run'

[rest of stacktrace removed because it's not helpful, and only shows the Ruby call stack down to the console]

However, if you call .to_son the end of the pathname object then it works:

StackProf.run(mode: :cpu, out: Rails.root.join("tmp/stackprof-cpu.dump").to_s) do
2.4.0 :055 >     10.times {2**10}
2.4.0 :056?>   end
 => #<File:/[...]/tmp/stackprof-cpu.dump>

Presumably this is due to the fact that (upon reading the code) it seems that the out parameter can take eithert an IO object or a file path. In which case, this should be documented, and / or checked internally and converted to a string if necessary.

This caused much head-scratching and gnashing of teeth!

@tmm1
Copy link
Owner

tmm1 commented Nov 17, 2017

Can you open a PR which adds a to_s in the right spot, and maybe a test.

NickLaMuro added a commit to NickLaMuro/stackprof that referenced this issue Oct 2, 2018
The code for `stackprof_results` currently only does checks to see if
the VALUE for `_stackprof.out` is a T_STRING, otherwise it assumes it is
an IO object.

This updates the code to first check if Pathname has been required and
defined, and if it is and the _stackprof.out is a Pathname, then open a
file in the same manner as if it was a string, but calls `.to_s` to
convert it to a ruby string first.

Fixes tmm1#79
NickLaMuro added a commit to NickLaMuro/stackprof that referenced this issue Oct 2, 2018
The code for `stackprof_results` currently only does checks to see if
the VALUE for `_stackprof.out` is a `T_STRING`, otherwise it assumes it
is an IO object.

This updates the code to first check if `Pathname` has been required and
defined.  If it is and the `_stackprof.out` is a `Pathname`, then open a
file in the same manner as if it was a string, but calls `.to_s` to
convert it to a ruby string first.

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

No branches or pull requests

3 participants