diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 85a13a08ffa506..885ecb33feeb2c 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -4473,13 +4473,31 @@ TADDR MethodAndStartAddressToEECodeInfoPointer(MethodDesc *pMethodDesc, PCODE pN } CONTRACTL_END; // MethodDesc ==> Code Address ==>JitManager - TADDR start = pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode(); - if(start == 0) { + TADDR entryPoint = pNativeCodeStartAddress ? pNativeCodeStartAddress : pMethodDesc->GetNativeCode(); + if(entryPoint == 0) { // this method hasn't been jitted return 0; } - return GetInterpreterCodeFromEntryPointIfPresent(start); + TADDR start = GetInterpreterCodeFromEntryPointIfPresent(entryPoint); + +#if defined(TARGET_WASM) && defined(FEATURE_PORTABLE_ENTRYPOINTS) + if (start == entryPoint && entryPoint == pMethodDesc->GetPortableEntryPointIfExists() && + PortableEntryPoint::HasNativeEntryPoint((PCODE)entryPoint)) + { + // Native R2R portable entry points store a function-table index rather than an address + // registered with ExecutionManager. EventPipe needs the corresponding synthetic virtual IP. + DWORD functionTableIndex = + static_cast(reinterpret_cast(PortableEntryPoint::GetActualCode((PCODE)entryPoint))); + TADDR virtualIP = ExecutionManager::GetWasmVirtualIPFromFunctionTableIndex(functionTableIndex); + if (virtualIP != 0) + { + start = virtualIP; + } + } +#endif // TARGET_WASM && FEATURE_PORTABLE_ENTRYPOINTS + + return start; } /****************************************************************************/ diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs index aa9daf674b9198..1bfbbb78d61224 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/EventPipeDiagnosticsTests.cs @@ -41,7 +41,6 @@ public EventPipeDiagnosticsTests(ITestOutputHelper output, SharedBuildPerTestCla [Theory] [InlineData(Configuration.Debug, false)] [InlineData(Configuration.Release, false)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/132410", typeof(BuildTestBase), nameof(IsCoreClrRuntime))] public async Task BlazorEventPipeTestWithCpuSamples(Configuration config, bool aot) { string extraProperties = @" @@ -76,20 +75,27 @@ await RunForBuildWithDotnetRun(new BlazorRunOptions( } )); - var methodFound = false; + bool appMethodFound = false; + bool readyToRunMethodFound = false; using (var source = TraceLog.OpenOrConvert(ConvertTrace(info, "cpuprofile.nettrace"))) { - methodFound = source.CallStacks.Any(stack => stack.CodeAddress.FullMethodName == "BlazorBasicTestApp.Pages.Counter.IncrementCount()"); - if (!methodFound) + appMethodFound = source.CallStacks.Any(stack => stack.CodeAddress.FullMethodName == "BlazorBasicTestApp.Pages.Counter.IncrementCount()"); + if (!appMethodFound) { foreach (var stack in source.CallStacks) { _testOutput.WriteLine($"Stack: {stack.CodeAddress.FullMethodName}"); } } + + readyToRunMethodFound = source.CodeAddresses.Any(address => address.FullMethodName.StartsWith("System.Buffer.Memmove(", StringComparison.Ordinal)); } - Assert.True(methodFound, "The cpuprofile.nettrace should contain stack frames for the 'Counter.IncrementCount' method"); + Assert.True(appMethodFound, "The cpuprofile.nettrace should contain stack frames for the 'Counter.IncrementCount' method"); + if (BuildTestBase.IsCoreClrRuntime) + { + Assert.True(readyToRunMethodFound, "The cpuprofile.nettrace should contain rundown information for the ReadyToRun 'System.Buffer.Memmove' method"); + } } [Fact]