Skip to content

Commit

Permalink
[mono] Disable counters and logdest on wasm (dotnet#51525)
Browse files Browse the repository at this point in the history
  • Loading branch information
CoffeeFlux committed Apr 23, 2021
1 parent f39f83d commit 6cd562f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/mono/cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@
/* Disable Threads */
#cmakedefine DISABLE_THREADS 1

/* Disable perf counters */
#cmakedefine DISABLE_PERF_COUNTERS

/* Disable MONO_LOG_DEST */
#cmakedefine DISABLE_LOG_DEST

/* GC description */
#cmakedefine DEFAULT_GC_NAME 1

Expand Down
2 changes: 2 additions & 0 deletions src/mono/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ option (DISABLE_EXECUTABLES "Disable the build of the runtime executables")
option (DISABLE_CRASH_REPORTING "Disable crash reporting subsystem")
option (DISABLE_ICALL_TABLES "Enable separate icall table library")
option (DISABLE_QCALLS "Disable support for QCalls")
option (DISABLE_PERF_COUNTERS "Disable support for perf counters")
option (DISABLE_LOG_DEST "Disable MONO_LOG_DEST support")
option (ENABLE_ICALL_EXPORT "Export icall functions")
option (ENABLE_ICALL_SYMBOL_MAP "Generate tables which map icall functions to their C symbols")
option (ENABLE_PERFTRACING "Enables support for eventpipe library")
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
</ItemGroup>
<!-- WASM specific options -->
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true'">
<_MonoMinimal Condition="'$(Configuration)' == 'Release'">,debugger_agent</_MonoMinimal>
<_MonoMinimal Condition="'$(Configuration)' == 'Release'">,debugger_agent,log_dest,perf_counters</_MonoMinimal>
<_MonoMinimal Condition="'$(Configuration)' == 'Release' and '$(MonoEnableAssertMessages)' != 'true'">$(_MonoMinimal),assert_messages</_MonoMinimal>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsBrowser)' == 'true'">
Expand Down
97 changes: 97 additions & 0 deletions src/mono/mono/utils/mono-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct _MonoCounter {
size_t size;
};

#ifndef DISABLE_PERF_COUNTERS

static MonoCounter *counters = NULL;
static mono_mutex_t counters_mutex;

Expand Down Expand Up @@ -749,4 +751,99 @@ mono_runtime_resource_set_callback (MonoResourceCallback callback)
limit_reached = callback;
}

#else // DISABLE_MONO_COUNTERS

int
mono_counter_get_variance (MonoCounter *counter)
{
return 0;
}

int
mono_counter_get_unit (MonoCounter *counter)
{
return 0;
}

int
mono_counter_get_section (MonoCounter *counter)
{
return 0;
}

int
mono_counter_get_type (MonoCounter *counter)
{
return 0;
}

size_t
mono_counter_get_size (MonoCounter *counter)
{
return 0;
}

void
mono_counters_enable (int section_mask)
{
}

void
mono_counters_init (void)
{
}

void
mono_counters_register (const char* name, int type, void *addr)
{
}

void
mono_counters_register_with_size (const char *name, int type, void *addr, int size)
{
}

void
mono_counters_on_register (MonoCounterRegisterCallback callback)
{
}

void
mono_counters_foreach (CountersEnumCallback cb, gpointer user_data)
{
}

int
mono_counters_sample (MonoCounter *counter, void *buffer, int buffer_size)
{
return 0;
}

void
mono_counters_dump (int section_mask, FILE *outfile)
{
}

void
mono_counters_cleanup (void)
{
}

void
mono_runtime_resource_check_limit (int resource_type, uintptr_t value)
{
}

int
mono_runtime_resource_limit (int resource_type, uintptr_t soft_limit, uintptr_t hard_limit)
{
return 1;
}

void
mono_runtime_resource_set_callback (MonoResourceCallback callback)
{
}

#endif // DISABLE_MONO_COUNTERS

7 changes: 6 additions & 1 deletion src/mono/mono/utils/mono-logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ mono_trace_set_logdest_string (const char *dest)
logger.writer = mono_log_write_os_log;
logger.closer = mono_log_close_os_log;
logger.dest = (char*) dest;
#else
#elif !defined(DISABLE_LOG_DEST)
if (dest && !strcmp("flight-recorder", dest)) {
logger.opener = mono_log_open_recorder;
logger.writer = mono_log_write_recorder;
Expand All @@ -164,6 +164,11 @@ mono_trace_set_logdest_string (const char *dest)
logger.closer = mono_log_close_logfile;
logger.dest = (char *) dest;
}
#else
logger.opener = mono_log_open_logfile;
logger.writer = mono_log_write_logfile;
logger.closer = mono_log_close_logfile;
logger.dest = NULL;
#endif

mono_trace_set_log_handler_internal(&logger, NULL);
Expand Down

0 comments on commit 6cd562f

Please sign in to comment.