Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e5d4b7f
Extended timing of the native runtime performance
grendello Feb 21, 2024
00ebd76
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 22, 2024
77e4614
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 22, 2024
cc4bd92
Improve output
grendello Feb 22, 2024
c409721
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 23, 2024
3714c16
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 26, 2024
5d9866b
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 27, 2024
9076672
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 28, 2024
9d4f0cd
Update apkdesc files
grendello Feb 28, 2024
7036aa5
Add more events
grendello Feb 28, 2024
2e7fa09
Merge branch 'main' into dev/grendel/extended-timing
grendello Feb 29, 2024
13cfef8
It's obvious it's about duration...
grendello Feb 29, 2024
4b3ef60
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 1, 2024
f78eec1
WIP for writing to file
grendello Mar 1, 2024
e300549
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 1, 2024
3cccaae
Update apkdesc
grendello Mar 1, 2024
873f412
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 6, 2024
812ddb3
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 7, 2024
1f8b888
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 8, 2024
0a3d18d
Update apkdesc
grendello Mar 11, 2024
08d0b99
Merge branch 'main' into dev/grendel/extended-timing
grendello Mar 20, 2024
48ce87b
Merge branch 'main' into dev/grendel/extended-timing
grendello Apr 2, 2024
418279d
Merge branch 'main' into dev/grendel/extended-timing
grendello Apr 3, 2024
e2d0ef6
Merge branch 'main' into dev/grendel/extended-timing
grendello Apr 25, 2024
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
20 changes: 20 additions & 0 deletions src/monodroid/jni/basic-utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ BasicUtilities::set_world_accessable ([[maybe_unused]] const char *path)
}
}

bool
BasicUtilities::set_world_accessible (int fd) noexcept
{
if (fd < 0) {
return false;
}

int r;
do {
r = fchmod (fd, 0664);
} while (r == -1 && errno == EINTR);

if (r == -1) {
log_error (LOG_DEFAULT, "fchmod(%d, 0664) failed: %s", fd, strerror (errno));
return false;
}

return true;
}

void
BasicUtilities::set_user_executable ([[maybe_unused]] const char *path)
{
Expand Down
3 changes: 3 additions & 0 deletions src/monodroid/jni/basic-utilities.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ namespace xamarin::android
void create_public_directory (const char *dir);
int create_directory (const char *pathname, mode_t mode);
void set_world_accessable (const char *path);

[[nodiscard]]
bool set_world_accessible (int fd) noexcept;
void set_user_executable (const char *path);
bool file_exists (const char *file);
bool directory_exists (const char *directory);
Expand Down
1 change: 1 addition & 0 deletions src/monodroid/jni/debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace xamarin::android
static inline constexpr std::string_view DEBUG_MONO_RUNTIME_ARGS_PROPERTY { "debug.mono.runtime_args" };
static inline constexpr std::string_view DEBUG_MONO_SOFT_BREAKPOINTS { "debug.mono.soft_breakpoints" };
static inline constexpr std::string_view DEBUG_MONO_TRACE_PROPERTY { "debug.mono.trace" };
static inline constexpr std::string_view DEBUG_MONO_TIMING { "debug.mono.timing" };
static inline constexpr std::string_view DEBUG_MONO_WREF_PROPERTY { "debug.mono.wref" };

public:
Expand Down
87 changes: 63 additions & 24 deletions src/monodroid/jni/monodroid-glue-internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,16 @@
#include "cpp-util.hh"
#include "xxhash.hh"

#include <mono/metadata/class.h>
#include <mono/utils/mono-counters.h>
#include <mono/metadata/profiler.h>

// NDEBUG causes robin_map.h not to include <iostream> which, in turn, prevents indirect inclusion of <mutex>. <mutex>
// conflicts with our std::mutex definition in cppcompat.hh
#if !defined (NDEBUG)
#define NDEBUG
#define NDEBUG_UNDEFINE
#endif

// hush some compiler warnings
#if defined (__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#endif // __clang__

#include <tsl/robin_map.h>

#if defined (__clang__)
#pragma clang diagnostic pop
#endif // __clang__

#if defined (NDEBUG_UNDEFINE)
#undef NDEBUG
#undef NDEBUG_UNDEFINE
#endif

//#include <mono/utils/mono-publib.h>
#include <mono/jit/mono-private-unstable.h>
#include <mono/metadata/mono-private-unstable.h>

#include "robin-map.hh"

// See https://github.com/dotnet/runtime/pull/67024
// See https://github.com/xamarin/xamarin-android/issues/6935
extern mono_bool mono_opt_aot_lazy_assembly_load;
Expand All @@ -64,6 +43,35 @@ namespace xamarin::android::internal
}
};

using timing_sequence_map_t = tsl::robin_map<void*, size_t>;

class TimingProfilerState
{
public:
template<typename T>
void add_sequence (T* ptr, size_t sequence_number)
{
std::lock_guard lock (map_lock);
seq_map[ptr] = sequence_number;
}

template<typename T>
size_t get_sequence (T* ptr)
{
std::lock_guard lock (map_lock);
auto iter = seq_map.find (ptr);
if (iter == seq_map.end ()) {
return 0;
}

return iter->second;
}

private:
timing_sequence_map_t seq_map;
std::mutex map_lock;
};

class MonodroidRuntime
{
using pinvoke_api_map = tsl::robin_map<
Expand Down Expand Up @@ -228,6 +236,11 @@ namespace xamarin::android::internal
void set_debug_options ();
void parse_gdb_options ();
void mono_runtime_init (JNIEnv *env, dynamic_local_string<PROPERTY_VALUE_BUFFER_LEN>& runtime_args);
void timing_init () noexcept;
void timing_ensure_state () noexcept;
void timing_init_extended () noexcept;
void timing_init_verbose () noexcept;
void timing_init_extreme () noexcept;
void init_android_runtime (JNIEnv *env, jclass runtimeClass, jobject loader);
void set_environment_variable_for_directory (const char *name, jstring_wrapper &value, bool createDirectory, mode_t mode);

Expand Down Expand Up @@ -261,6 +274,31 @@ namespace xamarin::android::internal
static void jit_done (MonoProfiler *prof, MonoMethod *method, MonoJitInfo* jinfo);
static void thread_start (MonoProfiler *prof, uintptr_t tid);
static void thread_end (MonoProfiler *prof, uintptr_t tid);
static void prof_assembly_loading (MonoProfiler *prof, MonoAssembly *assembly) noexcept;
static void prof_assembly_loaded (MonoProfiler *prof, MonoAssembly *assembly) noexcept;
static void prof_image_loading (MonoProfiler *prof, MonoImage *assembly) noexcept;
static void prof_image_loaded (MonoProfiler *prof, MonoImage *assembly) noexcept;
static void prof_class_loading (MonoProfiler *prof, MonoClass *klass) noexcept;
static void prof_class_loaded (MonoProfiler *prof, MonoClass *klass) noexcept;
static void prof_vtable_loading (MonoProfiler *prof, MonoVTable *vtable) noexcept;
static void prof_vtable_loaded (MonoProfiler *prof, MonoVTable *vtable) noexcept;
static void prof_method_enter (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *context) noexcept;
static void prof_method_leave (MonoProfiler *prof, MonoMethod *method, MonoProfilerCallContext *context) noexcept;
static void prof_method_begin_invoke (MonoProfiler *prof, MonoMethod *method) noexcept;
static void prof_method_end_invoke (MonoProfiler *prof, MonoMethod *method) noexcept;
static void prof_monitor_contention (MonoProfiler *prof, MonoObject *object) noexcept;
static void prof_monitor_acquired (MonoProfiler *prof, MonoObject *object) noexcept;

template<size_t MaxStackSpace>
static void get_full_class_name (MonoClass *klass, internal::dynamic_local_string<MaxStackSpace>& info) noexcept
{
info.append (mono_class_get_namespace (klass));
if (info.length () > 0) {
info.append (".");
}
info.append (mono_class_get_name (klass));
}

#if !defined (RELEASE)
static MonoReflectionType* typemap_java_to_managed (MonoString *java_type_name) noexcept;
static const char* typemap_managed_to_java (MonoReflectionType *type, const uint8_t *mvid) noexcept;
Expand Down Expand Up @@ -325,6 +363,7 @@ namespace xamarin::android::internal
static void *system_native_library_handle;
static void *system_security_cryptography_native_android_library_handle;
static void *system_io_compression_native_library_handle;
static inline TimingProfilerState* timing_profiler_state = nullptr;
static std::mutex dso_handle_write_lock;
};
}
Expand Down
Loading