Skip to content

[browser] dev tools profiler - method name resolution #115726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testing/scenarios/BuildWasmAppsJobsList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ Wasm.Build.Tests.DebugLevelTests
Wasm.Build.Tests.PreloadingTests
Wasm.Build.Tests.EnvVariablesTests
Wasm.Build.Tests.HttpTests
Wasm.Build.Tests.DiagnosticsTests
5 changes: 4 additions & 1 deletion src/mono/browser/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,12 @@ EMSCRIPTEN_KEEPALIVE char * mono_wasm_method_get_name_ex (MonoMethod *method) {
MONO_ENTER_GC_UNSAFE;
const char *method_name = mono_method_get_name (method);
// starts with .ctor or .cctor
if (mono_method_get_flags (method, NULL) & 0x0800 /* METHOD_ATTRIBUTE_SPECIAL_NAME */ && strlen (res) < 7) {
if (!method_name) {
res = strdup ("<unknown>");
} else if (method_name && mono_method_get_flags (method, NULL) & 0x0800 /* METHOD_ATTRIBUTE_SPECIAL_NAME */ && strlen (method_name) < 7) {
res = (char *) malloc (128);
snprintf (res, 128,"%s.%s", mono_class_get_name (mono_method_get_class (method)), method_name);
res[127] = '\0';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is harmless but snprintf should null terminate even at max length, is it really not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MS Doc
The _snprintf family of functions only appends a terminating NULL character if the formatted string length is strictly less than count characters.

Maybe emscripten libc is different, but I wanted to be sure.

} else {
res = strdup (method_name);
}
Expand Down
10 changes: 5 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/DiagnosticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public async Task RunSimpleAppWithLogProfiler()
public async Task RunSimpleAppWithBrowserProfiler()
{
Configuration config = Configuration.Release;
ProjectInfo info = CopyTestAsset(config, false, TestAsset.WasmBasicTestApp, "BrowserProfilerTest");

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

BuildProject(info, config, new BuildOptions(AssertAppBundle: false, WasmPerfTracing: true), isNativeBuild: true);

var result = await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "BrowserProfilerTest"));
Assert.Contains("performance.measure: TestMeaning", result.TestOutput);
await RunForBuildWithDotnetRun(new BrowserRunOptions(Configuration: config, TestScenario: "BrowserProfilerTest"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@

public partial class BrowserProfilerTest
{
public class ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
{
bool _even;
public ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789(int i)
{
_even = i % 2 == 0;
}
}

[JSExport]
public static int TestMeaning()
{
for(int i=0; i<100; i++){
var r = new int[1000];
var bla = new ClassWithVeryVeryLongName012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789(i);
}

return 42;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,12 @@ try {
break;
case "BrowserProfilerTest":
console.log("not ready yet")
const origMeasure = globalThis.performance.measure
let foundB = false;
globalThis.performance.measure = (method, options) => {
console.log(`performance.measure: ${method}`);
origMeasure(method, options);
if (method === "TestMeaning") {
foundB = true;
}
};
const myExportsB = await getAssemblyExports(config.mainAssemblyName);
const testMeaningB = myExportsB.BrowserProfilerTest.TestMeaning;
Expand All @@ -325,7 +327,7 @@ try {
document.getElementById("out").innerHTML = retB;
console.debug(`ret: ${retB}`);

exit(retB == 42 ? 0 : 1);
exit(foundB && retB == 42 ? 0 : 1);

break;
case "OverrideBootConfigName":
Expand Down
Loading