1
1
#include < cstdlib>
2
+ #include < cstdio>
3
+ #include < cstring>
4
+
2
5
#include < inttypes.h>
6
+ #include < fcntl.h>
3
7
8
+ #include " android-system.hh"
4
9
#include " cppcompat.hh"
5
10
#include " logger.hh"
6
11
#include " monodroid-glue-internal.hh"
@@ -40,8 +45,34 @@ MonodroidRuntime::dump_method_events ()
40
45
mono_profiler_set_jit_begin_callback (profiler_handle, nullptr );
41
46
mono_profiler_set_jit_done_callback (profiler_handle, nullptr );
42
47
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 ());
43
74
44
- fprintf (
75
+ dprintf (
45
76
jit_log,
46
77
R"( <?xml version="1.0" encoding="utf-8"?>)
47
78
<methods count="%zu">
@@ -54,7 +85,7 @@ MonodroidRuntime::dump_method_events ()
54
85
bool was_jited = (record.state & MethodEventRecord::JitStateStarted) == MethodEventRecord::JitStateStarted;
55
86
timing_diff diff { record.jit_elapsed };
56
87
57
- fprintf (
88
+ dprintf (
58
89
jit_log,
59
90
R"( <method name="%s" invocation_count="%)" PRIu64 R"( " jit_time="%li:%u::%u" jit_status="%s" />
60
91
)" ,
@@ -70,8 +101,6 @@ MonodroidRuntime::dump_method_events ()
70
101
}
71
102
72
103
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);
77
106
}
0 commit comments