Can't get a minimal Sinatra example working
Closed this issue · 8 comments
As a perftools newbie I'm running into problems trying to get it running with my Sinatra application. I've created a minimal 'hello world' app that illustrates my problem:
https://github.com/petewarden/sinatraperftoolsexample
I did my best to follow the directions in the documentation, but I'm betting there's just a step that I'm missing. In more detail, here's what I'm doing:
-
Installing the perftools gem using this in my Gemfile and running bundle install:
gem "rack-perftools_profiler" -
Including the file in my application:
require 'rack/perftools_profiler' -
Also including a configuration block:
configure :profiling do
use ::Rack::PerftoolsProfiler, :default_printer => 'gif'
end -
Launch the application using rackup and visit http://localhost:9292/?profile=true
From my reading of the documentation, I would expect to see a gif displayed in the result showing profile information, but instead I see exactly the same page that appears without the profile argument.
What am I doing wrong? Any help much appreciated, I'm itching to use the framework.
ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10]
uname -v
Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386
Gemfile.lock
GEM
remote: http://rubygems.org/
specs:
open4 (1.1.0)
perftools.rb (0.5.6)
rack (1.3.2)
rack-perftools_profiler (0.5.0)
open4 (> 1.0)> 0.5.6)
perftools.rb (
rack (> 1.0)> 1.1)
sinatra (1.2.6)
rack (
tilt (< 2.0, >= 1.2.2)
tilt (1.3.2)
Pete,
Sorry for the delayed reply - I've been on the road with spotty access to the internet. To answer your question, I think your problem is that you are not starting rackup in the 'profiling' environment. You can do so like this
rackup -E profiling
or, you can alter the code in your app to be like this:
configure do
use ::Rack::PerftoolsProfiler, :default_printer => 'gif'
end
and just do:
rackup
That said, I can see how this is confusing, so I'll update the readme to be more clear. Let me know if this doesn't solve your problem.
Thanks, that is helpful. I was including the configure do ... end statement
in the example code, but it didn't seem to be working correctly (possibly
because I placed it within the app class?). Adding the arguments to Rackup
does work, but I then run into a problem with pprof.rb not being found when
I pass in profile=true in the URL. I'll investigate further, ideally I'd
like to create a minimal standalone example that other newbies like me can
start with as a template.
Thanks again for your help!
On Mon, Aug 8, 2011 at 8:34 PM, bhb <
reply@reply.github.com>wrote:
Pete,
Sorry for the delayed reply - I've been on the road with spotty access to
the internet. To answer your question, I think your problem is that you are
not starting rackup in the 'profiling' environment. You can do so like thisrackup -E profiling
or, you can alter the code in your app to be like this:
configure do use ::Rack::PerftoolsProfiler, :default_printer => 'gif' endand just do:
rackup
That said, I can see how this is confusing, so I'll update the readme to be
more clear. Let me know if this doesn't solve your problem.Reply to this email directly or view it on GitHub:
"I'll investigate further, ideally I'd like to create a minimal standalone
example that other newbies like me can start with as a template."
Sounds cool to me. I'm still on the road, but as soon as I get a chance,
I'll see if I can fork your sample project and make something simple that
works for me. Please let me know if you get stuck.
Ben
On Tue, Aug 9, 2011 at 1:54 PM, petewarden <
reply@reply.github.com>wrote:
Thanks, that is helpful. I was including the configure do ... end statement
in the example code, but it didn't seem to be working correctly (possibly
because I placed it within the app class?). Adding the arguments to Rackup
does work, but I then run into a problem with pprof.rb not being found when
I pass in profile=true in the URL. I'll investigate further, ideally I'd
like to create a minimal standalone example that other newbies like me can
start with as a template.Thanks again for your help!
On Mon, Aug 8, 2011 at 8:34 PM, bhb <
reply@reply.github.com>wrote:Pete,
Sorry for the delayed reply - I've been on the road with spotty access to
the internet. To answer your question, I think your problem is that you
are
not starting rackup in the 'profiling' environment. You can do so like
thisrackup -E profiling
or, you can alter the code in your app to be like this:
configure do use ::Rack::PerftoolsProfiler, :default_printer => 'gif' endand just do:
rackup
That said, I can see how this is confusing, so I'll update the readme to
be
more clear. Let me know if this doesn't solve your problem.Reply to this email directly or view it on GitHub:
Reply to this email directly or view it on GitHub:
Ben Brinckerhoff
bbrinck.com
twitter.com/bbrinck
Pete,
I think I see the problem. If you use rack-perftools_profiler, you don't need to call PerfTools::CpuProfiler directly - that's what the middleware does for you. Check out my fork (https://github.com/bhb/sinatraperftoolsexample) for a simple example that will provide profiling data if you visit http://localhost:9292/?profile=true
I hope that helps. Let me know if you have any other questions.
Ben
That direct call was actually just some debugging code I mistakenly checked
in. I wanted to make sure that perftools was present and working on my
system, but didn't intend for it to be in the example. I've reverted the
code back to the original version, sorry about that.
What I'm basically trying to figure out with the sample code is how to make
a call to eg http://localhost:9292/?profile=true trigger a profile.
cheers,
Pete
On Fri, Aug 12, 2011 at 3:38 AM, bhb <
reply@reply.github.com>wrote:
Pete,
I think I see the problem. If you use rack-perftools_profiler, you don't
need to call PerfTools::CpuProfiler directly - that's what the middleware
does for you. Check out my fork (
https://github.com/bhb/sinatraperftoolsexample) for a simple example that
will provide profiling data if you visit
http://localhost:9292/?profile=trueI hope that helps. Let me know if you have any other questions.
Ben
Reply to this email directly or view it on GitHub:
Strange. The code on my fork works for me. What do you see when you visit http://localhost:9292/?profile=true ?
If you see a message like "No nodes to print" or "Running the command 'pprof.rb --text /tmp/rack_perftools_profiler.prof' failed to generate a file"
it simply means that the code was so fast that it couldn't be profiled - basically, the profiler never even had a chance to take a sample. This usually only happens if the page is very simple (and therefore would not be interesting to profile anyway). To get around this, I recommend inserting some code like 5_000_000.times{ 1+2+3+4+5 }
to artificially slow down the route so you can see some profiling data.
Thanks Ben. I don't see any message in the logs, and the delivered page is
identical to the one served up without the profile argument.
It is helpful to know the application works for you though, since it
suggests the problem is with my machine's configuration, not the code. I'm
running it on my OS X laptop, so the next thing I'll try is a clean Ubuntu
EC2 box.
On Fri, Aug 12, 2011 at 2:25 PM, bhb <
reply@reply.github.com>wrote:
Strange. The code on my fork works for me. What do you see when you visit
http://localhost:9292/?profile=true ?If you see a message like "No nodes to print" or "Running the command
'pprof.rb --text /tmp/rack_perftools_profiler.prof' failed to generate a
file"it simply means that the code was so fast that it couldn't be profiled -
basically, the profiler never even had a chance to take a sample. This
usually only happens if the page is very simple (and therefore would not be
interesting to profile anyway). To get around this, I recommend inserting
some code like5_000_000.times{ 1+2+3+4+5 }
to artificially slow down the
route so you can see some profiling data.Reply to this email directly or view it on GitHub:
How strange. I'm running on OS X (10.6.8), so I'm not sure what the problem
is.
I checked out your branch on my machine and ran 'rackup -E profiling', and
hit http://localhost:9292/?profile=true and I get the error message "No
nodes to print".
Have you tried the basic example for perftools.rb on your machine? The
directions are in the README at https://github.com/tmm1/perftools.rb. Maybe
there is some error that my middleware is missing.
Can you also try this sequence?
http://localhost:9292/**start** (and see what message appears)
http://localhost:9292/
http://localhost:9292/**stop** (and see what message appears)
http://localhost:9292/**data** (and see what happens)
On Mon, Aug 15, 2011 at 2:38 PM, petewarden <
reply@reply.github.com>wrote:
Thanks Ben. I don't see any message in the logs, and the delivered page is
identical to the one served up without the profile argument.It is helpful to know the application works for you though, since it
suggests the problem is with my machine's configuration, not the code. I'm
running it on my OS X laptop, so the next thing I'll try is a clean Ubuntu
EC2 box.On Fri, Aug 12, 2011 at 2:25 PM, bhb <
reply@reply.github.com>wrote:Strange. The code on my fork works for me. What do you see when you visit
http://localhost:9292/?profile=true ?If you see a message like "No nodes to print" or "Running the command
'pprof.rb --text /tmp/rack_perftools_profiler.prof' failed to generate a
file"it simply means that the code was so fast that it couldn't be profiled -
basically, the profiler never even had a chance to take a sample. This
usually only happens if the page is very simple (and therefore would not
be
interesting to profile anyway). To get around this, I recommend inserting
some code like5_000_000.times{ 1+2+3+4+5 }
to artificially slow down
the
route so you can see some profiling data.Reply to this email directly or view it on GitHub:
Reply to this email directly or view it on GitHub:
Ben Brinckerhoff
bbrinck.com
twitter.com/bbrinck