|
18 | 18 | using Microsoft.Azure.WebJobs.Script.Configuration;
|
19 | 19 | using Microsoft.Azure.WebJobs.Script.Description;
|
20 | 20 | using Microsoft.Azure.WebJobs.Script.WebHost;
|
| 21 | +using Microsoft.Azure.WebJobs.Script.WebHost.Middleware; |
21 | 22 | using Microsoft.Azure.WebJobs.Script.Workers.Rpc;
|
| 23 | +using Microsoft.Diagnostics.JitTrace; |
22 | 24 | using Microsoft.Extensions.Configuration;
|
23 | 25 | using Microsoft.Extensions.DependencyInjection;
|
24 | 26 | using Microsoft.Extensions.Hosting;
|
@@ -267,6 +269,23 @@ public async Task StartAsync_SetsCorrectActiveHost_RefreshesLanguageWorkerOption
|
267 | 269 | Assert.Equal("7", rpcChannelAfterSpecialization.Config.Description.DefaultRuntimeVersion);
|
268 | 270 | }
|
269 | 271 |
|
| 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 | + |
270 | 289 | private IWebHostBuilder CreateStandbyHostBuilder(params string[] functions)
|
271 | 290 | {
|
272 | 291 | string scriptRootConfigPath = ConfigurationPath.Combine(ConfigurationSectionNames.WebHost, nameof(ScriptApplicationHostOptions.ScriptPath));
|
|
0 commit comments