Skip to content

Commit d970374

Browse files
committed
Fix interp PGO WBT
1 parent 9de28c2 commit d970374

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/InterpPgoTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public InterpPgoTests(ITestOutputHelper output, SharedBuildPerTestClassFixture b
2828
[InlineData("Release")]
2929
public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
3030
{
31-
// We need to invoke Greeting enough times to cause BCL code to tier so we can exercise interpreter PGO
31+
// We need to invoke Random enough times to cause BCL code to tier so we can exercise interpreter PGO
3232
// Invoking it too many times makes the test meaningfully slower.
33-
const int iterationCount = 70;
33+
const int iterationCount = 50;
3434

3535
_testOutput.WriteLine("/// Creating project");
3636
CopyTestAsset("WasmBasicTestApp", "InterpPgoTest", "App");
@@ -61,13 +61,13 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
6161
lock (runner.OutputLines)
6262
output = string.Join(Environment.NewLine, runner.OutputLines);
6363

64-
Assert.Contains("Hello, World!", output);
64+
Assert.Contains("I filled a buffer with random items", output);
6565
// Verify that no PGO table was located in cache
6666
Assert.Contains("Failed to load interp_pgo table", output);
6767
// Verify that the table was saved after the app ran
6868
Assert.Contains("Saved interp_pgo table", output);
6969
// Verify that a specific method was tiered by the Greeting calls and recorded by PGO
70-
Assert.Contains("added System.Runtime.CompilerServices.Unsafe:Add<byte> (byte&,int) to table", output);
70+
Assert.Contains(" System.Random:Next () to table", output);
7171
}
7272

7373
{
@@ -81,7 +81,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
8181
lock (runner.OutputLines)
8282
output = string.Join(Environment.NewLine, runner.OutputLines);
8383

84-
Assert.Contains("Hello, World!", output);
84+
Assert.Contains("I filled a buffer with random items", output);
8585
// Verify that table data was loaded from cache
8686
// if this breaks, it could be caused by change in config which affects the config hash and the cache storage hash key
8787
Assert.Contains(" bytes of interp_pgo data (table size == ", output);
@@ -90,7 +90,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
9090
// Verify that method(s) were found in the table and eagerly tiered
9191
Assert.Contains("because it was in the interp_pgo table", output);
9292
// Verify that a specific method was tiered by the Greeting calls and recorded by PGO
93-
Assert.Contains("added System.Runtime.CompilerServices.Unsafe:Add<byte> (byte&,int) to table", output);
93+
Assert.Contains(" System.Random:Next () to table", output);
9494
}
9595

9696
_testOutput.WriteLine("/// Done");

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ public partial class InterpPgoTest
1212
internal static partial string GetHRef();
1313

1414
[JSExport]
15-
internal static string Greeting()
15+
internal static void TryToTier(int iterationCount)
1616
{
17-
var text = $"Hello, World! Greetings from {GetHRef()}";
17+
var buffer = new int[4096];
18+
var random = new Random();
19+
for (int i = 0; i < iterationCount; i++) {
20+
for (int j = 0; j < buffer.Length; j++)
21+
buffer[j] = random.Next();
22+
}
23+
var text = $"Greetings from {GetHRef()}. I filled a buffer with random items {iterationCount} times.";
1824
Console.WriteLine(text);
19-
return text;
2025
}
2126
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,8 @@ try {
130130
}
131131
}
132132
});
133-
const iterationCount = params.get("iterationCount") ?? 70;
134-
for (let i = 0; i < iterationCount; i++) {
135-
exports.InterpPgoTest.Greeting();
136-
};
133+
const iterationCount = params.get("iterationCount") ?? "70";
134+
exports.InterpPgoTest.TryToTier(parseInt(iterationCount));
137135
await INTERNAL.interp_pgo_save_data();
138136
exit(0);
139137
break;

0 commit comments

Comments
 (0)