From f67de95c8d1e23f084568828468433a27babeaa2 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 14:30:23 +0100 Subject: [PATCH 1/9] Expose setting CPU SamplingProfiler rate --- src/native/eventpipe/ep-sample-profiler.c | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index b1c10d76a9deb3..f66c104340ef6a 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -205,13 +205,43 @@ sample_profiler_enable (void) } } +void +ep_sample_event_pipe_callback( + const uint8_t* source_id, + unsigned long is_enabled, + uint8_t level, + uint64_t match_any_keywords, + uint64_t match_all_keywords, + EventFilterDescriptor* filter_data, + void* callback_data) +{ + if (filter_data) { + ep_char8_t *filter_data_char = (ep_char8_t*)(filter_data->ptr); + const uint32_t filter_data_size = filter_data->size; + ep_char8_t *candidateKey = NULL; + size_t offset = 0; + const ep_char8_t *sampleProfilerIntervalMSKey = "SampleProfilerIntervalMS"; + + while (offset < filter_data_size) { + candidateKey = filter_data_char + offset; + if (strcmp(candidateKey, sampleProfilerIntervalMSKey) == 0) { + ep_sample_profiler_set_sampling_rate(_strtoui64(candidateKey + 25, 0L, 10) * 1000000); + break; + } + else { + offset += strlen(candidateKey) + 1; + } + } + } +} + void ep_sample_profiler_init (EventPipeProviderCallbackDataQueue *provider_callback_data_queue) { ep_requires_lock_held (); if (!_sampling_provider) { - _sampling_provider = provider_create_register (ep_config_get_sample_profiler_provider_name_utf8 (), NULL, NULL, provider_callback_data_queue); + _sampling_provider = provider_create_register (ep_config_get_sample_profiler_provider_name_utf8 (), ep_sample_event_pipe_callback, NULL, provider_callback_data_queue); ep_raise_error_if_nok (_sampling_provider != NULL); _thread_time_event = provider_add_event ( _sampling_provider, From 0120edd8c42730bdd0292b3fdf711184e04a744b Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 15:21:17 +0100 Subject: [PATCH 2/9] fix build issues with _strtoui64 --- src/native/eventpipe/ep-sample-profiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index f66c104340ef6a..c324420d461f27 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -225,7 +225,7 @@ ep_sample_event_pipe_callback( while (offset < filter_data_size) { candidateKey = filter_data_char + offset; if (strcmp(candidateKey, sampleProfilerIntervalMSKey) == 0) { - ep_sample_profiler_set_sampling_rate(_strtoui64(candidateKey + 25, 0L, 10) * 1000000); + ep_sample_profiler_set_sampling_rate(strtol(candidateKey + 25, 0L, 10) * 1000000); break; } else { From 389516c92183f5c4ee89695ef38e72bc8bfed85b Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 15:36:24 +0100 Subject: [PATCH 3/9] include stdlib --- src/native/eventpipe/ep-sample-profiler.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index c324420d461f27..3fa86465d6462a 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -1,4 +1,5 @@ #include "ep-rt-config.h" +#include #ifdef ENABLE_PERFTRACING #if !defined(EP_INCLUDE_SOURCE_FILES) || defined(EP_FORCE_INCLUDE_SOURCE_FILES) @@ -225,7 +226,7 @@ ep_sample_event_pipe_callback( while (offset < filter_data_size) { candidateKey = filter_data_char + offset; if (strcmp(candidateKey, sampleProfilerIntervalMSKey) == 0) { - ep_sample_profiler_set_sampling_rate(strtol(candidateKey + 25, 0L, 10) * 1000000); + ep_sample_profiler_set_sampling_rate(_strtoui64(candidateKey + 25, NULL, 10) * 1000000); break; } else { From b160fe5d81cb8bf210f22f281fce489a2e20043a Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 15:54:48 +0100 Subject: [PATCH 4/9] change to stroull --- src/native/eventpipe/ep-sample-profiler.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 3fa86465d6462a..2c1a76c49b1894 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -1,5 +1,4 @@ #include "ep-rt-config.h" -#include #ifdef ENABLE_PERFTRACING #if !defined(EP_INCLUDE_SOURCE_FILES) || defined(EP_FORCE_INCLUDE_SOURCE_FILES) @@ -226,7 +225,7 @@ ep_sample_event_pipe_callback( while (offset < filter_data_size) { candidateKey = filter_data_char + offset; if (strcmp(candidateKey, sampleProfilerIntervalMSKey) == 0) { - ep_sample_profiler_set_sampling_rate(_strtoui64(candidateKey + 25, NULL, 10) * 1000000); + ep_sample_profiler_set_sampling_rate(strtoull(candidateKey + 25, NULL, 10) * 1000000); break; } else { From 6b3a71c6a41ce40fd6e5adfa1b5b4d6ddf92dd7c Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 17:01:38 +0100 Subject: [PATCH 5/9] make function static --- src/native/eventpipe/ep-sample-profiler.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 2c1a76c49b1894..1e69505074b4fa 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -56,6 +56,17 @@ static void sample_profiler_enable (void); +static +void +ep_sample_event_pipe_callback( + const uint8_t* source_id, + unsigned long is_enabled, + uint8_t level, + uint64_t match_any_keywords, + uint64_t match_all_keywords, + EventFilterDescriptor* filter_data, + void* callback_data); + /* * EventPipeSampleProfiler. */ @@ -205,6 +216,7 @@ sample_profiler_enable (void) } } +static void ep_sample_event_pipe_callback( const uint8_t* source_id, From ad342f8f967746ac994fcbcc86b327833951d267 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 17:38:04 +0100 Subject: [PATCH 6/9] fix warning on pointer cast --- src/native/eventpipe/ep-sample-profiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 1e69505074b4fa..715190112ed1be 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -228,7 +228,7 @@ ep_sample_event_pipe_callback( void* callback_data) { if (filter_data) { - ep_char8_t *filter_data_char = (ep_char8_t*)(filter_data->ptr); + ep_char8_t *filter_data_char = reinterpret_cast(filter_data->ptr); const uint32_t filter_data_size = filter_data->size; ep_char8_t *candidateKey = NULL; size_t offset = 0; From 5f5f1fb1d671ace9018b5621ec408b690d177371 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 19:57:38 +0100 Subject: [PATCH 7/9] another way of casting 2 --- src/native/eventpipe/ep-sample-profiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 715190112ed1be..073f845f8ddbe8 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -228,7 +228,7 @@ ep_sample_event_pipe_callback( void* callback_data) { if (filter_data) { - ep_char8_t *filter_data_char = reinterpret_cast(filter_data->ptr); + ep_char8_t *filter_data_char = (ep_char8_t *)((void *)(filter_data->ptr)); const uint32_t filter_data_size = filter_data->size; ep_char8_t *candidateKey = NULL; size_t offset = 0; From 54d83a018380de025f62cfec24c5a11d47967c86 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sat, 18 Mar 2023 20:24:35 +0100 Subject: [PATCH 8/9] another way of casting 3 --- src/native/eventpipe/ep-sample-profiler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 073f845f8ddbe8..487b3fc1545dd6 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -228,7 +228,7 @@ ep_sample_event_pipe_callback( void* callback_data) { if (filter_data) { - ep_char8_t *filter_data_char = (ep_char8_t *)((void *)(filter_data->ptr)); + ep_char8_t *filter_data_char = (ep_char8_t *)((uintptr_t)(filter_data->ptr)); const uint32_t filter_data_size = filter_data->size; ep_char8_t *candidateKey = NULL; size_t offset = 0; From 40450b57e69186d55f09a849f6c6f8609313411e Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Sun, 19 Mar 2023 10:55:54 +0100 Subject: [PATCH 9/9] delete separate prototype --- src/native/eventpipe/ep-sample-profiler.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/native/eventpipe/ep-sample-profiler.c b/src/native/eventpipe/ep-sample-profiler.c index 487b3fc1545dd6..b337b9ddc39244 100644 --- a/src/native/eventpipe/ep-sample-profiler.c +++ b/src/native/eventpipe/ep-sample-profiler.c @@ -56,17 +56,6 @@ static void sample_profiler_enable (void); -static -void -ep_sample_event_pipe_callback( - const uint8_t* source_id, - unsigned long is_enabled, - uint8_t level, - uint64_t match_any_keywords, - uint64_t match_all_keywords, - EventFilterDescriptor* filter_data, - void* callback_data); - /* * EventPipeSampleProfiler. */