generated from unoplatform/template
-
Notifications
You must be signed in to change notification settings - Fork 8
/
0006-enable-log-profiler.patch
247 lines (224 loc) · 10.6 KB
/
0006-enable-log-profiler.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
From 37c21886fd6182731791059864656b32d7dd0805 Mon Sep 17 00:00:00 2001
From: Jerome Laban <jerome@platform.uno>
Date: Mon, 19 Jun 2023 12:46:00 +0000
Subject: [PATCH] enable log profiler
---
.../Directory.Build.props | 1 +
src/mono/mono.proj | 3 +++
src/mono/mono/mini/mini-wasm.c | 1 -
src/mono/mono/profiler/CMakeLists.txt | 7 +++++++
src/mono/mono/profiler/helper.c | 6 ++++++
src/mono/mono/profiler/log.c | 18 +++++++++++++++++-
src/mono/wasm/runtime/profiler.ts | 9 +++++++--
src/mono/wasm/runtime/startup.ts | 6 +++++-
src/mono/wasm/runtime/types/internal.ts | 5 +++++
9 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
index 3a961b3078c..65ffb10837b 100644
--- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
+++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
@@ -232,6 +232,7 @@
<PlatformManifestFileEntry Include="libmono-ee-interp.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-icall-table.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-profiler-aot.a" IsNative="true" />
+ <PlatformManifestFileEntry Include="libmono-profiler-log.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-profiler-browser.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-wasm-eh-js.a" IsNative="true" />
<PlatformManifestFileEntry Include="libmono-wasm-eh-wasm.a" IsNative="true" />
diff --git a/src/mono/mono.proj b/src/mono/mono.proj
index 8b412b3369e..1b8c4c7b741 100644
--- a/src/mono/mono.proj
+++ b/src/mono/mono.proj
@@ -1023,6 +1023,9 @@
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-aot.a">
<Destination>$(RuntimeBinDir)libmono-profiler-aot.a</Destination>
</_MonoRuntimeArtifacts>
+ <_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-log.a">
+ <Destination>$(RuntimeBinDir)libmono-profiler-log.a</Destination>
+ </_MonoRuntimeArtifacts>
<_MonoRuntimeArtifacts Condition="'$(TargetsBrowser)' == 'true' and '$(BuildMonoAOTCrossCompilerOnly)' != 'true'" Include="$(MonoObjDir)out\lib\libmono-profiler-browser.a">
<Destination>$(RuntimeBinDir)libmono-profiler-browser.a</Destination>
</_MonoRuntimeArtifacts>
diff --git a/src/mono/mono/mini/mini-wasm.c b/src/mono/mono/mini/mini-wasm.c
index cab202a1fa3..33ad65edafe 100644
--- a/src/mono/mono/mini/mini-wasm.c
+++ b/src/mono/mono/mini/mini-wasm.c
@@ -565,7 +565,6 @@ static void *timer_handler;
void
mono_runtime_setup_stat_profiler (void)
{
- g_error ("mono_runtime_setup_stat_profiler");
}
gboolean
diff --git a/src/mono/mono/profiler/CMakeLists.txt b/src/mono/mono/profiler/CMakeLists.txt
index 6bca0098368..31ec5671508 100644
--- a/src/mono/mono/profiler/CMakeLists.txt
+++ b/src/mono/mono/profiler/CMakeLists.txt
@@ -6,6 +6,7 @@ include_directories(
${PROJECT_BINARY_DIR}/../../mono/eglib
${CMAKE_CURRENT_SOURCE_DIR}/../..
${PROJECT_SOURCE_DIR}/../
+ ${PROJECT_SOURCE_DIR}/../../../native/public
${PROJECT_SOURCE_DIR}/../eglib
${PROJECT_SOURCE_DIR}/../sgen)
@@ -30,6 +31,12 @@ if(NOT DISABLE_LIBS)
endif()
endif()
+ if(HOST_WASM)
+ add_library(mono-profiler-log-static STATIC helper.c log.c log-args.c)
+ set_target_properties(mono-profiler-log-static PROPERTIES OUTPUT_NAME mono-profiler-log)
+ install(TARGETS mono-profiler-log-static LIBRARY)
+ endif()
+
if(NOT HOST_WASI)
add_library(mono-profiler-aot-static STATIC aot.c helper.c)
target_link_libraries(mono-profiler-aot-static PRIVATE monoapi)
diff --git a/src/mono/mono/profiler/helper.c b/src/mono/mono/profiler/helper.c
index bbff8e7bf95..05fc31b6708 100644
--- a/src/mono/mono/profiler/helper.c
+++ b/src/mono/mono/profiler/helper.c
@@ -8,7 +8,9 @@
#include <config.h>
+#if !defined (HOST_WASM)
#include <mono/utils/mono-logger-internals.h>
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -42,6 +44,7 @@ mono_profhelper_close_socket_fd (SOCKET fd)
void
mono_profhelper_setup_command_server (SOCKET *server_socket, int *command_port, const char* profiler_name)
{
+#if !defined (HOST_WASM)
*server_socket = socket (PF_INET, SOCK_STREAM, 0);
if (*server_socket == INVALID_SOCKET) {
@@ -77,11 +80,13 @@ mono_profhelper_setup_command_server (SOCKET *server_socket, int *command_port,
}
*command_port = ntohs (server_address.sin_port);
+#endif
}
void
mono_profhelper_add_to_fd_set (fd_set *set, SOCKET fd, int *max_fd)
{
+#if !defined (HOST_WASM)
/*
* This should only trigger for the basic FDs (server socket, pipes) at
* startup if for some mysterious reason they're too large. In this case,
@@ -99,4 +104,5 @@ mono_profhelper_add_to_fd_set (fd_set *set, SOCKET fd, int *max_fd)
if (*max_fd < GUINT64_TO_INT(fd))
*max_fd = (int)fd;
+#endif
}
diff --git a/src/mono/mono/profiler/log.c b/src/mono/mono/profiler/log.c
index 1aa33e9c40e..eff4aef5de0 100644
--- a/src/mono/mono/profiler/log.c
+++ b/src/mono/mono/profiler/log.c
@@ -3503,6 +3503,7 @@ runtime_initialized (MonoProfiler *profiler)
mono_os_sem_init (&log_profiler.attach_threads_sem, 0);
+#if !defined (HOST_WASM)
/*
* We must start the helper thread before the writer thread. This is
* because start_helper_thread () sets up the command port which is written
@@ -3511,6 +3512,9 @@ runtime_initialized (MonoProfiler *profiler)
start_helper_thread ();
start_writer_thread ();
start_dumper_thread ();
+#else
+ dump_header ();
+#endif
/*
* Wait for all the internal threads to be started. If we don't do this, we
@@ -3592,7 +3596,7 @@ create_profiler (const char *args, const char *filename, GPtrArray *filters)
}
}
if (*nf == '|') {
-#if HAVE_API_SUPPORT_WIN32_PIPE_OPEN_CLOSE && !defined (HOST_WIN32)
+#if HAVE_API_SUPPORT_WIN32_PIPE_OPEN_CLOSE && !defined (HOST_WIN32) && !defined (HOST_WASM)
log_profiler.file = popen (nf + 1, "w");
log_profiler.pipe_output = 1;
#else
@@ -3640,6 +3644,18 @@ create_profiler (const char *args, const char *filename, GPtrArray *filters)
log_profiler.startup_time = current_time ();
}
+#if defined (HOST_WASM)
+MONO_API void
+mono_profiler_flush_log ();
+
+void
+mono_profiler_flush_log ()
+{
+ while (handle_writer_queue_entry ());
+ while (handle_dumper_queue_entry ());
+}
+#endif
+
MONO_API void
mono_profiler_init_log (const char *desc);
diff --git a/src/mono/wasm/runtime/profiler.ts b/src/mono/wasm/runtime/profiler.ts
index da627b50ec4..c2e4db95746 100644
--- a/src/mono/wasm/runtime/profiler.ts
+++ b/src/mono/wasm/runtime/profiler.ts
@@ -1,8 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
-import { ENVIRONMENT_IS_WEB, linkerEnableAotProfiler, linkerEnableBrowserProfiler, mono_assert, runtimeHelpers } from "./globals";
-import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions } from "./types/internal";
+import { ENVIRONMENT_IS_WEB, linkerEnableAotProfiler, linkerEnableBrowserProfiler, mono_assert, Module, runtimeHelpers } from "./globals";
+import { MonoMethod, AOTProfilerOptions, BrowserProfilerOptions, LogProfilerOptions } from "./types/internal";
import { profiler_c_functions as cwraps } from "./cwraps";
import { utf8ToString } from "./strings";
@@ -98,3 +98,8 @@ export function mono_wasm_profiler_leave(method: MonoMethod): void {
globalThis.performance.measure(methodName, options);
}
}
+
+// options = { configuration: "log profiler options string" }
+export function mono_wasm_init_log_profiler(options: LogProfilerOptions): void {
+ Module.ccall("mono_wasm_load_profiler_log", null, ["string"], [options.configuration]);
+}
\ No newline at end of file
diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts
index e9eee44f0de..3f867a9741e 100644
--- a/src/mono/wasm/runtime/startup.ts
+++ b/src/mono/wasm/runtime/startup.ts
@@ -9,7 +9,7 @@ import { disableLegacyJsInterop, ENVIRONMENT_IS_PTHREAD, exportedRuntimeAPI, INT
import cwraps, { init_c_exports } from "./cwraps";
import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug";
import { toBase64StringImpl } from "./base64";
-import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler } from "./profiler";
+import { mono_wasm_init_aot_profiler, mono_wasm_init_browser_profiler, mono_wasm_init_log_profiler } from "./profiler";
import { initialize_marshalers_to_cs } from "./marshal-to-cs";
import { initialize_marshalers_to_js } from "./marshal-to-js";
import { init_polyfills_async } from "./polyfills";
@@ -232,6 +232,10 @@ async function onRuntimeInitializedAsync(userOnRuntimeInitialized: () => void) {
await wait_for_all_assets();
+ if (runtimeHelpers.config.logProfilerOptions) {
+ mono_wasm_init_log_profiler(runtimeHelpers.config.logProfilerOptions);
+ }
+
// Threads early are not supported with memory snapshot. See below how we enable them later.
// Please disable startupMemoryCache in order to be able to diagnose or pause runtime startup.
if (MonoWasmThreads && !runtimeHelpers.config.startupMemoryCache) {
diff --git a/src/mono/wasm/runtime/types/internal.ts b/src/mono/wasm/runtime/types/internal.ts
index f2dba23fe73..3e8e4372d66 100644
--- a/src/mono/wasm/runtime/types/internal.ts
+++ b/src/mono/wasm/runtime/types/internal.ts
@@ -69,6 +69,7 @@ export function coerceNull<T extends ManagedPointer | NativePointer>(ptr: T | nu
assets?: AssetEntryInternal[],
runtimeOptions?: string[], // array of runtime options as strings
aotProfilerOptions?: AOTProfilerOptions, // dictionary-style Object. If omitted, aot profiler will not be initialized.
+ logProfilerOptions?: LogProfilerOptions, // dictionary-style Object. If omitted, log profiler will not be initialized.
browserProfilerOptions?: BrowserProfilerOptions, // dictionary-style Object. If omitted, browser profiler will not be initialized.
waitForDebugger?: number,
appendElementOnExit?: boolean
@@ -78,6 +79,10 @@ export type MonoConfigInternal = MonoConfig & {
exitAfterSnapshot?: number
loadAllSatelliteResources?: boolean
};
+
+export type LogProfilerOptions = {
+ configuration?: string // log profiler options string"
+}
export type RunArguments = {
applicationArguments?: string[],
--
2.25.1