From a2f71eaad09bcc661949566b982795e79b9c1423 Mon Sep 17 00:00:00 2001 From: Scott Francis Date: Tue, 23 May 2017 21:03:23 -0400 Subject: [PATCH 1/2] Fix missed samples stat in object mode --- ext/stackprof/stackprof.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/stackprof/stackprof.c b/ext/stackprof/stackprof.c index 3c075ca4..c064cbee 100644 --- a/ext/stackprof/stackprof.c +++ b/ext/stackprof/stackprof.c @@ -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; @@ -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; } @@ -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); } From ff09c5ef786b09a60f3eb059459058138ccf14cd Mon Sep 17 00:00:00 2001 From: Scott Francis Date: Wed, 24 May 2017 08:30:51 -0400 Subject: [PATCH 2/2] Add test --- test/test_stackprof.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/test_stackprof.rb b/test/test_stackprof.rb index 27da5c37..ce6c9405 100644 --- a/test/test_stackprof.rb +++ b/test/test_stackprof.rb @@ -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