rubinius/rubinius — Issue #1450: Profiler calling #[] on nil when profiling rails app startup
Author: betelgeuse
Created: 2011-12-14 15:49:55+00:00
State: open

Commit in use 7770f9db35a1999471c87ad00c7cf773b91af075

Wrapping script/rails like:

```ruby
require 'profile'
profiler = Rubinius::Profiler::Instrumenter.new
profiler.profile do
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
end
```

I get an error:

```
$ time script/rails r 'puts "foo"'
foo
An exception occurred running script/rails
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.[] (NoMethodError)

User defined backtrace:
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:149:in `thread_flat'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:149:in `thread_flat'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:148:in `thread_flat'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:133:in `flat'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:132:in `flat'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:0:in `show'
/home/betelgeuse/.rvm/rubies/rbx-head/lib/tooling/profiler/profiler.rb:91:in `profile'
script/rails:17:in `__script__'

Backtrace:
NilClass#raise_nil_warning_for at /home/betelgeuse/.rvm/gems/rbx-head
/gems/activesupport-3.1.3/lib
/active_support/whiny_nil.rb:58
NilClass#[] (method_missing) at /home/betelgeuse/.rvm/gems/rbx-head
/gems/activesupport-3.1.3/lib
/active_support/whiny_nil.rb:46
{ } in Rubinius::Profiler::Instrumenter#thread_flat at /home/betelgeuse/.rvm
/rubies/rbx-head/lib
/tooling/profiler
/profiler.rb:149
{ } in Enumerable(Array)#inject at kernel/common/enumerable.rb:216
Array#each at kernel/bootstrap/array.rb:66
Enumerable(Array)#inject at kernel/common/enumerable.rb:212
{ } in Rubinius::Profiler::Instrumenter#thread_flat at /home/betelgeuse/.rvm
/rubies/rbx-head/lib
/tooling/profiler
/profiler.rb:149
Rubinius::LookupTable#each at kernel/bootstrap/lookuptable.rb:111
Rubinius::Profiler::Instrumenter#thread_flat at /home/betelgeuse/.rvm/rubies
/rbx-head/lib/tooling/profiler
/profiler.rb:148
{ } in Rubinius::Profiler::Instrumenter#flat at /home/betelgeuse/.rvm/rubies
/rbx-head/lib/tooling/profiler
/profiler.rb:133
Array#each at kernel/bootstrap/array.rb:66
Rubinius::Profiler::Instrumenter#flat at /home/betelgeuse/.rvm/rubies/rbx-head
/lib/tooling/profiler/profiler.rb:132
Rubinius::Profiler::Instrumenter#show at /home/betelgeuse/.rvm/rubies/rbx-head
/lib/tooling/profiler/profiler.rb:113
Rubinius::Profiler::Instrumenter#profile at /home/betelgeuse/.rvm/rubies
/rbx-head/lib/tooling/profiler
/profiler.rb:91
Object#__script__ at script/rails:17
Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:65
Rubinius::CodeLoader.load_script at kernel/delta/codeloader.rb:107
Rubinius::Loader#script at kernel/loader.rb:653
Rubinius::Loader#main at kernel/loader.rb:808
No profiling data was available
Command exited with non-zero status 1
85.18user 30.93system 1:48.74elapsed 106%CPU (0avgtext+0avgdata 1030368maxresident)k
0inputs+0outputs (0major+126557minor)pagefaults 0swaps

```