Skip to content

Commit

Permalink
Try as I might, can't get counts working without the interpreter
Browse files Browse the repository at this point in the history
Will probably require a custom build of the MonoVM runtime :(
  • Loading branch information
grendello committed Nov 20, 2024
1 parent a7a8f91 commit 0048d70
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/native/monodroid/monodroid-glue-internal.hh
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ namespace xamarin::android::internal
jmethodID java_System_identityHashCode;
jmethodID Class_getName;
jclass java_TimeZone;
FILE *jit_log;
MonoProfilerHandle profiler_handle;

/*
Expand Down
12 changes: 1 addition & 11 deletions src/native/monodroid/monodroid-glue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,21 +684,11 @@ MonodroidRuntime::mono_runtime_init ([[maybe_unused]] JNIEnv *env, [[maybe_unuse
// TESTING UBSAN: integer overflow
//log_warn (LOG_DEFAULT, "Let us have an overflow: %d", INT_MAX + 1);

bool log_methods = FastTiming::enabled () && !FastTiming::is_bare_mode ();
if (log_methods) [[unlikely]] {
log_debug (LOG_ASSEMBLY, "Enabling method logging");
std::unique_ptr<char> jit_log_path {Util::path_combine (AndroidSystem::override_dirs [0], "methods.txt")};
log_debug (LOG_ASSEMBLY, "JIT log path: %s", jit_log_path.get ());
Util::create_directory (AndroidSystem::override_dirs [0], 0755);
jit_log = Util::monodroid_fopen (jit_log_path.get (), "w");
Util::set_world_accessable (jit_log_path.get ());
}

profiler_handle = mono_profiler_create (nullptr);
mono_profiler_set_thread_started_callback (profiler_handle, thread_start);
mono_profiler_set_thread_stopped_callback (profiler_handle, thread_end);

if (log_methods) [[unlikely]]{
if (FastTiming::enabled () && !FastTiming::is_bare_mode ()) [[unlikely]]{
method_event_map_write_lock = std::make_unique<mutex> ();
method_event_map = std::make_unique<method_event_map_t> ();

Expand Down
41 changes: 35 additions & 6 deletions src/native/monodroid/performance-methods.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <cstdlib>
#include <cstdio>
#include <cstring>

#include <inttypes.h>
#include <fcntl.h>

#include "android-system.hh"
#include "cppcompat.hh"
#include "logger.hh"
#include "monodroid-glue-internal.hh"
Expand Down Expand Up @@ -40,8 +45,34 @@ MonodroidRuntime::dump_method_events ()
mono_profiler_set_jit_begin_callback (profiler_handle, nullptr);
mono_profiler_set_jit_done_callback (profiler_handle, nullptr);
mono_profiler_set_jit_failed_callback (profiler_handle, nullptr);
mono_profiler_set_method_begin_invoke_callback (profiler_handle, nullptr);
mono_profiler_set_method_end_invoke_callback (profiler_handle, nullptr);

switch (AndroidSystem::get_mono_aot_mode ()) {
case MonoAotMode::MONO_AOT_MODE_INTERP:
case MonoAotMode::MONO_AOT_MODE_INTERP_ONLY:
case MonoAotMode::MONO_AOT_MODE_INTERP_LLVMONLY:
case MonoAotMode::MONO_AOT_MODE_LLVMONLY_INTERP:
mono_profiler_set_call_instrumentation_filter_callback (profiler_handle, nullptr);
mono_profiler_set_method_enter_callback (profiler_handle, nullptr);
mono_profiler_set_method_leave_callback (profiler_handle, nullptr);
break;

default:
// Other AOT modes are ignored
break;
}

std::unique_ptr<char> jit_log_path {Util::path_combine (AndroidSystem::override_dirs [0], "methods.xml")};
Util::create_directory (AndroidSystem::override_dirs [0], 0755);
int jit_log = open (jit_log_path.get (), O_CREAT | O_WRONLY | O_TRUNC | O_SYNC, 0644);
if (jit_log < 0) {
log_error (LOG_DEFAULT, "Failed to open '%s' for writing: %s", jit_log_path.get (), strerror (errno));
return;
}
Util::set_world_accessable (jit_log_path.get ());

fprintf (
dprintf (
jit_log,
R"(<?xml version="1.0" encoding="utf-8"?>)
<methods count="%zu">
Expand All @@ -54,7 +85,7 @@ MonodroidRuntime::dump_method_events ()
bool was_jited = (record.state & MethodEventRecord::JitStateStarted) == MethodEventRecord::JitStateStarted;
timing_diff diff { record.jit_elapsed };

fprintf (
dprintf (
jit_log,
R"( <method name="%s" invocation_count="%)" PRIu64 R"(" jit_time="%li:%u::%u" jit_status="%s" />
)",
Expand All @@ -70,8 +101,6 @@ MonodroidRuntime::dump_method_events ()
}

method_event_map->clear ();
fprintf (jit_log, "</methods>\n");
fflush (jit_log);
fclose (jit_log);
jit_log = nullptr;
dprintf (jit_log, "</methods>\n");
close (jit_log);
}

0 comments on commit 0048d70

Please sign in to comment.