Skip to content

Commit c74ba8e

Browse files
committed
Try as I might, can't get counts working without the interpreter
Will probably require a custom build of the MonoVM runtime :(
1 parent cb401ab commit c74ba8e

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/native/monodroid/monodroid-glue-internal.hh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ namespace xamarin::android::internal
268268
jmethodID java_System_identityHashCode;
269269
jmethodID Class_getName;
270270
jclass java_TimeZone;
271-
FILE *jit_log;
272271
MonoProfilerHandle profiler_handle;
273272

274273
/*

src/native/monodroid/monodroid-glue.cc

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -684,21 +684,11 @@ MonodroidRuntime::mono_runtime_init ([[maybe_unused]] JNIEnv *env, [[maybe_unuse
684684
// TESTING UBSAN: integer overflow
685685
//log_warn (LOG_DEFAULT, "Let us have an overflow: %d", INT_MAX + 1);
686686

687-
bool log_methods = FastTiming::enabled () && !FastTiming::is_bare_mode ();
688-
if (log_methods) [[unlikely]] {
689-
log_debug (LOG_ASSEMBLY, "Enabling method logging");
690-
std::unique_ptr<char> jit_log_path {Util::path_combine (AndroidSystem::override_dirs [0], "methods.txt")};
691-
log_debug (LOG_ASSEMBLY, "JIT log path: %s", jit_log_path.get ());
692-
Util::create_directory (AndroidSystem::override_dirs [0], 0755);
693-
jit_log = Util::monodroid_fopen (jit_log_path.get (), "w");
694-
Util::set_world_accessable (jit_log_path.get ());
695-
}
696-
697687
profiler_handle = mono_profiler_create (nullptr);
698688
mono_profiler_set_thread_started_callback (profiler_handle, thread_start);
699689
mono_profiler_set_thread_stopped_callback (profiler_handle, thread_end);
700690

701-
if (log_methods) [[unlikely]]{
691+
if (FastTiming::enabled () && !FastTiming::is_bare_mode ()) [[unlikely]]{
702692
method_event_map_write_lock = std::make_unique<mutex> ();
703693
method_event_map = std::make_unique<method_event_map_t> ();
704694

src/native/monodroid/performance-methods.cc

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#include <cstdlib>
2+
#include <cstdio>
3+
#include <cstring>
4+
25
#include <inttypes.h>
6+
#include <fcntl.h>
37

8+
#include "android-system.hh"
49
#include "cppcompat.hh"
510
#include "logger.hh"
611
#include "monodroid-glue-internal.hh"
@@ -40,8 +45,34 @@ MonodroidRuntime::dump_method_events ()
4045
mono_profiler_set_jit_begin_callback (profiler_handle, nullptr);
4146
mono_profiler_set_jit_done_callback (profiler_handle, nullptr);
4247
mono_profiler_set_jit_failed_callback (profiler_handle, nullptr);
48+
mono_profiler_set_method_begin_invoke_callback (profiler_handle, nullptr);
49+
mono_profiler_set_method_end_invoke_callback (profiler_handle, nullptr);
50+
51+
switch (AndroidSystem::get_mono_aot_mode ()) {
52+
case MonoAotMode::MONO_AOT_MODE_INTERP:
53+
case MonoAotMode::MONO_AOT_MODE_INTERP_ONLY:
54+
case MonoAotMode::MONO_AOT_MODE_INTERP_LLVMONLY:
55+
case MonoAotMode::MONO_AOT_MODE_LLVMONLY_INTERP:
56+
mono_profiler_set_call_instrumentation_filter_callback (profiler_handle, nullptr);
57+
mono_profiler_set_method_enter_callback (profiler_handle, nullptr);
58+
mono_profiler_set_method_leave_callback (profiler_handle, nullptr);
59+
break;
60+
61+
default:
62+
// Other AOT modes are ignored
63+
break;
64+
}
65+
66+
std::unique_ptr<char> jit_log_path {Util::path_combine (AndroidSystem::override_dirs [0], "methods.xml")};
67+
Util::create_directory (AndroidSystem::override_dirs [0], 0755);
68+
int jit_log = open (jit_log_path.get (), O_CREAT | O_WRONLY | O_TRUNC | O_SYNC, 0644);
69+
if (jit_log < 0) {
70+
log_error (LOG_DEFAULT, "Failed to open '%s' for writing: %s", jit_log_path.get (), strerror (errno));
71+
return;
72+
}
73+
Util::set_world_accessable (jit_log_path.get ());
4374

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

57-
fprintf (
88+
dprintf (
5889
jit_log,
5990
R"( <method name="%s" invocation_count="%)" PRIu64 R"(" jit_time="%li:%u::%u" jit_status="%s" />
6091
)",
@@ -70,8 +101,6 @@ MonodroidRuntime::dump_method_events ()
70101
}
71102

72103
method_event_map->clear ();
73-
fprintf (jit_log, "</methods>\n");
74-
fflush (jit_log);
75-
fclose (jit_log);
76-
jit_log = nullptr;
104+
dprintf (jit_log, "</methods>\n");
105+
close (jit_log);
77106
}

0 commit comments

Comments
 (0)