-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 Track Number of Jitted Methods #91235
Merged
Merged
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7b31090
New beginning for the Jitted Methods Counting Test.
ivdiazsa b565e74
EXPERIMENTAL CHANGE ONLY: Added a command to print the whole directory
ivdiazsa 2317a4b
experimental change only: Discovered the jobs have dependencies on
ivdiazsa caf11e8
EXPERIMENT-ONLY CHANGE: Added the 'ls -R' directly to the Helix Post
ivdiazsa fda5625
Merge branch 'main' into jitted-parts
ivdiazsa efd048d
Maybe it doesn't like me removing the innerloop...?
ivdiazsa d243aef
More experimenting... So we can't do just musl...
ivdiazsa 90b639e
Merge branch 'main' into jitted-parts
ivdiazsa 87212da
Changed the test's methodology to use the JitInfo API, instead of
ivdiazsa 7c3cca8
Added the `AlwaysUseCrossgen2` property to the HelloWorld test app.
ivdiazsa 85f3317
Now printing the Jitted Methods to compare with my local machine.
ivdiazsa 0893d48
REVIEW-READY: Reenabled all the pipelines to see if there are any
ivdiazsa 35bc35e
Changed the Jitted methods counter to consider the whole process,
ivdiazsa cf7996b
DEBUG-ONLY CHANGE: We're getting more Jitted methods on Arm64 for some
ivdiazsa bb026de
Merge branch 'main' into jitted-parts
ivdiazsa 1a33f0b
Enabled musl outerloop pipelines because we were observing different
ivdiazsa 88d59f2
Will you stop complaining now?
ivdiazsa ad3f2fd
READY: Reenabled the pipelines and disabled the test for R2R_CG2
ivdiazsa b99398d
Changed the jits-number limit.
ivdiazsa adbb0b2
Changed the test to not require an external app anymore, and fixed
ivdiazsa 1e81e8a
DEBUG-ONLY CHANGE: Printing some logging to try to figure out why
ivdiazsa ad7a855
...
ivdiazsa 376b205
...
ivdiazsa d9cb394
Due to how some machines are set up, it is actually possible for a
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,7 @@ extends: | |
platforms: | ||
- linux_arm | ||
- linux_musl_arm64 | ||
- linux_arm64 | ||
- linux_x64 | ||
- osx_arm64 | ||
- osx_x64 | ||
|
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
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
17 changes: 17 additions & 0 deletions
17
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,17 @@ | ||
// 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!"); | ||
// We're fine converting to int here because if we got that many jitted | ||
// methods that would require a long, then that means something is | ||
// extremely wrong. Actually, I'm not even sure it's possible. | ||
int jits = (int) System.Runtime.JitInfo.GetCompiledMethodCount(false); | ||
return jits > 0 ? jits : -1; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework> | ||
<CLRTestKind>BuildOnly</CLRTestKind> | ||
<AlwaysUseCrossgen2>true</AlwaysUseCrossgen2> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="HelloWorld.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
114 changes: 114 additions & 0 deletions
114
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,114 @@ | ||
// 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; | ||
|
||
using Reflection = System.Reflection; | ||
using InteropServices = System.Runtime.InteropServices; | ||
|
||
public class JittedMethodsCountingTest | ||
{ | ||
private const int MAX_JITTED_METHODS_ACCEPTED = 50; | ||
|
||
[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; | ||
} | ||
|
||
if (IsRunCrossgen2Set() && IsRunningOnARM64()) | ||
{ | ||
Console.WriteLine("\nThis test is currently unsupported on ARM64 when" | ||
+ " RunCrossGen2 is enabled. Skipping...\n"); | ||
return 100; | ||
} | ||
|
||
string testAppLocation = Path.GetDirectoryName(Reflection | ||
.Assembly | ||
.GetExecutingAssembly() | ||
.Location); | ||
string appName = Path.Combine(testAppLocation, "HelloWorld.dll"); | ||
|
||
// For adding any new apps for this test, make sure they return a negative | ||
// number when failing. | ||
int appResult = RunHelloWorldApp(appName); | ||
|
||
if (appResult < 0) | ||
{ | ||
Console.WriteLine("App failed somewhere and so we can't proceed with" | ||
+ " the Jitted Methods analysis."); | ||
|
||
Console.WriteLine("App Exit Code: {0}", appResult); | ||
Console.WriteLine("Exiting..."); | ||
|
||
return 101; | ||
} | ||
|
||
// App finished successfully. We can now take a look at how many methods | ||
// got jitted at runtime. | ||
Console.WriteLine("Number of Jitted Methods: {0}\n", appResult); | ||
return appResult > 0 && appResult <= MAX_JITTED_METHODS_ACCEPTED ? 100 : 101; | ||
} | ||
|
||
private static bool IsReadyToRunEnvSet() | ||
{ | ||
string? dotnetR2R = Environment.GetEnvironmentVariable("DOTNET_ReadyToRun"); | ||
return (string.IsNullOrEmpty(dotnetR2R) || dotnetR2R == "1"); | ||
} | ||
|
||
private static bool IsRunCrossgen2Set() | ||
{ | ||
string? runCrossgen2 = Environment.GetEnvironmentVariable("RunCrossGen2"); | ||
return (runCrossgen2 == "1"); | ||
} | ||
|
||
private static bool IsRunningOnARM64() | ||
{ | ||
InteropServices.Architecture thisMachineArch = InteropServices | ||
.RuntimeInformation | ||
.OSArchitecture; | ||
|
||
return (thisMachineArch == InteropServices.Architecture.Arm64); | ||
} | ||
|
||
private static int RunHelloWorldApp(string appName) | ||
{ | ||
// The app's exit code is the number of jitted methods it got. | ||
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, | ||
}; | ||
|
||
Console.WriteLine("\nLaunching Test App: {0} {1}", startInfo.FileName, | ||
startInfo.Arguments); | ||
|
||
app.StartInfo = startInfo; | ||
app.Start(); | ||
app.WaitForExit(); | ||
appExitCode = app.ExitCode; | ||
} | ||
|
||
return appExitCode; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
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,21 @@ | ||
<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> |
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.
The setup with the app running in a separate process made sense when the test used JIT logging to get the method count.
This setup is overkill now that the test just calls
GetCompiledMethodCount
and checks its value. Would it be better to turn this into an ordinary single process test that just callsGetCompiledMethodCount
and checks its value (and skipping the check in specific environments)?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.
Actually, this makes a lot of sense. I just tested it on my local machine and I'm getting 4 jitted methods instead of the 1 I used to get with the solo HelloWorld app. Since the number of jitted methods is very similar, does it make sense to you to do it like this instead @trylek?