Skip to content

Commit b6a8764

Browse files
authored
[browser] dev tools profiler - method name resolution (#115726)
1 parent a9114e3 commit b6a8764

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

eng/testing/scenarios/BuildWasmAppsJobsList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ Wasm.Build.Tests.DebugLevelTests
4949
Wasm.Build.Tests.PreloadingTests
5050
Wasm.Build.Tests.EnvVariablesTests
5151
Wasm.Build.Tests.HttpTests
52+
Wasm.Build.Tests.DiagnosticsTests

src/mono/browser/runtime/driver.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,12 @@ EMSCRIPTEN_KEEPALIVE char * mono_wasm_method_get_name_ex (MonoMethod *method) {
521521
MONO_ENTER_GC_UNSAFE;
522522
const char *method_name = mono_method_get_name (method);
523523
// starts with .ctor or .cctor
524-
if (mono_method_get_flags (method, NULL) & 0x0800 /* METHOD_ATTRIBUTE_SPECIAL_NAME */ && strlen (res) < 7) {
524+
if (!method_name) {
525+
res = strdup ("<unknown>");
526+
} else if (method_name && mono_method_get_flags (method, NULL) & 0x0800 /* METHOD_ATTRIBUTE_SPECIAL_NAME */ && strlen (method_name) < 7) {
525527
res = (char *) malloc (128);
526528
snprintf (res, 128,"%s.%s", mono_class_get_name (mono_method_get_class (method)), method_name);
529+
res[127] = '\0';
527530
} else {
528531
res = strdup (method_name);
529532
}

src/mono/wasm/Wasm.Build.Tests/DiagnosticsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public async Task RunSimpleAppWithLogProfiler()
4646
public async Task RunSimpleAppWithBrowserProfiler()
4747
{
4848
Configuration config = Configuration.Release;
49-
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "BrowserProfilerTest");
5049

51-
string extraArgs = $"-p:WasmProfilers=\"browser\"";
52-
BuildProject(info, config, new BuildOptions(ExtraMSBuildArgs: extraArgs, AssertAppBundle: false, WasmPerfTracing: true), isNativeBuild: true);
50+
string extraProperties = "<WasmProfilers>browser:callspec=all,interval=0</WasmProfilers>";
51+
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "BrowserProfilerTest", extraProperties: extraProperties);
52+
53+
BuildProject(info, config, new BuildOptions(AssertAppBundle: false, WasmPerfTracing: true), isNativeBuild: true);
5354

54-
var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "BrowserProfilerTest"));
55-
Assert.Contains("performance.measure: TestMeaning", result.TestOutput);
55+
await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "BrowserProfilerTest"));
5656
}
5757
}

src/mono/wasm/testassets/WasmBasicTestApp/App/BrowserProfilerTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,21 @@
77

88
public partial class BrowserProfilerTest
99
{
10+
public class ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
11+
{
12+
bool _even;
13+
public ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789(int i)
14+
{
15+
_even = i % 2 == 0;
16+
}
17+
}
18+
1019
[JSExport]
1120
public static int TestMeaning()
1221
{
1322
for(int i=0; i<100; i++){
1423
var r = new int[1000];
24+
var bla = new ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789(i);
1525
}
1626

1727
return 42;

src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,12 @@ try {
312312
break;
313313
case "BrowserProfilerTest":
314314
console.log("not ready yet")
315-
const origMeasure = globalThis.performance.measure
315+
let foundB = false;
316316
globalThis.performance.measure = (method, options) => {
317317
console.log(`performance.measure: ${method}`);
318-
origMeasure(method, options);
318+
if (method === "TestMeaning") {
319+
foundB = true;
320+
}
319321
};
320322
const myExportsB = await getAssemblyExports(config.mainAssemblyName);
321323
const testMeaningB = myExportsB.BrowserProfilerTest.TestMeaning;
@@ -325,7 +327,7 @@ try {
325327
document.getElementById("out").innerHTML = retB;
326328
console.debug(`ret: ${retB}`);
327329

328-
exit(retB == 42 ? 0 : 1);
330+
exit(foundB && retB == 42 ? 0 : 1);
329331

330332
break;
331333
case "OverrideBootConfigName":

0 commit comments

Comments
 (0)