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

Fix missed samples stat in object mode #109

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static struct {

size_t overall_signals;
size_t overall_samples;
size_t newobj_signals;
size_t during_gc;
size_t unrecorded_gc_samples;
st_table *frames;
Expand Down Expand Up @@ -96,6 +97,7 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
_stackprof.frames = st_init_numtable();
_stackprof.overall_signals = 0;
_stackprof.overall_samples = 0;
_stackprof.newobj_signals = 0;
_stackprof.during_gc = 0;
}

Expand Down Expand Up @@ -572,9 +574,10 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
static void
stackprof_newobj_handler(VALUE tpval, void *data)
{
_stackprof.overall_signals++;
if (RTEST(_stackprof.interval) && _stackprof.overall_signals % NUM2LONG(_stackprof.interval))
_stackprof.newobj_signals++;
if (RTEST(_stackprof.interval) && _stackprof.newobj_signals % NUM2LONG(_stackprof.interval))
return;
_stackprof.overall_signals++;
stackprof_job_handler(0);
}

Expand Down
8 changes: 8 additions & 0 deletions test/test_stackprof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ def test_object_allocation_interval
assert_equal 10, profile[:samples]
end

def test_object_allocation_missed_samples
profile = StackProf.run(mode: :object, interval: 100) do
1000.times { Object.new }
end
assert_equal 10, profile[:samples]
assert_equal 0, profile[:missed_samples]
end

def test_cputime
profile = StackProf.run(mode: :cpu, interval: 500) do
math
Expand Down