Skip to content

[coreclr] Enable CoreCLR profiling based on debug.mono.profile #9971

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions src/native/clr/host/host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ void Host::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass runtimeCl
jstring_array_wrapper runtimeApks (env, runtimeApksJava);
AndroidSystem::setup_app_library_directories (runtimeApks, applicationDirs, haveSplitApks);

set_profile_options ();

gather_assemblies_and_libraries (runtimeApks, haveSplitApks);

size_t clr_init_time_index;
Expand Down Expand Up @@ -487,3 +489,20 @@ auto Host::Java_JNI_OnLoad (JavaVM *vm, [[maybe_unused]] void *reserved) noexcep
AndroidSystem::init_max_gref_count ();
return JNI_VERSION_1_6;
}

inline void
Host::set_profile_options () noexcept
{
// We want to avoid dynamic allocation, thus let’s create a buffer that can take both the property value and a
// path without allocation
dynamic_local_string<SENSIBLE_PATH_MAX + Constants::PROPERTY_VALUE_BUFFER_LEN> value;
{
dynamic_local_string<Constants::PROPERTY_VALUE_BUFFER_LEN> prop_value;
if (AndroidSystem::monodroid_get_system_property (Constants::DEBUG_MONO_PROFILE_PROPERTY, prop_value) == 0)
return;

value.assign (prop_value);
log_info (LOG_DEFAULT, "Setting DOTNET_DiagnosticPorts with: {}", optional_string (value.get ()));
setenv ("DOTNET_DiagnosticPorts", value.get (), 1);
}
}
1 change: 1 addition & 0 deletions src/native/clr/include/host/host.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace xamarin::android {
static auto zip_scan_callback (std::string_view const& apk_path, int apk_fd, dynamic_local_string<SENSIBLE_PATH_MAX> const& entry_name, uint32_t offset, uint32_t size) -> bool;
static void gather_assemblies_and_libraries (jstring_array_wrapper& runtimeApks, bool have_split_apks);
static void scan_filesystem_for_assemblies_and_libraries () noexcept;
static void set_profile_options () noexcept;

static size_t clr_get_runtime_property (const char *key, char *value_buffer, size_t value_buffer_size, void *contract_context) noexcept;
static bool clr_external_assembly_probe (const char *path, void **data_start, int64_t *size) noexcept;
Expand Down
Loading