-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add New Test to Monitor Number of Jitted Methods #90681
Closed
Closed
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c7c02a5
Added my first draft for the JIT methods counter tests.
ivdiazsa c7df757
Began incorporating the HelloWorld with the test builds.
ivdiazsa 9b9bb10
Added the Jitted Methods counting test to JIT/Performance.
ivdiazsa 1713f45
Made more progress. Still doesn't work.
ivdiazsa e0080e9
Clean up.
ivdiazsa 474d0aa
Added information to the test as per Tomas' feedback.
ivdiazsa 908e50e
Forgot to uncomment some code.
ivdiazsa 3707cf8
Removed the ReadyToRun and TieredCompilation env vars as per JanK's f…
ivdiazsa eec4acb
Fixed a couple semantic errors I overlooked in my previous commit.
ivdiazsa 8fa21fb
Merge branch 'main' into jit-participants
ivdiazsa 7d36e14
Made the test only run in ReadyToRun environments, and addressed some…
ivdiazsa 34b0ded
Replaced the 'is null' check with 'string.IsNullOrEmpty()' to play it…
ivdiazsa 1c9684c
Moved the JittedMethodsCountingTest to src/tests/readytorun as per Br…
ivdiazsa 6029d89
Changed app paths to be absolute instead of relative.
ivdiazsa 04d88e2
DEBUG-ONLY CHANGE: Helix just plain refuses to find the file that is …
ivdiazsa e3b96c8
DEBUG-ONLY CHANGE: Helix seems to not like '&&' to concatenate comman…
ivdiazsa f300f88
DEBUG-ONLY CHANGE: Maybe this will print the tree?
ivdiazsa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/tests/readytorun/JittedMethodsCountingTest/HelloWorld/HelloWorld.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
internal class HelloWorld | ||
{ | ||
static int Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello World!"); | ||
return 0; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/tests/readytorun/JittedMethodsCountingTest/HelloWorld/HelloWorld.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
<CLRTestKind>BuildOnly</CLRTestKind> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="HelloWorld.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
129 changes: 129 additions & 0 deletions
129
src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
public class JittedMethodsCountingTest | ||
{ | ||
private const int MAX_JITTED_METHODS_ACCEPTED = 120; | ||
|
||
[Fact] | ||
public static int TestEntryPoint() | ||
{ | ||
// If DOTNET_ReadyToRun is disabled, then this test ought to be skipped. | ||
if (!IsReadyToRunEnvSet()) | ||
{ | ||
Console.WriteLine("\nThis test is only supported in ReadyToRun scenarios." | ||
+ " Skipping...\n"); | ||
return 100; | ||
} | ||
|
||
string appName = "HelloWorld.dll"; | ||
string jitOutputFile = "jits.txt"; | ||
|
||
// DOTNET_JitStdOutFile appends to the file in question if it exists. | ||
// This can potentially cause issues, so we have to make sure it is | ||
// created exclusively for this test's purpose. | ||
if (File.Exists(jitOutputFile)) | ||
{ | ||
File.Delete(jitOutputFile); | ||
} | ||
|
||
// For adding any new apps for this test, make sure their success return | ||
// code is 0, so we can universally handle when they fail. | ||
int appResult = RunHelloWorldApp(appName, jitOutputFile); | ||
|
||
if (appResult != 0) | ||
{ | ||
Console.WriteLine("App failed somewhere and so we can't proceed with" | ||
+ " the Jitted Methods analysis. Exiting..."); | ||
return 101; | ||
} | ||
|
||
// App finished successfully. We can now take a look at the methods that | ||
// got jitted at runtime. | ||
int jits = GetNumberOfJittedMethods(jitOutputFile); | ||
return jits > 0 && jits <= MAX_JITTED_METHODS_ACCEPTED ? 100 : 101; | ||
} | ||
|
||
private static bool IsReadyToRunEnvSet() | ||
{ | ||
string? dotnetR2R = Environment.GetEnvironmentVariable("DOTNET_ReadyToRun"); | ||
return (string.IsNullOrEmpty(dotnetR2R) || dotnetR2R == "1") ? true : false; | ||
} | ||
|
||
private static int RunHelloWorldApp(string appName, string jitOutputFile) | ||
{ | ||
int appExitCode = -1; | ||
|
||
// Set up our CoreRun call. | ||
string coreRoot = Environment.GetEnvironmentVariable("CORE_ROOT"); | ||
string exeSuffix = OperatingSystem.IsWindows() ? ".exe" : ""; | ||
string coreRun = Path.Combine(coreRoot, $"corerun{exeSuffix}"); | ||
|
||
using (Process app = new Process()) | ||
{ | ||
var startInfo = new ProcessStartInfo | ||
{ | ||
FileName = coreRun, | ||
Arguments = appName, | ||
CreateNoWindow = true, | ||
UseShellExecute = false, | ||
}; | ||
|
||
// Set up the environment for running the test app. We are looking | ||
// to seeing how many methods were jitted at runtime. So, we ask | ||
// the runtime to print them out with DOTNET_JitDisasmSummary, and | ||
// write them out to a file we can parse and investigate later | ||
// with DOTNET_JitStdOutFile. | ||
startInfo.EnvironmentVariables.Add("DOTNET_JitDisasmSummary", "1"); | ||
startInfo.EnvironmentVariables.Add("DOTNET_JitStdOutFile", jitOutputFile); | ||
|
||
Console.WriteLine("\nLaunching Test App: {0} {1}", startInfo.FileName, | ||
startInfo.Arguments); | ||
|
||
app.StartInfo = startInfo; | ||
app.Start(); | ||
app.WaitForExit(); | ||
|
||
appExitCode = app.ExitCode; | ||
Console.WriteLine("App Exit Code: {0}", appExitCode); | ||
Console.WriteLine("Jitted Methods Generated File: {0}", jitOutputFile); | ||
} | ||
|
||
return appExitCode; | ||
} | ||
|
||
private static int GetNumberOfJittedMethods(string jitOutputFile) | ||
{ | ||
string[] lines = File.ReadAllLines(jitOutputFile); | ||
|
||
// Print out the jitted methods from the app run previously. This is | ||
// mostly done as additional logging to simplify potential bug investigations | ||
// in the future. | ||
|
||
Console.WriteLine("\n========== App Jitted Methods Start =========="); | ||
foreach (string line in lines) | ||
{ | ||
Console.WriteLine(line); | ||
} | ||
Console.WriteLine("========== App Jitted Methods End ==========\n"); | ||
|
||
// The jitted methods are printed in the following format: | ||
// | ||
// method number: method description | ||
// | ||
// This is why we split by ':' and parse the left side as a number. | ||
|
||
string[] tokens = lines.Last().Split(":"); | ||
int numJittedMethods = Int32.Parse(tokens[0]); | ||
Console.WriteLine("Total Jitted Methods: {0}\n", numJittedMethods); | ||
|
||
return numJittedMethods; | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<JitOptimizationSensitive>true</JitOptimizationSensitive> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="JittedMethodsCountingTest.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="HelloWorld/HelloWorld.csproj"> | ||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly> | ||
<OutputItemType>Content</OutputItemType> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</ProjectReference> | ||
</ItemGroup> | ||
|
||
</Project> | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should generate a full path akin to what I did in #90647,
The scripts may be tampering with the current directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion Tomas! Will try it this way. I don't know why I didn't bring those changes here. Must've slipped through the cracks.