From 44e32d4ff7b40802459713247270720c97fc6235 Mon Sep 17 00:00:00 2001 From: Andrey Date: Fri, 7 Jun 2024 21:23:37 +0200 Subject: [PATCH] use filename returned from profile frames for prefix path checks --- ext/datadog_cov/datadog_cov.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/datadog_cov/datadog_cov.c b/ext/datadog_cov/datadog_cov.c index 1758e7de..21065667 100644 --- a/ext/datadog_cov/datadog_cov.c +++ b/ext/datadog_cov/datadog_cov.c @@ -118,19 +118,6 @@ static void dd_cov_update_coverage(rb_event_flag_t event, VALUE data, VALUE self } dd_cov_data->last_filename_ptr = current_filename_ptr; - // if the current filename is not located under the root, we skip it - if (strncmp(dd_cov_data->root, c_filename, dd_cov_data->root_len) != 0) - { - return; - } - - // if ignored_path is provided and the current filename is located under the ignored_path, we skip it too - // this is useful for ignoring bundled gems location - if (dd_cov_data->ignored_path_len != 0 && strncmp(dd_cov_data->ignored_path, c_filename, dd_cov_data->ignored_path_len) == 0) - { - return; - } - int captured_frames = rb_profile_frames( 0 /* stack starting depth */, PROFILE_FRAMES_BUFFER_SIZE, @@ -148,6 +135,20 @@ static void dd_cov_update_coverage(rb_event_flag_t event, VALUE data, VALUE self return; } + char *filename_ptr = StringValuePtr(filename); + // if the current filename is not located under the root, we skip it + if (strncmp(dd_cov_data->root, filename_ptr, dd_cov_data->root_len) != 0) + { + return; + } + + // if ignored_path is provided and the current filename is located under the ignored_path, we skip it too + // this is useful for ignoring bundled gems location + if (dd_cov_data->ignored_path_len != 0 && strncmp(dd_cov_data->ignored_path, filename_ptr, dd_cov_data->ignored_path_len) == 0) + { + return; + } + rb_hash_aset(dd_cov_data->coverage, filename, Qtrue); }