Skip to content

Commit bd8417a

Browse files
authored
Adding a unit test to track number of failed PGOs. (#6497)
* Adding a unit test to track number of failed PGOs. This ensures we check the failures with every commit and if numbers jump more than 1% then we need to regenrate PGO. * Fail the test if PGO file doesn't exist. * Using 1% threshold for failed PGOs
1 parent 293dfa1 commit bd8417a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

test/WebJobs.Script.Tests.Integration/WebHostEndToEnd/SpecializationE2ETests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
using Microsoft.Azure.WebJobs.Script.Configuration;
1919
using Microsoft.Azure.WebJobs.Script.Description;
2020
using Microsoft.Azure.WebJobs.Script.WebHost;
21+
using Microsoft.Azure.WebJobs.Script.WebHost.Middleware;
2122
using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
23+
using Microsoft.Diagnostics.JitTrace;
2224
using Microsoft.Extensions.Configuration;
2325
using Microsoft.Extensions.DependencyInjection;
2426
using Microsoft.Extensions.Hosting;
@@ -267,6 +269,23 @@ public async Task StartAsync_SetsCorrectActiveHost_RefreshesLanguageWorkerOption
267269
Assert.Equal("7", rpcChannelAfterSpecialization.Config.Description.DefaultRuntimeVersion);
268270
}
269271

272+
[Fact]
273+
public void ColdStart_JitFailuresTest()
274+
{
275+
var path = Path.Combine(Path.GetDirectoryName(new Uri(typeof(HostWarmupMiddleware).Assembly.CodeBase).LocalPath), WarmUpConstants.PreJitFolderName, WarmUpConstants.JitTraceFileName);
276+
277+
var file = new FileInfo(path);
278+
279+
Assert.True(file.Exists, $"Expected PGO file '{file.FullName}' does not exist. The file was either renamed or deleted.");
280+
281+
JitTraceRuntime.Prepare(file, out int successfulPrepares, out int failedPrepares);
282+
283+
var failurePercentage = (double) failedPrepares / successfulPrepares * 100;
284+
285+
// using 1% as approximate number of allowed failures before we need to regenrate a new PGO file.
286+
Assert.True( failurePercentage < 1.0 , $"Number of failed PGOs are more than 1 percent! Current number of failures are {failedPrepares}. This will definitely impact cold start! Time to regenrate PGOs and update the {WarmUpConstants.JitTraceFileName} file!");
287+
}
288+
270289
private IWebHostBuilder CreateStandbyHostBuilder(params string[] functions)
271290
{
272291
string scriptRootConfigPath = ConfigurationPath.Combine(ConfigurationSectionNames.WebHost, nameof(ScriptApplicationHostOptions.ScriptPath));

0 commit comments

Comments
 (0)