Re: Rails (rails 3 and ruby 1.9.3) and ruby-prof

187 views
Skip to first unread message

rogerdpack

unread,
Jul 10, 2012, 12:06:05 PM7/10/12
to ruby-opt...@googlegroups.com
I think you're seeing the same thing as this other fella did:
https://groups.google.com/forum/?hl=en_US&fromgroups#!topic/ruby-optimization/TyeOmxSei4o

Do you have a way to send it to us to reproduce it?
-r


On Tuesday, July 10, 2012 9:30:54 AM UTC-6, lifey wrote:
Hi,
I am trying to use ruby-prof in a little bit different way than I c in the documentation and I fail. 

So I added the following lines into the routes.rb file (two actions which will stop and start the profiler ):

 match 'rubyprof/start' => 'rubyprof#start'
 match 'rubyprof/stop' => 'rubyprof#stop'

And I added the new controller:

require 'ruby-prof'

class RubyprofController < ApplicationController
  def start
    RubyProf.start
    is = StringIO.new
    is << 'Profiler started'
    render :inline => is.string
  end

  def stop
    result = RubyProf.stop

    is = StringIO.new
    if (params.has_key?(:callstack))
      printer = RubyProf::CallStackPrinter.new(result)
      printer.print(is, :min_percent=>0)
    end
    if (params.has_key?(:graphhtml))
      printer = RubyProf::GraphHtmlPrinter.new(result)
      printer.print(is, :min_percent=>0)
    end
    if (params.has_key?(:flat))
      printer = RubyProf::FlatPrinter.new(result)
      printer.print(is, :min_percent=>0)
    end

    if (params.has_key?(:file))
      printer = RubyProf::FlatPrinter.new(result)
      fs = File.open(params[:file], 'w')
      fs.puts is.string
    end
    render :inline => is.string
  end
end
It works fine when I do nothing between the start and the stop 
If actual work is done (accessing the application from the web ) I get :


NoMethodError in RubyprofController#stop

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.collect

Rails.root: /var/www/projects/XXXXXXXX/current

Application Trace | Framework Trace | Full Trace
app/models/tableless.rb:27:in `inspect'
ruby-prof (0.11.2) lib/ruby-prof/printers/graph_html_printer.rb:64:in `full_name'
ruby-prof (0.11.2) lib/ruby-prof/printers/graph_html_printer.rb:64:in `method_href'
ruby-prof (0.11.2) lib/ruby-prof/printers/graph_html_printer.rb:58:in `create_link'
(erb):148:in `block (3 levels) in print'
(erb):137:in `each'
(erb):137:in `block (2 levels) in print'
(erb):96:in `reverse_each'
(erb):96:in `block in print'
(erb):74:in `each'
(erb):74:in `print'
/usr/lib/ruby/1.9.1/erb.rb:838:in `eval'
/usr/lib/ruby/1.9.1/erb.rb:838:in `result'
ruby-prof (0.11.2) lib/ruby-prof/printers/graph_html_printer.rb:44:in `print'
app/controllers/rubyprof_controller.rb:21:in `stop'
What am I doing wrong ? 
Should ruby prof be started end stopped from the same flow ?
Can this be a result of other threads interaction ?

Thanks in advance for any help .

Reply all
Reply to author
Forward
0 new messages