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

ArgumentError on interval <1 or >1m #126

Merged
merged 1 commit into from
Jul 5, 2020
Merged
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
5 changes: 5 additions & 0 deletions ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <pthread.h>

#define BUF_SIZE 2048
#define MICROSECONDS_IN_SECOND 1000000

typedef struct {
size_t total_samples;
Expand Down Expand Up @@ -92,6 +93,10 @@ stackprof_start(int argc, VALUE *argv, VALUE self)
}
if (!RTEST(mode)) mode = sym_wall;

if (!NIL_P(interval) && (NUM2INT(interval) < 1 || NUM2INT(interval) >= MICROSECONDS_IN_SECOND)) {
rb_raise(rb_eArgError, "interval is a number of microseconds between 1 and 1 million");
}

if (!_stackprof.frames) {
_stackprof.frames = st_init_numtable();
_stackprof.overall_signals = 0;
Expand Down
9 changes: 9 additions & 0 deletions test/test_stackprof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,15 @@ def test_pathname_out
refute_empty profile[:frames]
end

def test_min_max_interval
[-1, 0, 1_000_000, 1_000_001].each do |invalid_interval|
err = assert_raises(ArgumentError, "invalid interval #{invalid_interval}") do
StackProf.run(interval: invalid_interval, debug: true) {}
end
assert_match(/microseconds/, err.message)
end
end

def math
250_000.times do
2 ** 10
Expand Down