Skip to content

Commit

Permalink
Fix interp PGO WBT
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Jun 6, 2024
1 parent 9de28c2 commit d970374
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public InterpPgoTests(ITestOutputHelper output, SharedBuildPerTestClassFixture b
[InlineData("Release")]
public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config)
{
// We need to invoke Greeting enough times to cause BCL code to tier so we can exercise interpreter PGO
// We need to invoke Random enough times to cause BCL code to tier so we can exercise interpreter PGO
// Invoking it too many times makes the test meaningfully slower.
const int iterationCount = 70;
const int iterationCount = 50;

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

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

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

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

_testOutput.WriteLine("/// Done");
Expand Down
11 changes: 8 additions & 3 deletions src/mono/wasm/testassets/WasmBasicTestApp/App/InterpPgoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ public partial class InterpPgoTest
internal static partial string GetHRef();

[JSExport]
internal static string Greeting()
internal static void TryToTier(int iterationCount)
{
var text = $"Hello, World! Greetings from {GetHRef()}";
var buffer = new int[4096];
var random = new Random();
for (int i = 0; i < iterationCount; i++) {
for (int j = 0; j < buffer.Length; j++)
buffer[j] = random.Next();
}
var text = $"Greetings from {GetHRef()}. I filled a buffer with random items {iterationCount} times.";
Console.WriteLine(text);
return text;
}
}
6 changes: 2 additions & 4 deletions src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ try {
}
}
});
const iterationCount = params.get("iterationCount") ?? 70;
for (let i = 0; i < iterationCount; i++) {
exports.InterpPgoTest.Greeting();
};
const iterationCount = params.get("iterationCount") ?? "70";
exports.InterpPgoTest.TryToTier(parseInt(iterationCount));
await INTERNAL.interp_pgo_save_data();
exit(0);
break;
Expand Down

0 comments on commit d970374

Please sign in to comment.