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

Allocation tracing #117

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Allocation tracing #117

wants to merge 27 commits into from

Conversation

jhawthorn
Copy link
Owner

@jhawthorn jhawthorn commented Dec 17, 2024

I want to add the ability to trace and query allocation information about specific objects in the same way that ObjectSpace.trace_object_allocations works, except with full stack information.

obj = nil
allocations = Vernier::AllocationTracer.trace do
  obj = Object.new
end
stack = allocations.stack(obj)
puts stack
# Class#new at <cfunc>:0
# block in <main> at /Users/jhawthorn/src/vernier/test_allocation_tracing.rb:5
# Vernier::AllocationTracer#trace at /Users/jhawthorn/src/vernier/lib/vernier/allocation_tracer.rb:19
# Vernier::AllocationTracer.trace at /Users/jhawthorn/src/vernier/lib/vernier/allocation_tracer.rb:13
# <main> at /Users/jhawthorn/src/vernier/test_allocation_tracing.rb:4

TODO: retained profiling mode should be built off of this functionality DONE!

@jhawthorn jhawthorn changed the title WIP: Allocation tracing Allocation tracing Jan 22, 2025
@joshuay03
Copy link
Collaborator

So so keen! Gonna give it a whirl this weekend.

Copy link
Collaborator

@joshuay03 joshuay03 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Played around with it a bit and everything's working as expected.

TODO: retained profiling mode should be built off of this functionality DONE!

This is a nice win as well.

Should we mention this in the README? Happy to do that in a follow-up.

}
end

GC.verify_compaction_references(toward: :empty, expand_heap: true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, neat!

"#<#{self.class} #{elapsed_seconds} seconds, #{threads.count} threads, #{samples.count} samples, #{samples.uniq.size} unique>"
"#<#{self.class} #{elapsed_seconds rescue "?"} seconds, #{threads.count} threads, #{samples.count} samples, #{samples.uniq.size} unique>"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in case the result is inspected before the end time is set? Do we expect such a scenario considering a complete result is expected by the end of #stop, or is it more so to make debugging easier?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I guess this also ensures CustomCollector#inspect works out of the box.

# * Watching for freed objects
# * Stopped
# * Ignoring new objects
# * Ignoring for freed objects
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# * Ignoring for freed objects
# * Ignoring freed objects

@@ -1953,32 +1220,18 @@ Init_vernier(void)
VALUE rb_mVernierMarkerPhase = rb_define_module_under(rb_mVernierMarker, "Phase");
rb_mVernierMarkerType = rb_define_module_under(rb_mVernierMarker, "Type");

rb_cVernierResult = rb_define_class_under(rb_mVernier, "Result", rb_cObject);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duped on line 1218.

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

Successfully merging this pull request may close these issues.

2 participants