srawlins / allocation_stats

Tooling for tracing object allocations in Ruby 2.1
Other
259 stars 13 forks source link

Allow compatibility with BasicObject and descendants. #1

Closed griffindy closed 10 years ago

griffindy commented 10 years ago

If you try to use AllocationStats.trace and any descendant of BasicObject (but not Object) is created during the block, it will fail from calling object_id and send. BasicObject does not implement those two methods, but does use __id__ and __send__.

That was a simple refactor. The slightly more complicated problem is that BasicObject#class does not exist. I found a way to implement #class by referencing the superclass of a BasicObject's eigenclass.

Let me know if there's anything else you want me to add to the pull request.

srawlins commented 10 years ago

Thanks for the PR! specs look good. I'm thinking of adding a spec for your case. Out of curiosity, what Basic Object descendants were involved when you found this bug?

griffindy commented 10 years ago

I can add the spec if you want, though I imagine you have your own system set up.

I happened across this while trying to profile something using sidekiq. Specifically, Redis::Future is a BasicObject, not really sure why.

srawlins commented 10 years ago

LGTM. I'll write a spec as well.