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