Skip to content

Commit c606f5a

Browse files
authored
[Mono] Enable AOT to print out the list of compiled methods (#81567)
* Initial setup * Exclude generics and update variable names * Review feedbacks and error handling
1 parent 3bec33b commit c606f5a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/mono/mono/mini/aot-compiler.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ typedef struct MonoAotOptions {
188188
char *llvm_outfile;
189189
char *data_outfile;
190190
char *export_symbols_outfile;
191+
char *compiled_methods_outfile;
191192
GList *profile_files;
192193
GList *mibc_profile_files;
193194
gboolean save_temps;
@@ -407,6 +408,7 @@ typedef struct MonoAotCompile {
407408
FILE *logfile;
408409
FILE *instances_logfile;
409410
FILE *data_outfile;
411+
FILE *compiled_methods_outfile;
410412
int datafile_offset;
411413
int gc_name_offset;
412414
// In this mode, we are emitting dedupable methods that we encounter
@@ -8546,6 +8548,8 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts)
85468548
opts->llvm_outfile = g_strdup (arg + strlen ("llvm-outfile="));
85478549
} else if (str_begins_with (arg, "export-symbols-outfile=")) {
85488550
opts->export_symbols_outfile = g_strdup (arg + strlen ("export-symbols-outfile="));
8551+
} else if (str_begins_with (arg, "compiled-methods-outfile=")) {
8552+
opts->compiled_methods_outfile = g_strdup (arg + strlen ("compiled-methods-outfile="));
85498553
} else if (str_begins_with (arg, "temp-path=")) {
85508554
opts->temp_path = clean_path (g_strdup (arg + strlen ("temp-path=")));
85518555
} else if (str_begins_with (arg, "save-temps")) {
@@ -9565,6 +9569,11 @@ compile_method (MonoAotCompile *acfg, MonoMethod *method)
95659569
mono_acfg_unlock (acfg);
95669570

95679571
mono_atomic_inc_i32 (&acfg->stats.ccount);
9572+
9573+
if (acfg->aot_opts.compiled_methods_outfile && acfg->compiled_methods_outfile != NULL) {
9574+
if (!mono_method_is_generic_impl (method) && method->token != 0)
9575+
fprintf (acfg->compiled_methods_outfile, "%x\n", method->token);
9576+
}
95689577
}
95699578

95709579
static mono_thread_start_return_t WINAPI
@@ -14525,6 +14534,12 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1452514534
acfg->logfile = fopen (acfg->aot_opts.logfile, "a+");
1452614535
}
1452714536

14537+
if (acfg->aot_opts.compiled_methods_outfile && !acfg->dedup_collect_only) {
14538+
acfg->compiled_methods_outfile = fopen (acfg->aot_opts.compiled_methods_outfile, "w+");
14539+
if (!acfg->compiled_methods_outfile)
14540+
aot_printerrf (acfg, "Unable to open compiled-methods-outfile specified file %s\n", acfg->aot_opts.compiled_methods_outfile);
14541+
}
14542+
1452814543
if (acfg->aot_opts.data_outfile) {
1452914544
acfg->data_outfile = fopen (acfg->aot_opts.data_outfile, "w+");
1453014545
if (!acfg->data_outfile) {
@@ -14880,6 +14895,10 @@ aot_assembly (MonoAssembly *ass, guint32 jit_opts, MonoAotOptions *aot_options)
1488014895

1488114896
current_acfg = NULL;
1488214897

14898+
if (acfg->compiled_methods_outfile) {
14899+
fclose (acfg->compiled_methods_outfile);
14900+
}
14901+
1488314902
return emit_aot_image (acfg);
1488414903
}
1488514904

@@ -15245,6 +15264,13 @@ mono_aot_assemblies (MonoAssembly **assemblies, int nassemblies, guint32 jit_opt
1524515264
dedup_methods = g_hash_table_new (NULL, NULL);
1524615265
}
1524715266

15267+
if (aot_opts.compiled_methods_outfile) {
15268+
if (g_ensure_directory_exists (aot_opts.compiled_methods_outfile) == FALSE) {
15269+
fprintf (stderr, "AOT : failed to create the directory to save the compiled method names: %s\n", aot_opts.compiled_methods_outfile);
15270+
exit (1);
15271+
}
15272+
}
15273+
1524815274
for (int i = 0; i < nassemblies; ++i) {
1524915275
res = aot_assembly (assemblies [i], jit_opts, &aot_opts);
1525015276
if (res != 0) {

0 commit comments

Comments
 (0)